def guess_next_dev(version): from setuptools_scm import git from setuptools_scm.version import guess_next_version erfa_version = git.parse(LIBERFADIR) if not erfa_version.exact: warn(f'liberfa/erfa not at a tagged release, but at {erfa_version}') erfa_tag = erfa_version.format_with("{tag}") version_string = str(version.tag) if version.exact: if not version_string.startswith(erfa_tag): warn( f'tag {version_string} does not start with liberfa/erfa tag {erfa_tag}' ) return version_string else: if erfa_tag > version_string: guessed = erfa_tag elif 'dev' in version_string or len(version_string.split('.')) > 3: return guess_next_version(version.tag) else: guessed = version_string.partition("+")[0] + '.1' return version.format_with("{guessed}.dev{distance}", guessed=guessed)
def test_case_mismatch_on_windows_git(tmpdir): """Case insensitive path checks on Windows""" p = tmpdir.ensure("CapitalizedDir", dir=1) do("git init", p) res = parse(str(p).lower()) assert res is not None
def test_version_from_git(wd): assert wd.version == "0.1.dev0" assert git.parse(str(wd.cwd), git.DEFAULT_DESCRIBE).branch == "master" wd.commit_testfile() assert wd.version.startswith("0.1.dev1+g") assert not wd.version.endswith("1-") wd("git tag v0.1") assert wd.version == "0.1" wd.write("test.txt", "test2") assert wd.version.startswith("0.2.dev0+g") wd.commit_testfile() assert wd.version.startswith("0.2.dev1+g") wd("git tag version-0.2") assert wd.version.startswith("0.2") wd.commit_testfile() wd("git tag version-0.2.post210+gbe48adfpost3+g0cc25f2") with pytest.warns(UserWarning, match="tag '.*' will be stripped of its suffix '.*'"): assert wd.version.startswith("0.2") wd.commit_testfile() wd("git tag 17.33.0-rc") assert wd.version == "17.33.0rc0"
def test_case_mismatch_on_windows_git(tmpdir): """Case insensitive path checks on Windows""" p = tmpdir.ensure("CapitalizedDir", dir=1) do('git init', p) res = parse(str(p).lower()) assert res is not None
def _guess_next_dev(version, liberfadir=None): if liberfadir is None: liberfadir = pathlib.Path( __file__).parent.parent.parent / 'liberfa' / 'erfa' erfa_version = git.parse(liberfadir) if not erfa_version.exact: warn( f'liberfa/erfa not at a tagged release, but at {erfa_version}') erfa_tag = erfa_version.format_with("{tag}") version_string = str(version.tag) if version.exact: if not version_string.startswith(erfa_tag): warn(f'tag {version_string} does not start with ' f'liberfa/erfa tag {erfa_tag}') return version_string else: if erfa_tag > version_string: guessed = erfa_tag elif 'dev' in version_string or len(version_string.split('.')) > 3: return guess_next_version(version.tag) else: guessed = version_string.partition("+")[0] + '.1' return version.format_with("{guessed}.dev{distance}", guessed=guessed)
def parse_git(root, **kwargs): """ Parse function for setuptools_scm """ from setuptools_scm.git import parse kwargs["describe_command"] = "git describe --dirty --tags --long" return parse(root, **kwargs)
def parse_git(root, **kwargs): """ Parse function for setuptools_scm that ignores tags for non-C++ subprojects, e.g. apache-arrow-js-XXX tags. """ from setuptools_scm.git import parse kwargs['describe_command'] = \ "git describe --dirty --tags --long --match 'apache-arrow-[0-9].*'" return parse(root, **kwargs)
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_git_getdate(wd): # TODO: case coverage for git wd parse today = date.today() def parse_date(): return git.parse(os.fspath(wd.cwd)).node_date git_wd = git.GitWorkdir(os.fspath(wd.cwd)) assert git_wd.get_head_date() is None assert parse_date() == today wd.commit_testfile() assert git_wd.get_head_date() == today meta = git.parse(os.fspath(wd.cwd)) assert meta.node_date == today
def parse_with_fetch(*args, **kwargs) -> str: """If the repo is found to be shallow, fetch a full. By default, RTD does a fetch --limit 50, if a tag is not present in the last 50 commits, the version reported by setuptools_scm will be incorrect and appears as ``v0.1.dev...`` in the towncrier changelog. Another approach is to enable ``DONT_SHALLOW_CLONE`` for the repo https://docs.readthedocs.io/en/stable/feature-flags.html#feature-flags This was done for ansible-navigator on the day of this commit. :param args: The arguments :param kwargs: The keyword arguments :returns: The parsed version """ assert "pre_parse" not in kwargs return parse(*args, pre_parse=fetch_on_shallow, **kwargs)
def test_version_from_git(wd): assert wd.version == "0.1.dev0" assert git.parse(str(wd.cwd), git.DEFAULT_DESCRIBE).branch == "master" wd.commit_testfile() assert wd.version.startswith("0.1.dev1+g") assert not wd.version.endswith("1-") wd("git tag v0.1") assert wd.version == "0.1" wd.write("test.txt", "test2") assert wd.version.startswith("0.2.dev0+g") wd.commit_testfile() assert wd.version.startswith("0.2.dev1+g") wd("git tag version-0.2") assert wd.version.startswith("0.2") wd.commit_testfile() wd("git tag version-0.2.post210+gbe48adfpost3+g0cc25f2") with pytest.warns(UserWarning, match="tag '.*' will be stripped of its suffix '.*'"): assert wd.version.startswith("0.2") wd.commit_testfile() wd("git tag 17.33.0-rc") assert wd.version == "17.33.0rc0" # custom normalization assert wd.get_version(normalize=False) == "17.33.0-rc" assert wd.get_version(version_cls=NonNormalizedVersion) == "17.33.0-rc" assert (wd.get_version( version_cls="setuptools_scm.NonNormalizedVersion") == "17.33.0-rc")
def test_git_parse_shallow_fail(shallow_wd): with pytest.raises(ValueError) as einfo: git.parse(str(shallow_wd), pre_parse=git.fail_on_shallow) assert "git fetch" in str(einfo.value)
def test_git_parse_shallow_warns(shallow_wd, recwarn): git.parse(str(shallow_wd)) msg = recwarn.pop() assert "is shallow and may cause errors" in str(msg.message)
def parse_date(): return git.parse(os.fspath(wd.cwd)).node_date
def parse(root, config): try: return parse_pkginfo(root, config) except OSError: return git.parse(root, config=config) or hg.parse(root, config=config)
def test_parse_call_order(wd): git.parse(str(wd.cwd), git.DEFAULT_DESCRIBE)
def test_git_shallow_autocorrect(shallow_wd, recwarn): git.parse(str(shallow_wd), pre_parse=git.fetch_on_shallow) msg = recwarn.pop() assert 'git fetch was used to rectify' in str(msg.message) git.parse(str(shallow_wd), pre_parse=git.fail_on_shallow)
def test_git_parse_shallow_warns(shallow_wd, recwarn): git.parse(str(shallow_wd)) msg = recwarn.pop() assert 'is shallow and may cause errors' in str(msg.message)
def parse_fetch_on_shallow(root): from setuptools_scm.git import parse, fetch_on_shallow return parse(root, pre_parse=fetch_on_shallow)
def test_git_shallow_autocorrect(shallow_wd, recwarn): git.parse(str(shallow_wd), pre_parse=git.fetch_on_shallow) msg = recwarn.pop() assert "git fetch was used to rectify" in str(msg.message) git.parse(str(shallow_wd), pre_parse=git.fail_on_shallow)
def test_parse_no_worktree(tmpdir): ret = git.parse(str(tmpdir)) assert ret is None
def test_git_gone(wd, monkeypatch): monkeypatch.setenv("PATH", str(wd.cwd / "not-existing")) with pytest.raises(EnvironmentError, match="'git' was not found"): git.parse(str(wd.cwd), git.DEFAULT_DESCRIBE)
def test_git_parse_shallow_fail(shallow_wd): with pytest.raises(ValueError) as einfo: git.parse(str(shallow_wd), pre_parse=git.fail_on_shallow) assert 'git fetch' in str(einfo.value)
def parse_git(root, **kwargs): from setuptools_scm.git import parse kwargs[ "describe_command"] = 'git describe --dirty --tags --long --match "[0-9].*"' return parse(root, **kwargs)