Skip to content

Commit 16056cd

Browse files
authored
Merge pull request #329 from CitrineInformatics/pne-6628/fix-pypi-deploy
pne-6628/fix-pypi-deploy
2 parents f3e4568 + 7365537 commit 16056cd

File tree

5 files changed

+71
-2
lines changed

5 files changed

+71
-2
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!python
2+
from os import getcwd, popen
3+
from os.path import relpath
4+
from packaging.version import Version
5+
import re
6+
import sys
7+
from typing import TextIO
8+
9+
10+
def main():
11+
repo_dir = popen("git rev-parse --show-toplevel", mode="r").read().rstrip()
12+
version_path = relpath(f'{repo_dir}/python/lolopy/version.py', getcwd())
13+
14+
try:
15+
with open(version_path, "r") as fh:
16+
new_version = extract_version(fh)
17+
except Exception as e:
18+
raise ValueError(f"Couldn't extract version from {version_path}") from e
19+
20+
try:
21+
with popen(f"git fetch origin && git show origin/main:python/lolopy/version.py", mode="r") as fh:
22+
old_version = extract_version(fh)
23+
except Exception as e:
24+
raise ValueError(f"Couldn't extract version from main branch") from e
25+
26+
if new_version.major != old_version.major:
27+
number = "major"
28+
code = 1
29+
elif new_version.minor != old_version.minor:
30+
number = "minor"
31+
code = 2
32+
elif new_version.micro != old_version.micro:
33+
number = "patch"
34+
code = 3
35+
else:
36+
number = "other component of"
37+
code = 5
38+
39+
if new_version > old_version:
40+
print(f"{number} version bump")
41+
return 0
42+
elif new_version < old_version:
43+
print(f"error - {number} version decreased! {new_version} < {old_version}")
44+
return code
45+
else:
46+
print(f"error - version unchanged! {new_version} == {old_version}")
47+
return 4
48+
49+
50+
def extract_version(handle: TextIO) -> Version:
51+
text = handle.read()
52+
if not re.search(r"\S", text):
53+
raise ValueError(f"No content")
54+
match = re.search(r"""^\s*__version__\s*=\s*(['"])(\S+)\1""", text, re.MULTILINE)
55+
if match:
56+
return Version(match.group(2))
57+
else:
58+
raise ValueError(f"No version found\n{text}")
59+
60+
61+
if __name__ == "__main__":
62+
sys.tracebacklimit = 0
63+
result = main()
64+
if result != 0:
65+
sys.exit(result)

.github/workflows/deployPyPi.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,5 @@ jobs:
3838
- name: Publish to PyPI
3939
uses: pypa/gh-action-pypi-publish@release/v1
4040
with:
41-
password: ${{ secrets.PYPI_API_TOKEN }}
41+
password: ${{ secrets.PYPI_API_TOKEN }}
42+
packages-dir: python/dist/

.github/workflows/tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ jobs:
7272
make
7373
pip install --only-binary=numpy,scipy -r requirements.txt
7474
pip install -r test_requirements.txt
75+
- name: Check version
76+
run: python .github/scripts/validate_version_bump.py
7577
- name: Run Python tests
7678
run: |
7779
cd python

python/lolopy/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# single source of truth for package version,
22
# see https://packaging.python.org/en/latest/single_source_version/
3-
__version__ = "3.0.0"
3+
__version__ = "3.0.1"

python/test_requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
pytest==8.3.3
2+
packaging

0 commit comments

Comments
 (0)