Skip to content

Handling of invalid and dev versions when building from source #9014

@PhrozenByte

Description

@PhrozenByte

When attempting to build Borg 1.4 from source with setuptools_scm failing to determine a valid version string automatically, any Borg invocation fails with the following ValueError:

$ borg --version
Traceback (most recent call last):
  File "/borg-build/src/borg/archiver.py", line 47, in <module>
    from .archive import Archive, ArchiveChecker, ArchiveRecreater, Statistics, is_special
  File "/borg-build/src/borg/archive.py", line 24, in <module>
    from .cache import ChunkListEntry
  File "/borg-build/src/borg/cache.py", line 31, in <module>
    from .crypto.key import PlaintextKey
  File "/borg-build/src/borg/crypto/key.py", line 30, in <module>
    from .nonces import NonceManager
  File "/borg-build/src/borg/crypto/nonces.py", line 8, in <module>
    from ..remote import InvalidRPCMethod
  File "/borg-build/src/borg/remote.py", line 41, in <module>
    BORG_VERSION = parse_version(__version__)
  File "/borg-build/src/borg/version.py", line 24, in parse_version
    raise ValueError('Invalid version string %s' % version)
ValueError: Invalid version string 0.1.dev1+gfb10207fe

It looks like you tried to handle this gracefully in __init__.py:

# assert that all semver components are integers
# this is mainly to show errors when people repackage poorly
# and setuptools_scm determines a 0.1.dev... version
assert all(isinstance(v, int) for v in __version_tuple__), \
"""\
broken borgbackup version metadata: %r
version metadata is obtained dynamically on installation via setuptools_scm,
please ensure your git repo has the correct tags or you provide the version
using SETUPTOOLS_SCM_PRETEND_VERSION in your build script.
""" % __version__

This actually pretty helpful error message is never shown unfortunately.

Furthermore, the SETUPTOOLS_SCM_PRETEND_VERSION env variable is nowhere mentioned in the docs. It might be a good idea to mention it in the "Installation - From Source - Using git" section of the docs.

Lastly, the auto-generated versions of setuptools_scm don't match Borg's version string format and are currently treated like stable versions (parse_version() e.g. yields (1,4,2,-1) for the auto-generated version 1.4.2.dev77+gfb10207fe, it should be something like (1,4,2,-9)).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions