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

Fix issue with prerelease git versions where the dash before the version number disappears #10

Closed
smarie opened this issue Feb 24, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@smarie
Copy link
Owner

smarie commented Feb 24, 2021

Consider some random python module that is in a git-versioned folder, tagged as 1.0.0-rc1 (release candidate. See semantic versioning: https://semver.org/spec/v2.0.0-rc.1.html)

The following code does not retrieve the right version string: the dash before the pre-release info is removed

from getversion import get_module_version

# import whatever local folder or file is available in this git folder
import my_module

# get the version and details. it will fallback to using the setuptools_scm one
ver, details = get_module_version(my_module)
print(details)  # SUCCESS on the setuptools_scm one (the last one)
print(ver)       # prints "1.0.0rc1" instead of "1.0.0-rc1" 

This has for example as consequence that the resulting version string is not compliant with semver while the initial git tag was:

from semver import parse_version_info
parse_version_info("1.0.0-rc1")  # this is ok
parse_version_info("1.0.0rc1")  # this fails

raises ValueError: 1.0.0rc1 is not valid SemVer string

@smarie smarie added the bug Something isn't working label Feb 24, 2021
@smarie
Copy link
Owner Author

smarie commented Feb 24, 2021

Digging a little bit, this is what happens

  • getversion delegates to its plugin_setuptools_scm.py that calls setuptools_scm.get_version(<root_folder>)

  • setuptools_scm.get_version :

    • executes git describe --dirty --tags --long --match *.* to get the correct version number 1.0.0-rc1
    • uses pkg_resources.parse_version(version_string) to get a Version object with the correct information, and stores it in it own wrapping object's version.tag attribute.
    • uses the string representation (__str__) of this Version object in the various "version scheme" string formatting methods

The issue is that since pkg_resources version 0.6a9 the string representation of a Version removes the dash !!

from pkg_resources import parse_version
ver_str = parse_version("1.0.0-rc1")
print(ver_str)  # yields 1.0.0rc1 !!!

There are several ways we can fix this:

  • to secure the usage of the output of get_version for use for example with semver, I will add today a fix that will use a custom version scheme.

  • this could be fixed in setuptools_scm. It would be my preferred option, since the default versioning scheme should probably closely match the tag actually visible in github, without removing dashes.

  • this could be fixed in pkg_resources. I am not sure that this should/could happen for retrocompatibility issues, and since this is not at all tied to git scm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant