Skip to content

Commit

Permalink
Merge pull request #4780 from NREL/fixup_python_bindings_release
Browse files Browse the repository at this point in the history
Fixup the python bindings during release
  • Loading branch information
tijcolem authored Jan 4, 2023
2 parents 7827af2 + d270792 commit 59f1eb4
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 3 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/python_bindings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,11 @@ jobs:
python -m pip install --upgrade pip
# Note: if we choose to do ALL or nothing, remove setuptools wheel twine (not needed unless trying to upload within this step)
pip install requests packaging setuptools wheel twine
bindings_v=$(python ./python/module/find_pypi_tag.py --current)
if [[ "$GITHUB_REF" == *"refs/tags"* ]]; then
bindings_v=$(python ./python/module/find_pypi_tag.py --pypi)
else
bindings_v=$(python ./python/module/find_pypi_tag.py --current)
fi;
pip install -i https://test.pypi.org/simple/ openstudio==$bindings_v
mkdir wheel
Expand All @@ -343,7 +347,7 @@ jobs:
m = openstudio.model.exampleModel()
print(m)
# if python_bindings succeeds but test_python_bindings fails and this is a release,
# if python_bindings succeeds but test_python_bindings fails and this is a release,
# remove that version from testpypi
upload_python_bindings_to_pypi:
if: contains(github.ref, 'refs/tags')
Expand Down
3 changes: 2 additions & 1 deletion python/module/find_pypi_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ def compute_appropriate_version(current_v: version.Version,
new_v += f"{pre_iden}{pre_v}"
post_v = max_v.post
if not post_v:
new_v += 'post0'
if not current:
new_v += 'post0'
elif current:
new_v += f"post{post_v}"
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,63 @@ def test_when_exist_no_prereleasetag(self):

self.compare(releases=["3.2.1", "3.2.1a1"],
v='3.2.1', expected_v="3.2.1post0")


class TestFindTestPyPiTagCurrent(unittest.TestCase):

def compare(self, releases: list[str], v: str, expected_v: str):
"""
Test helper, to avoid repeating myself
"""
new_v = compute_appropriate_version(
current_v=version.parse(v),
releases=[version.parse(v) for v in releases],
current=True
)
self.assertEqual(version.parse(expected_v), new_v)

def test_when_not_exist_with_prereleasetag(self):
self.compare(releases=["3.2.0"], v="3.2.1-alpha", expected_v="3.2.1a0")

def test_when_not_exist_no_prereleasetag(self):
self.compare(releases=["3.2.0"], v="3.2.1", expected_v="3.2.1")

def test_when_exist_with_prereleasetag(self):
self.compare(releases=["3.2.1"], v="3.2.1-alpha", expected_v="3.2.1a0")

self.compare(releases=["3.2.1", "3.2.1a0"],
v="3.2.1-alpha", expected_v="3.2.1a0")

self.compare(releases=["3.2.1", "3.2.1a0", "3.2.1a1"],
v="3.2.1-alpha", expected_v="3.2.1a1")

# Different prerelease tag
self.compare(releases=["3.2.1", "3.2.1a0", "3.2.1a1"],
v="3.2.1-beta", expected_v="3.2.1b0")

self.compare(releases=["3.2.1", "3.2.1a0", "3.2.1a1", "3.2.1b0"],
v="3.2.1-beta", expected_v="3.2.1b0")

self.compare(releases=["3.2.1", "3.2.1a20", "3.2.1b0", "3.2.1b10"],
v="3.2.1-beta", expected_v="3.2.1b10")

def test_with_rctag(self):

self.compare(releases=["3.2.0", "3.2.1a1"],
v='3.2.1-rc1', expected_v="3.2.1rc1")

# Here I actually expect a post release to be appended
self.compare(releases=["3.2.0", "3.2.1a1", "3.2.1rc1"],
v='3.2.1-rc1', expected_v="3.2.1rc1")

self.compare(releases=["3.2.0", "3.2.1a1", "3.2.1rc1"],
v='3.2.1-rc2', expected_v="3.2.1rc2")

# Now we release official
self.compare(releases=["3.2.0", "3.2.1a1", "3.2.1rc1"],
v='3.2.1', expected_v="3.2.1")

def test_when_exist_no_prereleasetag(self):

self.compare(releases=["3.2.1", "3.2.1a1"],
v='3.2.1', expected_v="3.2.1")

0 comments on commit 59f1eb4

Please sign in to comment.