summaryrefslogtreecommitdiff
path: root/src/setuptools_scm/hacks.py
diff options
context:
space:
mode:
authorAntony Lee <anntzer.lee@gmail.com>2020-03-22 14:48:32 +0100
committerAntony Lee <anntzer.lee@gmail.com>2020-05-01 16:28:29 +0200
commitaaab738a9e698b4d84c1f0724341a1b009b766ea (patch)
tree60e4d269e19a7d5b49ed6f74c7c1cf76a8ad8777 /src/setuptools_scm/hacks.py
parent200c56667fd8446056ec365b95ea2dccdd0a9a1b (diff)
downloadsetuptools-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/setuptools_scm/hacks.py')
-rw-r--r--src/setuptools_scm/hacks.py9
1 files changed, 8 insertions, 1 deletions
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)