Skip to content

Commit da658e4

Browse files
committed
cleanup and documentation
1 parent 76ef1b3 commit da658e4

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ jobs:
154154
# deploy development distribution with changes to develop
155155
deploy-dev-dist:
156156
needs: testing
157-
if: github.ref == 'refs/heads/ts/dev-release'
157+
if: github.ref == 'refs/heads/ts/dev-release' && github.event_name == 'push'
158158
runs-on: ubuntu-latest
159159
steps:
160160
- name: checkout
@@ -173,7 +173,7 @@ jobs:
173173
run: poetry install --no-root --with=dev
174174
- name: increment dev version
175175
env:
176-
PYPI_URL: https://test.pypi.org
176+
PYPI_URL: https://pypi.org
177177
run: poetry run python scripts/bump_dev_version.py
178178
- name: build dist
179179
run: poetry build
@@ -183,4 +183,9 @@ jobs:
183183
with:
184184
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
185185
repository_url: https://test.pypi.org/legacy/
186-
skip_existing: false
186+
skip_existing: false
187+
- name: publish distribution to PyPI
188+
if: steps.test-pypi.outcome == 'success'
189+
uses: pypa/gh-action-pypi-publish@release/v1
190+
with:
191+
password: ${{ secrets.PYPI_API_TOKEN }}

scripts/bump_dev_version.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import requests
77
import tomlkit
88

9+
# Version pattern from https://peps.python.org/pep-0440/#appendix-b-parsing-version-strings-with-regular-expressions
910
VERSION_PATTERN = r"""
1011
v?
1112
(?:
@@ -42,14 +43,16 @@
4243
)
4344

4445

45-
def extract_version_components(release_str: str) -> dict:
46-
match = _regex.match(release_str)
46+
def extract_version_components(version_str: str) -> dict:
47+
"""Splits a version string into its components"""
48+
match = _regex.match(version_str)
4749
if match is not None:
4850
return match.groupdict()
49-
raise Exception(f"Failed to extract components from {release_str}")
51+
raise Exception(f"Failed to extract components from {version_str}")
5052

5153

52-
def get_release_list(index_url: str, project_name: str):
54+
def get_release_list(index_url: str, project_name: str) -> list[str]:
55+
"""Gets a list of release versions from a pypi compliant index"""
5356
index_url = index_url.rstrip("/")
5457
response = requests.get(index_url + "/pypi/" + project_name + "/json")
5558
response.raise_for_status()
@@ -59,6 +62,7 @@ def get_release_list(index_url: str, project_name: str):
5962

6063

6164
def components_to_version(components: dict) -> str:
65+
"""Takes the components of a version and combines them into a string"""
6266
for key in components.keys():
6367
if components[key] is None:
6468
components[key] = ""
@@ -75,6 +79,9 @@ def components_to_version(components: dict) -> str:
7579
def increment_development_component(
7680
version_str: str, increment_components: bool = False
7781
) -> str:
82+
"""Increment develop component, and optionally increment the least
83+
signification version component if the current version string does
84+
not contain a development component."""
7885
version_groups = extract_version_components(version_str)
7986

8087
if version_groups["dev_n"]:
@@ -115,6 +122,7 @@ def increment_development_component(
115122

116123

117124
def version_greater_than(version_a: Optional[str], version_b: Optional[str]) -> bool:
125+
"""Compare if version a is strictly greater than version b"""
118126
if version_a is None:
119127
return False
120128
if version_b is None:
@@ -193,6 +201,10 @@ def version_greater_than(version_a: Optional[str], version_b: Optional[str]) ->
193201

194202

195203
def get_next_dev_version(local_version: str, release_list: list[str]) -> str:
204+
"""Compare local_version to list of released versions.
205+
If there are already dev builds it will incrment the latest of those builds.
206+
If there are not, it will create the version for the first dev build.
207+
"""
196208
local_version_components = extract_version_components(local_version)
197209

198210
recent_release = None
@@ -218,18 +230,22 @@ def get_next_dev_version(local_version: str, release_list: list[str]) -> str:
218230
return increment_development_component(local_version)
219231

220232

233+
# Read pyproject.toml
221234
pyproject_path = Path(os.path.abspath(__file__)).parents[1] / "pyproject.toml"
222-
223235
pyproject_contents = tomlkit.load(pyproject_path.open("r"))
224236

237+
# Query release list
225238
release_list = get_release_list(
226239
os.environ.get("PYPI_URL", "https://pypi.org/"),
227240
pyproject_contents["tool"]["poetry"]["name"].lower(),
228241
)
242+
# Get current version from pyproject.toml
229243
version = pyproject_contents["tool"]["poetry"]["version"]
230244

245+
# Determine name for dev release
231246
next_dev_version = get_next_dev_version(version, release_list)
232247
print(next_dev_version)
233248
pyproject_contents["tool"]["poetry"]["version"] = next_dev_version
234249

250+
# Update pyproject.toml
235251
tomlkit.dump(pyproject_contents, pyproject_path.open("w"))

0 commit comments

Comments
 (0)