diff options
author | Antony Lee <anntzer.lee@gmail.com> | 2018-09-05 18:22:42 +0200 |
---|---|---|
committer | Antony Lee <anntzer.lee@gmail.com> | 2019-03-03 20:54:19 +0100 |
commit | 04bde2dc07839780e7dab33f6e738b42ca963677 (patch) | |
tree | bf889c9753f62105c589f6c65058b569842549d3 | |
parent | 3892d5f24e3d863dcdf84bfab20485434bb4392f (diff) | |
download | setuptools-scm-04bde2dc07839780e7dab33f6e738b42ca963677.tar.gz |
Allow setting a fallback version in case everything else fails.
-rw-r--r-- | CHANGELOG.rst | 5 | ||||
-rw-r--r-- | README.rst | 18 | ||||
-rw-r--r-- | setup.py | 1 | ||||
-rw-r--r-- | src/setuptools_scm/__init__.py | 2 | ||||
-rw-r--r-- | src/setuptools_scm/config.py | 2 | ||||
-rw-r--r-- | src/setuptools_scm/hacks.py | 5 | ||||
-rw-r--r-- | testing/test_basic_api.py | 13 |
7 files changed, 40 insertions, 6 deletions
diff --git a/CHANGELOG.rst b/CHANGELOG.rst index f0b299d..4707051 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,3 +1,8 @@ +next +==== + +* fix #198 by adding the ``fallback_version`` option, which sets the version to be used when everything else fails. + v3.2.0 ====== @@ -253,12 +253,6 @@ The currently supported configuration keys are: repository to point ``setuptools_scm`` at the root of the repository by supplying ``__file__``. -:parse: - A function that will be used instead of the discovered SCM for parsing the - version. - Use with caution, this is a function for advanced use, and you should be - familiar with the ``setuptools_scm`` internals to use it. - :tag_regex: A Python regex string to extract the version part from any SCM tag. The regex needs to contain three named groups prefix, version and suffix, @@ -267,6 +261,18 @@ The currently supported configuration keys are: Defaults to the value of ``setuptools_scm.config.DEFAULT_TAG_REGEX`` (see `config.py <src/setuptools_scm/config.py>`_). +:fallback_version: + A version string that will be used if no other method for detecting the + version worked (e.g., when using a tarball with no metadata). If this is + unset (the default), setuptools_scm will error if it fails to detect the + version. + +:parse: + A function that will be used instead of the discovered SCM for parsing the + version. + Use with caution, this is a function for advanced use, and you should be + familiar with the ``setuptools_scm`` internals to use it. + :git_describe_command: This command will be used instead the default ``git describe`` command. Use with caution, this is a function for advanced use, and you should be @@ -76,6 +76,7 @@ arguments = dict( .hg_archival.txt = setuptools_scm.hg:parse_archival PKG-INFO = setuptools_scm.hacks:parse_pkginfo pip-egg-info = setuptools_scm.hacks:parse_pip_egg_info + setup.py = setuptools_scm.hacks:fallback_version [setuptools_scm.files_command] .hg = setuptools_scm.file_finder_hg:hg_find_files diff --git a/src/setuptools_scm/__init__.py b/src/setuptools_scm/__init__.py index f49cce4..f9ab5c2 100644 --- a/src/setuptools_scm/__init__.py +++ b/src/setuptools_scm/__init__.py @@ -120,6 +120,7 @@ def get_version( write_to_template=None, relative_to=None, tag_regex=None, + fallback_version=None, parse=None, git_describe_command=None, ): @@ -138,6 +139,7 @@ def get_version( config.write_to_template = write_to_template config.relative_to = relative_to config.tag_regex = tag_regex + config.fallback_version = fallback_version config.parse = parse config.git_describe_command = git_describe_command diff --git a/src/setuptools_scm/config.py b/src/setuptools_scm/config.py index 796dd0b..7b1d88b 100644 --- a/src/setuptools_scm/config.py +++ b/src/setuptools_scm/config.py @@ -44,6 +44,7 @@ class Configuration(object): local_scheme = None write_to = None write_to_template = None + fallback_version = None _relative_to = None parse = None _tag_regex = None @@ -59,6 +60,7 @@ class Configuration(object): self.local_scheme = "node-and-date" self.write_to = "" self.write_to_template = None + self.fallback_version = None self.parse = None self.tag_regex = DEFAULT_TAG_REGEX self.git_describe_command = None diff --git a/src/setuptools_scm/hacks.py b/src/setuptools_scm/hacks.py index a4ca586..1ef0bb4 100644 --- a/src/setuptools_scm/hacks.py +++ b/src/setuptools_scm/hacks.py @@ -22,3 +22,8 @@ def parse_pip_egg_info(root, config=None): if not items: return return parse_pkginfo(os.path.join(pipdir, items[0]), config=config) + + +def fallback_version(root, config=None): + if config.fallback_version is not None: + return meta(config.fallback_version, preformatted=True, config=config) diff --git a/testing/test_basic_api.py b/testing/test_basic_api.py index c032d23..5b5c6d6 100644 --- a/testing/test_basic_api.py +++ b/testing/test_basic_api.py @@ -1,4 +1,5 @@ import os +import sys import py import pytest @@ -56,6 +57,18 @@ def test_root_parameter_pass_by(monkeypatch, tmpdir): setuptools_scm.get_version(root=tmpdir.strpath) +def test_fallback(tmpdir, monkeypatch): + monkeypatch.delenv("SETUPTOOLS_SCM_DEBUG") + p = tmpdir.ensure("sub/package", dir=1) + p.join("setup.py").write( + """from setuptools import setup +setup(use_scm_version={"fallback_version": "12.34"}) +""" + ) + res = do((sys.executable, "setup.py", "--version"), p) + assert res == "12.34" + + @pytest.mark.parametrize( "version", ["1.0", "1.2.3.dev1+ge871260", "1.2.3.dev15+ge871260.d20180625", "2345"] ) |