diff options
Diffstat (limited to 'src/setuptools_scm/version.py')
-rw-r--r-- | src/setuptools_scm/version.py | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/src/setuptools_scm/version.py b/src/setuptools_scm/version.py index aa4bd49..cc4d838 100644 --- a/src/setuptools_scm/version.py +++ b/src/setuptools_scm/version.py @@ -132,6 +132,7 @@ class ScmVersion(object): dirty=False, preformatted=False, branch=None, + config=None, **kw ): if kw: @@ -146,6 +147,7 @@ class ScmVersion(object): self.dirty = dirty self.preformatted = preformatted self.branch = branch + self.config = config @property def extra(self): @@ -193,7 +195,14 @@ def _parse_tag(tag, preformatted, config): def meta( - tag, distance=None, dirty=False, node=None, preformatted=False, config=None, **kw + tag, + distance=None, + dirty=False, + node=None, + preformatted=False, + branch=None, + config=None, + **kw ): if not config: warnings.warn( @@ -203,7 +212,9 @@ def meta( parsed_version = _parse_tag(tag, preformatted, config) trace("version", tag, "->", parsed_version) assert parsed_version is not None, "cant parse version %s" % tag - return ScmVersion(parsed_version, distance, node, dirty, preformatted, **kw) + return ScmVersion( + parsed_version, distance, node, dirty, preformatted, branch, config, **kw + ) def guess_next_version(tag_version): @@ -260,6 +271,25 @@ def simplified_semver_version(version): ) +def release_branch_semver(version): + if version.exact: + return version.format_with("{tag}") + if version.branch is not None: + # Does the branch name (stripped of namespace) parse as a version? + branch_ver = _parse_version_tag(version.branch.split("/")[-1], version.config) + if branch_ver is not None: + # Does the branch version up to the minor part match the tag? If not it + # might be like, an issue number or something and not a version number, so + # we only want to use it if it matches. + tag_ver_up_to_minor = str(version.tag).split(".")[:SEMVER_MINOR] + branch_ver_up_to_minor = branch_ver["version"].split(".")[:SEMVER_MINOR] + if branch_ver_up_to_minor == tag_ver_up_to_minor: + # We're in a release/maintenance branch, next is a patch/rc/beta bump: + return version.format_next_version(guess_next_version) + # We're in a development branch, next is a minor bump: + return version.format_next_version(guess_next_simple_semver, retain=SEMVER_MINOR) + + def _format_local_with_time(version, time_format): if version.exact or version.node is None: |