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

bindings/python/setup.py.in does not properly sanitize version for release candidates #1621

Closed
matthewfeickert opened this issue Feb 18, 2022 · 1 comment · Fixed by #1623

Comments

@matthewfeickert
Copy link
Contributor

matthewfeickert commented Feb 18, 2022

This is pretty minor as it only affects release candidates and doesn't actually cause any problems as setuptools is smart enough to catch and fix it, but in PR #1605 I didn't properly account for release candidate versions like v5.4.1-rc2. Note both v5.4.1-rc2 and v5.4.1.rc2 will get sanitized to v5.4.1rc2 by pip and setuptools

>>> from pip._vendor.packaging.version import Version
>>> Version("v5.4.1-rc2")
<Version('5.4.1rc2')>
>>> Version("v5.4.1.rc2")
<Version('5.4.1rc2')>
>>> Version("v5.4.1rc2")
<Version('5.4.1rc2')>

As

# version needs to pass pip._vendor.packaging.version.Version()
version = version.replace("-", ".")
if version.startswith("v"):
version = version[1:]

was expecting something of the form "v5.4.1rc2", it doesn't properly catch v5.4.1-rc2 and instead transforms it into "5.4.1.rc2". As mentioned, pip and setuptools can still work with this, but in the build will give something like

XRootD library dir:     /code/build/src
XRootD src include dir: /code/xrootd/src
XRootD bin include dir: /code/build/src
Version:                5.4.1.rc2
/usr/local/venv/lib/python3.9/site-packages/setuptools/dist.py:505: UserWarning: Normalizing '5.4.1.rc2' to '5.4.1rc2'
@matthewfeickert
Copy link
Contributor Author

matthewfeickert commented Feb 18, 2022

There may be a cleaner way to do fix this, but this should work

...
    version_parts = version.split(".")

    # Ensure release candidates sanitized to <major>.<minor>.<patch>rc<candidate>
    if version_parts[-1].startswith("rc"):
        version = ".".join(version_parts[:-1]) + version_parts[-1]
        version_parts = version.split(".")
...
Example:
from pip._vendor.packaging.version import Version


def sanitize(version):
    print(f"\n# Starting version: {version}")

    # version needs to pass pip._vendor.packaging.version.Version()
    version = version.replace("-", ".")

    if version.startswith("v"):
        version = version[1:]

    version_parts = version.split(".")

    # Ensure release candidates sanitized to <major>.<minor>.<patch>rc<candidate>
    if version_parts[-1].startswith("rc"):
        version = ".".join(version_parts[:-1]) + version_parts[-1]
        version_parts = version.split(".")

    if len(version_parts[0]) == 8:
        # CalVer
        date = version_parts[0]
        year = date[:4]
        incremental = date[4:]
        if incremental.startswith("0"):
            incremental = incremental[1:]

        version = year + "." + incremental

        if len(version_parts) > 1:
            # https://github.com/pypa/pip/issues/9188#issuecomment-736025963
            hash = version_parts[1]
            version = version + "+" + hash

    print(f"# Sanitized version: {version}")
    assert version == str(Version(version))


sanitize("v5.4.1-rc2")
sanitize("v5.4.1.rc2")
sanitize("v5.4.1rc2")
sanitize("v20220128-34c8a39")
sanitize("2022.128")
sanitize("2022.128+a28a91c")
sanitize("6.0.0")

# Starting version: v5.4.1-rc2
# Sanitized version: 5.4.1rc2

# Starting version: v5.4.1.rc2
# Sanitized version: 5.4.1rc2

# Starting version: v5.4.1rc2
# Sanitized version: 5.4.1rc2

# Starting version: v20220128-34c8a39
# Sanitized version: 2022.128+34c8a39

# Starting version: 2022.128
# Sanitized version: 2022.128

# Starting version: 2022.128+a28a91c
# Sanitized version: 2022.128+a28a91c

# Starting version: 6.0.0
# Sanitized version: 6.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant