dbt-labs / dbt-common

Apache License 2.0
13 stars 15 forks source link

[Feature] Support Python PEP440 SemVer #185

Open guenp opened 3 months ago

guenp commented 3 months ago

Is this your first time submitting a feature request?

Describe the feature

For dbt-ducdkb, we recently implemented automated versioning via git tags, by adding in a pbr dependency. pbr uses what they call Linux/Python Compatible Semantic Versioning 3.0.0. The main differences with SemVer 2.0.0 are:

  • Pre-release versions are now separated by . not -, and use a/b/c rather than alpha/beta etc.
  • Alpha version are prefixed by a 0 such as: 2.0.0.0a1 instead of 2.0.0.a1 for version ‘2.0.0 alpha 1’. Please note dev version tag does not have a leading 0, as is 2.0.0.0a2.dev1.

Unfortunately, dbt-common's semver module doesn't seem to match this versioning. Concretely, this means I get this error:

version_string = '1.8.3.dev6'
    @classmethod
    def from_version_string(cls, version_string):
        match = _VERSION_REGEX.match(version_string)

        if not match:
>           raise dbt_common.exceptions.base.SemverError(
                f'"{version_string}" is not a valid semantic version.'
            )
E           dbt_common.exceptions.base.SemverError: "1.8.3.dev6" is not a valid semantic version.
venv/lib/python3.12/site-packages/dbt_common/semver.py:99: SemverError

We have a workaround for now, that post-processes the version and replaces the . with a -, see code and PR. However, it would be great to add support for Semver "3.0.0"/PEP-440 versioning to the regex!

Describe alternatives you've considered

Who will this benefit?

Are you interested in contributing this feature?

No response

Anything else?

No response