def test_tag_regex1(tag, expected): if "+" in tag: # pytest bug wrt cardinality with pytest.warns(UserWarning): result = meta(tag, config=c) else: result = meta(tag, config=c) assert result.tag.public == expected
def test_tag_regex1(tag, expected): config = Configuration() config.tag_regex = r"^(?P<prefix>v)?(?P<version>[^\+]+)(?P<suffix>.*)?$" if "+" in tag: # pytest bug wrt cardinality with pytest.warns(UserWarning): result = meta(tag, config=config) else: result = meta(tag, config=config) assert result.tag.public == expected
def myparse( root, describe_command=DEFAULT_DESCRIBE, config=None): """ rewriting of setuptools_scm.git.parse method to remove -branch string from any tags. This library is clearly not designed for people to adjust its function so I had to lift entire function from Aug 8 master with SHA a91b40c99ea9bfc4289272285f17e1d43c243b76 """ if not config: config = Configuration(root=root) if not has_command("git"): return wd = GitWorkdir.from_potential_worktree(config.absolute_root) if wd is None: return out, unused_err, ret = wd.do_ex(describe_command) if ret: # If 'git describe' failed, try to get the information otherwise. rev_node = wd.node() dirty = wd.is_dirty() if rev_node is None: return meta("0.0", distance=0, dirty=dirty, config=config) return meta( "0.0", distance=wd.count_all_nodes(), node="g" + rev_node, dirty=dirty, branch=wd.get_branch(), config=config, ) else: tag, number, node, dirty = _git_parse_describe(out) branch = wd.get_branch() if number: return meta( tag.replace('-branch',''), config=config, distance=number, node=node, dirty=dirty, branch=branch, ) else: return meta(tag.replace('-branch', ''), config=config, node=node, dirty=dirty, branch=branch)
def test_format_version_schemes(): version = meta("1.0", config=c) format_version( version, local_scheme="no-local-version", version_scheme=[lambda v: None, "guess-next-dev"], )
def test_branch_master(): v = meta("0.1.0", config=c, branch="master", distance=1, node="aaaaaaa") out = format_version(v, local_scheme=branch_scheme, version_scheme="guess-next-dev") assert out == "0.1.1.dev1+aaaaaaa"
def test_no_branch_there(): v = meta("0.1.0", config=c, branch="branch", distance=None) out = format_version(v, local_scheme=branch_scheme, version_scheme="guess-next-dev") assert out == "0.1.0"
def parse_version(root, **kwargs): """ Parse function for setuptools_scm that first tries to read '../VERSION' file to get a version number. """ from setuptools_scm.git import parse from setuptools_scm.version import meta version_file = os.path.join(repo_root, "..", "VERSION") if os.path.isfile(version_file): with open(version_file, "r", encoding="utf-8") as fp: return meta(fp.read().strip()) return parse(root, **kwargs)
def test_custom_version_cls(): """Test that we can pass our own version class instead of pkg_resources""" class MyVersion: def __init__(self, tag_str: str): self.tag = tag_str def __repr__(self): return "Custom %s" % self.tag scm_version = meta("1.0.0-foo", config=Configuration(version_cls=MyVersion)) assert isinstance(scm_version.tag, MyVersion) assert repr(scm_version.tag) == "Custom 1.0.0-foo"
def parse(root): import glob from setuptools_scm.utils import trace from setuptools_scm.version import meta for p in glob.iglob(os.path.join(root, '**/__about__.py')): try: about = {} with open(p) as f: exec(f.read(), about) return meta('{0}.dev0+unknown'.format(about["__version__"]), preformatted=True) except: trace('no __version__ in', p) continue else: return None
def parse(root, *, config): """ Based on https://github.com/pypa/setuptools_scm/blob/master/src/setuptools_scm/git.py#parse This is almost a verbatim copy, except that we tell setuptools_scm that the tag is preformatted to prevent them from applying Python's version normalisation. """ if not has_command("git"): return wd = GitWorkdir.from_potential_worktree(config.absolute_root) if wd is None: return warn_on_shallow(wd) describe_command = config.git_describe_command or DEFAULT_DESCRIBE out, unused_err, ret = wd.do_ex(describe_command) if ret: # If 'git git_describe_command' failed, try to get the information otherwise. tag = '0.1.0' distance = wd.count_all_nodes() dirty = wd.is_dirty() node = None branch = None rev_node = wd.node() if rev_node is not None: node = f'g{rev_node}' branch = wd.get_branch() else: tag, distance, node, dirty = _git_parse_describe(out) branch = wd.get_branch() version = meta( semver.parse_version_info(tag), distance=distance, dirty=dirty, node=node, preformatted=True, config=config, branch=branch ) version.preformatted = False return version
def parse_git_describe_string(_root, config=None): """ Return a setuptools_scm parsed version from a Git describe string found in the environment variable GIT_DESCRIBE_STRING. :param str _root: Relative path to cwd, used for finding the scm root. :param setuptools_scm.config.Configuration config: Configuration instance. :return: Parsed version or ``None``. :rtype: setuptools_scm.version.ScmVersion """ # pylint: disable=import-error # Those imports are only available at install time from setuptools_scm.git import _git_parse_describe from setuptools_scm.version import meta git_describe = os.environ.get('GIT_DESCRIBE_STRING') if not git_describe: return None tag, number, node, dirty = _git_parse_describe(git_describe) kwargs = {'distance': number} if number else {} return meta(tag, dirty=dirty, node=node, config=config, **kwargs)
@pytest.mark.parametrize( "tag, expected", [ ("1.1", "1.2.dev0"), ("1.2.dev", "1.2.dev0"), ("1.1a2", "1.1a3.dev0"), ("23.24.post2+deadbeef", "23.24.post3.dev0"), ], ) def test_next_tag(tag, expected): version = pkg_resources.parse_version(tag) assert guess_next_version(version, 0) == expected VERSIONS = { "exact": meta("1.1", None, False), "zerodistance": meta("1.1", 0, False), "dirty": meta("1.1", None, True), "distance": meta("1.1", 3, False), "distancedirty": meta("1.1", 3, True), } @pytest.mark.parametrize( "version,scheme,expected", [ ("exact", "guess-next-dev node-and-date", "1.1"), ("zerodistance", "guess-next-dev node-and-date", "1.2.dev0"), ("dirty", "guess-next-dev node-and-date", "1.2.dev0+dtime"), ("distance", "guess-next-dev node-and-date", "1.2.dev3"), ("distancedirty", "guess-next-dev node-and-date", "1.2.dev3+dtime"),
def archival_to_version(data): trace('data', data) versions = tags_to_versions(tag_re.findall(data.get('ref-names', ''))) if versions: return meta(versions[0])
from setuptools_scm.version import ( meta, simplified_semver_version, release_branch_semver_version, tags_to_versions, no_guess_dev_version, guess_next_version, ) c = Configuration() @pytest.mark.parametrize( "version, expected_next", [ pytest.param(meta("1.0.0", config=c), "1.0.0", id="exact"), pytest.param(meta("1.0", config=c), "1.0.0", id="short_tag"), pytest.param( meta("1.0.0", distance=2, branch="default", config=c), "1.0.1.dev2", id="normal_branch", ), pytest.param( meta("1.0", distance=2, branch="default", config=c), "1.0.1.dev2", id="normal_branch_short_tag", ), pytest.param( meta("1.0.0", distance=2, branch="feature", config=c), "1.1.0.dev2", id="feature_branch",
def test_calver_by_date_future_warning(): with pytest.warns(UserWarning, match="your previous tag*"): calver_by_date(meta(date_to_str(days_offset=-2), config=c, distance=2))
return 'time' @pytest.mark.parametrize('tag, expected', [ ('1.1', '1.2.dev0'), ('1.2.dev', '1.2.dev0'), ('1.1a2', '1.1a3.dev0'), ('23.24.post2+deadbeef', '23.24.post3.dev0'), ]) def test_next_tag(tag, expected): version = pkg_resources.parse_version(tag) assert guess_next_version(version, 0) == expected VERSIONS = { 'exact': meta('1.1', None, False), 'zerodistance': meta('1.1', 0, False), 'dirty': meta('1.1', None, True), 'distance': meta('1.1', 3, False), 'distancedirty': meta('1.1', 3, True), } @pytest.mark.parametrize('version,scheme,expected', [ ('exact', 'guess-next-dev node-and-date', '1.1'), ('zerodistance', 'guess-next-dev node-and-date', '1.2.dev0'), ('dirty', 'guess-next-dev node-and-date', '1.2.dev0+dtime'), ('distance', 'guess-next-dev node-and-date', '1.2.dev3'), ('distancedirty', 'guess-next-dev node-and-date', '1.2.dev3+dtime'), ('exact', 'post-release node-and-date', '1.1'), ('zerodistance', 'post-release node-and-date', '1.1.post0'),
simplified_semver_version, release_branch_semver_version, tags_to_versions, no_guess_dev_version, guess_next_version, format_version, calver_by_date, ) c = Configuration() @pytest.mark.parametrize( "version, expected_next", [ pytest.param(meta("1.0.0", config=c), "1.0.0", id="exact"), pytest.param(meta("1.0", config=c), "1.0.0", id="short_tag"), pytest.param( meta("1.0.0", distance=2, branch="default", config=c), "1.0.1.dev2", id="normal_branch", ), pytest.param( meta("1.0", distance=2, branch="default", config=c), "1.0.1.dev2", id="normal_branch_short_tag", ), pytest.param( meta("1.0.0", distance=2, branch="feature", config=c), "1.1.0.dev2", id="feature_branch",
def __format__(self, *k): return 'time' @pytest.mark.parametrize('tag, expected', [ ('1.1', '1.2.dev0'), ('1.2.dev', '1.2.dev0'), ('1.1a2', '1.1a3.dev0'), ]) def test_next_tag(tag, expected): version = pkg_resources.parse_version(tag) assert guess_next_version(version, 0) == expected VERSIONS = { 'exact': meta('1.1', None, False), 'zerodistance': meta('1.1', 0, False), 'dirty': meta('1.1', None, True), 'distance': meta('1.1', 3, False), 'distancedirty': meta('1.1', 3, True), } @pytest.mark.parametrize('version,scheme,expected', [ ('exact', 'guess-next-dev node-and-date', '1.1'), ('zerodistance', 'guess-next-dev node-and-date', '1.2.dev0+nNone'), ('dirty', 'guess-next-dev node-and-date', '1.2.dev0+nNone.dtime'), ('distance', 'guess-next-dev node-and-date', '1.2.dev3+nNone'), ('distancedirty', 'guess-next-dev node-and-date', '1.2.dev3+nNone.dtime'), ('exact', 'post-release node-and-date', '1.1'), ('zerodistance', 'post-release node-and-date', '1.1.post0+nNone'),
def test_tag_regex1(tag, expected): Configuration( ).tag_regex = r"^(?P<prefix>v)?(?P<version>[^\+]+)(?P<suffix>.*)?$" result = meta(tag) assert result.tag.public == expected
import pytest from setuptools_scm.config import Configuration from setuptools_scm.version import meta, simplified_semver_version, tags_to_versions @pytest.mark.parametrize( "version, expected_next", [ pytest.param(meta("1.0.0"), "1.0.0", id="exact"), pytest.param(meta("1.0"), "1.0.0", id="short_tag"), pytest.param( meta("1.0.0", distance=2, branch="default"), "1.0.1.dev2", id="normal_branch", ), pytest.param( meta("1.0", distance=2, branch="default"), "1.0.1.dev2", id="normal_branch_short_tag", ), pytest.param( meta("1.0.0", distance=2, branch="feature"), "1.1.0.dev2", id="feature_branch", ), pytest.param( meta("1.0", distance=2, branch="feature"), "1.1.0.dev2", id="feature_branch_short_tag", ), pytest.param(
import pytest from setuptools_scm.version import meta, simplified_semver_version @pytest.mark.parametrize('version, expected_next', [ pytest.param(meta("1.0.0"), "1.0.0", id='exact'), pytest.param(meta("1.0"), "1.0.0", id='short_tag'), pytest.param(meta("1.0.0", distance=2, branch='default'), "1.0.1.dev2", id='normal_branch'), pytest.param(meta("1.0", distance=2, branch='default'), "1.0.1.dev2", id='normal_branch_short_tag'), pytest.param(meta("1.0.0", distance=2, branch='feature'), "1.1.0.dev2", id='feature_branch'), pytest.param(meta("1.0", distance=2, branch='feature'), "1.1.0.dev2", id='feature_branch_short_tag'), pytest.param(meta("1.0.0", distance=2, branch='features/test'), "1.1.0.dev2", id='feature_in_branch'), ]) def test_next_semver(version, expected_next): computed = simplified_semver_version(version) assert computed == expected_next
@pytest.mark.parametrize( "tag, expected", [ ("1.1", "1.2"), ("1.2.dev", "1.2"), ("1.1a2", "1.1a3"), ("23.24.post2+deadbeef", "23.24.post3"), ], ) def test_next_tag(tag, expected): version = pkg_resources.parse_version(tag) assert guess_next_version(version) == expected VERSIONS = { "exact": meta("1.1", None, False), "zerodistance": meta("1.1", 0, False), "dirty": meta("1.1", None, True), "distance": meta("1.1", 3, False), "distancedirty": meta("1.1", 3, True), } @pytest.mark.parametrize( "version,scheme,expected", [ ("exact", "guess-next-dev node-and-date", "1.1"), ("zerodistance", "guess-next-dev node-and-date", "1.2.dev0"), ("dirty", "guess-next-dev node-and-date", "1.2.dev0+dtime"), ("distance", "guess-next-dev node-and-date", "1.2.dev3"), ("distancedirty", "guess-next-dev node-and-date", "1.2.dev3+dtime"),
def test_next_semver_bad_tag(): version = meta("1.0.0-foo", config=c) with pytest.raises(ValueError, match="1.0.0-foo can't be parsed as numeric version"): simplified_semver_version(version)
@pytest.mark.parametrize( "tag, expected", [ ("1.1", "1.2"), ("1.2.dev", "1.2"), ("1.1a2", "1.1a3"), ("23.24.post2+deadbeef", "23.24.post3"), ], ) def test_next_tag(tag, expected): version = pkg_resources.parse_version(tag) assert guess_next_version(version) == expected VERSIONS = { "exact": meta("1.1", distance=None, dirty=False), "zerodistance": meta("1.1", distance=0, dirty=False), "dirty": meta("1.1", distance=None, dirty=True), "distance": meta("1.1", distance=3, dirty=False), "distancedirty": meta("1.1", distance=3, dirty=True), } @pytest.mark.parametrize( "version,scheme,expected", [ ("exact", "guess-next-dev node-and-date", "1.1"), ("zerodistance", "guess-next-dev node-and-date", "1.2.dev0"), ("dirty", "guess-next-dev node-and-date", "1.2.dev0+dtime"), ("distance", "guess-next-dev node-and-date", "1.2.dev3"), ("distancedirty", "guess-next-dev node-and-date", "1.2.dev3+dtime"),