diff options
author | Antony Lee <anntzer.lee@gmail.com> | 2020-03-22 14:48:32 +0100 |
---|---|---|
committer | Antony Lee <anntzer.lee@gmail.com> | 2020-05-01 16:28:29 +0200 |
commit | aaab738a9e698b4d84c1f0724341a1b009b766ea (patch) | |
tree | 60e4d269e19a7d5b49ed6f74c7c1cf76a8ad8777 /src | |
parent | 200c56667fd8446056ec365b95ea2dccdd0a9a1b (diff) | |
download | setuptools-scm-aaab738a9e698b4d84c1f0724341a1b009b766ea.tar.gz |
Allow getting the version from the parent directory suffix.
Add a `parentdir_prefix_version` config parameter which allows lets
setuptools_scm get a version string from the name of the parent
directory: if `parentdir_prefix_version = "foo-"` and the parent
directory is named `foo-v12.34`, then the version is 12.34. This is
only active if the parameter is set (it defaults to unset, i.e. the
feature is opt-in), if getting the version from the SCM failed, *and*
there's no metadata already present. However, this has higher priority
than `fallback_version` (which remains the last-resort fallback).
This feature is intended to support the tarballs that GitHub
automatically creates for all releases, which have no metadata but
follow the correct naming scheme for the feature to work.
This feature is directly inspired from versioneer's `parentdir_prefix`
setting.
Diffstat (limited to 'src')
-rw-r--r-- | src/setuptools_scm/__init__.py | 1 | ||||
-rw-r--r-- | src/setuptools_scm/config.py | 2 | ||||
-rw-r--r-- | src/setuptools_scm/hacks.py | 9 |
3 files changed, 11 insertions, 1 deletions
diff --git a/src/setuptools_scm/__init__.py b/src/setuptools_scm/__init__.py index eebd9bb..6b22b28 100644 --- a/src/setuptools_scm/__init__.py +++ b/src/setuptools_scm/__init__.py @@ -127,6 +127,7 @@ def get_version( write_to_template=None, relative_to=None, tag_regex=DEFAULT_TAG_REGEX, + parentdir_prefix_version=None, fallback_version=None, fallback_root=".", parse=None, diff --git a/src/setuptools_scm/config.py b/src/setuptools_scm/config.py index b452557..e7f4d72 100644 --- a/src/setuptools_scm/config.py +++ b/src/setuptools_scm/config.py @@ -49,6 +49,7 @@ class Configuration(object): write_to=None, write_to_template=None, tag_regex=DEFAULT_TAG_REGEX, + parentdir_prefix_version=None, fallback_version=None, fallback_root=".", parse=None, @@ -63,6 +64,7 @@ class Configuration(object): self.local_scheme = local_scheme self.write_to = write_to self.write_to_template = write_to_template + self.parentdir_prefix_version = parentdir_prefix_version self.fallback_version = fallback_version self.fallback_root = fallback_root self.parse = parse diff --git a/src/setuptools_scm/hacks.py b/src/setuptools_scm/hacks.py index 1ef0bb4..e0db383 100644 --- a/src/setuptools_scm/hacks.py +++ b/src/setuptools_scm/hacks.py @@ -1,6 +1,6 @@ import os from .utils import data_from_mime, trace -from .version import meta +from .version import tag_to_version, meta def parse_pkginfo(root, config=None): @@ -25,5 +25,12 @@ def parse_pip_egg_info(root, config=None): def fallback_version(root, config=None): + if config.parentdir_prefix_version is not None: + _, parent_name = os.path.split(os.path.abspath(root)) + if parent_name.startswith(config.parentdir_prefix_version): + version = tag_to_version( + parent_name[len(config.parentdir_prefix_version) :], config) + if version is not None: + return meta(str(version), preformatted=True, config=config) if config.fallback_version is not None: return meta(config.fallback_version, preformatted=True, config=config) |