Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not fail when tag versions cannot be parsed. #409

Merged
merged 3 commits into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ Changelog for zest.releaser
8.0.0a2 (unreleased)
--------------------

- Nothing changed yet.
- Do not fail when tag versions cannot be parsed.
This can happen in ``lasttaglog``, ``lasttagdiff``, and ``bumpversion``, with ``setuptools`` 66 or higher.
Fixes `issue 408 <https://github.com/zestsoftware/zest.releaser/issues/408>`_.
[maurits]


8.0.0a1 (2023-02-08)
Expand Down
2 changes: 1 addition & 1 deletion zest/releaser/tests/functional-git.txt
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,5 @@ The changelog and setup.py are at 0.2 and indicate dev mode:
And there are no uncommitted changes:

>>> print(execute_command(["git", "status"]))
On branch master
On branch main
nothing to commit, working directory clean
2 changes: 1 addition & 1 deletion zest/releaser/tests/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def _mock_urlopen(url):
gitsourcedir = os.path.join(test.tempdir, "tha.example-git")
shutil.copytree(sourcedir, gitsourcedir)
os.chdir(gitsourcedir)
execute_command(["git", "init"])
execute_command(["git", "init", "-b", "main"])
# Configure local git.
execute_command(["git", "config", "--local", "user.name", "Temp user"])
execute_command(["git", "config", "--local", "user.email", "temp@example.com"])
Expand Down
8 changes: 4 additions & 4 deletions zest/releaser/tests/git.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Commit it:
['git', 'commit', '-a', '-m', 'small tweak', '-n']

In some cases we get this output:
``[master ...] small tweak``
``[main ...] small tweak``
and in other this:
``Created commit ...: small tweak``

Expand Down Expand Up @@ -189,14 +189,14 @@ The tempdir should be at tag 0.1. The last line ought to be "a = 2"
...
a = 2

Change back to the source directory and return to the master branch.
Change back to the source directory and return to the main branch.

>>> os.chdir(gitsourcedir)
>>> cmd = [['git', 'checkout', 'master'],
>>> cmd = [['git', 'checkout', 'main'],
... ['git', 'submodule', 'update', '--init', '--recursive']]
>>> print(execute_commands(cmd))
RED Previous HEAD position was ... small tweak
RED Switched to branch 'master'
RED Switched to branch 'main'

Pushing changes
---------------
Expand Down
4 changes: 2 additions & 2 deletions zest/releaser/tests/pyproject-toml.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ We remove and add files.
>>> _ = execute_command(["git", "add", "pyproject.toml"])
>>> _ = execute_command(["git", "commit", "-m", "Move to pyproject.toml"])
>>> print(execute_command(["git", "status"]))
On branch master
On branch main
nothing to commit, working directory clean

The version is at 0.1.dev0:
Expand Down Expand Up @@ -140,5 +140,5 @@ The changelog and pyproject.toml are at 0.2 and indicate dev mode:
And there are no uncommitted changes:

>>> print(execute_command(["git", "status"]))
On branch master
On branch main
nothing to commit, working directory clean
27 changes: 20 additions & 7 deletions zest/releaser/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -849,19 +849,32 @@ def get_last_tag(vcs, allow_missing=False):
# by setuptools' version parsing. A direct match is obviously
# right. The 'less' approach handles development eggs that have
# already been switched back to development.
available_tags.reverse()
mauritsvanrees marked this conversation as resolved.
Show resolved Hide resolved
found = available_tags[0]
# Note: if parsing the current version fails, there is nothing we can do:
# there is no sane way of knowing which version is smaller than an unparsable
# version, so we just break hard.
parsed_version = parse_version(version)
found = parsed_found = None
for tag in available_tags:
parsed_tag = parse_version(tag)
parsed_found = parse_version(found)
try:
parsed_tag = parse_version(tag)
except Exception:
# I don't want to import this specific exception,
# because it sounds unstable:
# pkg_resources.extern.packaging.version.InvalidVersion
continue
mauritsvanrees marked this conversation as resolved.
Show resolved Hide resolved
if parsed_tag == parsed_version:
found = tag
logger.debug("Found exact match: %s", found)
break
if parsed_tag >= parsed_found and parsed_tag < parsed_version:
logger.debug("Found possible lower match: %s", tag)
found = tag
if parsed_tag >= parsed_version:
# too new tag, not interesting
continue
if found is not None and parsed_tag <= parsed_found:
# we already have a better match
continue
logger.debug("Found possible lower match: %s", tag)
found = tag
parsed_found = parsed_tag
return found


Expand Down