예제 #1
0
def test_pkginfo_noscmroot(tmpdir, monkeypatch):
    """if we are indeed a sdist, the root does not apply"""
    monkeypatch.delenv("SETUPTOOLS_SCM_DEBUG")

    # we should get the version from pkg-info if git is broken
    p = tmpdir.ensure("sub/package", dir=1)
    tmpdir.mkdir(".git")
    p.join("setup.py").write("from setuptools import setup;"
                             'setup(use_scm_version={"root": ".."})')

    _, stderr, ret = do_ex((sys.executable, "setup.py", "--version"), p)
    assert "setuptools-scm was unable to detect version for" in stderr
    assert ret == 1

    p.join("PKG-INFO").write("Version: 1.0")
    res = do((sys.executable, "setup.py", "--version"), p)
    assert res == "1.0"

    try:
        do("git init", p.dirpath())
    except FileNotFoundError:
        pass
    else:
        res = do((sys.executable, "setup.py", "--version"), p)
        assert res == "0.1.dev0"
예제 #2
0
def shallow_wd(wd, tmpdir):
    wd.commit_testfile()
    wd.commit_testfile()
    wd.commit_testfile()
    target = tmpdir.join('wd_shallow')
    do(['git', 'clone', "file://%s" % wd.cwd, str(target,), '--depth=1'])
    return target
예제 #3
0
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
예제 #4
0
def shallow_wd(wd, tmpdir):
    wd.commit_testfile()
    wd.commit_testfile()
    wd.commit_testfile()
    target = tmpdir.join('wd_shallow')
    do(['git', 'clone', "file://%s" % wd.cwd, str(target,), '--depth=1'])
    return target
예제 #5
0
def repositories_hg_git(tmp_path):
    from setuptools_scm.utils import do

    tmp_path = tmp_path.resolve()
    path_git = tmp_path / "repo_git"
    path_git.mkdir()

    wd = Wd(path_git)
    wd("git init")
    wd("git config user.email [email protected]")
    wd('git config user.name "a test"')
    wd.add_command = "git add ."
    wd.commit_command = "git commit -m test-{reason}"

    path_hg = tmp_path / "repo_hg"
    do(f"hg clone {path_git} {path_hg} --config extensions.hggit=")
    assert path_hg.exists()

    with open(path_hg / ".hg/hgrc", "a") as file:
        file.write("[extensions]\nhggit =\n")

    wd_hg = Wd(path_hg)
    wd_hg.add_command = "hg add ."
    wd_hg.commit_command = 'hg commit -m test-{reason} -u test -d "0 0"'

    return wd_hg, wd
예제 #6
0
def shallow_wd(wd, tmpdir):
    wd.commit_testfile()
    wd.commit_testfile()
    wd.commit_testfile()
    target = tmpdir.join("wd_shallow")
    do(["git", "clone", "file://%s" % wd.cwd, str(target), "--depth=1"])
    return target
예제 #7
0
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
예제 #8
0
def test_pyproject_support_with_git(tmpdir, monkeypatch, wd):
    monkeypatch.delenv("SETUPTOOLS_SCM_DEBUG")
    pkg = tmpdir.join("wd")
    pkg.join("pyproject.toml").write("""[tool.setuptools_scm]""")
    pkg.join("setup.py").write("__import__('setuptools').setup()")
    res = do((sys.executable, "setup.py", "--version"), pkg)
    assert res == "0.1.dev0"
예제 #9
0
def test_pretend_version_named_pyproject_integration(tmpdir, monkeypatch, wd):
    test_pyproject_support_with_git(tmpdir, monkeypatch, wd)
    monkeypatch.setenv(
        PRETEND_KEY_NAMED.format(name="setuptools_scm_example".upper()),
        "3.2.1")
    res = do((sys.executable, "setup.py", "--version"), tmpdir / "wd")
    assert res.endswith("3.2.1")
예제 #10
0
def test_git_worktree_support(wd, tmpdir):
    wd.commit_testfile()
    worktree = tmpdir.join("work_tree")
    wd("git worktree add -b work-tree %s" % worktree)

    res = do([sys.executable, "-m", "setuptools_scm", "ls"], cwd=worktree)
    assert str(worktree) in res
예제 #11
0
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"
예제 #12
0
def test_pyproject_support_with_git(tmpdir, monkeypatch, wd):
    pytest.importorskip("toml")
    pkg = tmpdir.join("wd")
    pkg.join("pyproject.toml").write("""[tool.setuptools_scm]""")
    pkg.join("setup.py").write(
        "__import__('setuptools').setup(name='setuptools_scm_example')")
    res = do((sys.executable, "setup.py", "--version"), pkg)
    assert res.endswith("0.1.dev0")
예제 #13
0
def test_git_worktree_support(wd, tmp_path):
    wd.commit_testfile()
    worktree = tmp_path / "work_tree"
    wd("git worktree add -b work-tree %s" % worktree)

    res = do([sys.executable, "-m", "setuptools_scm", "ls"], cwd=worktree)
    assert "test.txt" in res
    assert str(worktree) in res
예제 #14
0
def test_parentdir_prefix(tmpdir, monkeypatch):
    monkeypatch.delenv("SETUPTOOLS_SCM_DEBUG")
    p = tmpdir.ensure("projectname-v12.34", dir=True)
    p.join("setup.py").write("""from setuptools import setup
setup(use_scm_version={"parentdir_prefix_version": "projectname-"})
""")
    res = do((sys.executable, "setup.py", "--version"), p)
    assert res == "12.34"
예제 #15
0
def test_root_search_parent_directories(tmpdir, wd, monkeypatch):
    monkeypatch.delenv("SETUPTOOLS_SCM_DEBUG")
    p = wd.cwd.joinpath("sub/package")
    p.mkdir(parents=True)
    p.joinpath("setup.py").write_text("""from setuptools import setup
setup(use_scm_version={"search_parent_directories": True})
""")
    res = do((sys.executable, "setup.py", "--version"), p)
    assert res == "0.1.dev0"
예제 #16
0
def test_root_relative_to(tmpdir, wd, monkeypatch):
    monkeypatch.delenv("SETUPTOOLS_SCM_DEBUG")
    p = wd.cwd.ensure("sub/package", dir=1)
    p.join("setup.py").write("""from setuptools import setup
setup(use_scm_version={"root": "../..",
                       "relative_to": __file__})
""")
    res = do((sys.executable, "setup.py", "--version"), p)
    assert res == "0.1.dev0"
예제 #17
0
def test_pyproject_support(tmpdir, monkeypatch):
    pytest.importorskip("toml")
    monkeypatch.delenv("SETUPTOOLS_SCM_DEBUG")
    pkg = tmpdir.ensure("package", dir=42)
    pkg.join("pyproject.toml").write("""[tool.setuptools_scm]
fallback_version = "12.34"
""")
    pkg.join("setup.py").write("__import__('setuptools').setup()")
    res = do((sys.executable, "setup.py", "--version"), pkg)
    assert res == "12.34"
예제 #18
0
def test_git_version_unnormalized_setuptools(with_class, tmpdir, wd,
                                             monkeypatch):
    """
    Test that when integrating with setuptools without normalization,
    the version is not normalized in write_to files,
    but still normalized by setuptools for the final dist metadata.
    """
    monkeypatch.delenv("SETUPTOOLS_SCM_DEBUG")
    p = wd.cwd

    # create a setup.py
    dest_file = str(tmpdir.join("VERSION.txt")).replace("\\", "/")
    if with_class is False:
        # try normalize = False
        setup_py = """
from setuptools import setup
setup(use_scm_version={'normalize': False, 'write_to': '%s'})
"""
    elif with_class is type:
        # custom non-normalizing class
        setup_py = """
from setuptools import setup

class MyVersion:
    def __init__(self, tag_str: str):
        self.version = tag_str

    def __repr__(self):
        return self.version

setup(use_scm_version={'version_cls': MyVersion, 'write_to': '%s'})
"""
    elif with_class is str:
        # non-normalizing class referenced by name
        setup_py = """from setuptools import setup
setup(use_scm_version={
    'version_cls': 'setuptools_scm.NonNormalizedVersion',
    'write_to': '%s'
})
"""

    # finally write the setup.py file
    p.joinpath("setup.py").write_text(setup_py % dest_file)

    # do git operations and tag
    wd.commit_testfile()
    wd("git tag 17.33.0-rc1")

    # setuptools still normalizes using packaging.Version (removing the dash)
    res = do((sys.executable, "setup.py", "--version"), p)
    assert res == "17.33.0rc1"

    # but the version tag in the file is non-normalized (with the dash)
    assert tmpdir.join("VERSION.txt").read() == "17.33.0-rc1"
예제 #19
0
def test_pkginfo_noscmroot(tmpdir, monkeypatch):
    """if we are indeed a sdist, the root does not apply"""
    monkeypatch.delenv("SETUPTOOLS_SCM_DEBUG")

    # we should get the version from pkg-info if git is broken
    p = tmpdir.ensure('sub/package', dir=1)
    tmpdir.mkdir('.git')
    p.join('setup.py').write('from setuptools import setup;'
                             'setup(use_scm_version={"root": ".."})')

    _, stderr, ret = do_ex('python setup.py --version', p)
    assert 'setuptools-scm was unable to detect version for' in stderr
    assert ret == 1

    p.join("PKG-INFO").write('Version: 1.0')
    res = do('python setup.py --version', p)
    assert res == '1.0'

    do('git init', p.dirpath())
    res = do('python setup.py --version', p)
    assert res == '1.0'
예제 #20
0
def test_pkginfo_noscmroot(tmpdir, monkeypatch):
    """if we are indeed a sdist, the root does not apply"""
    monkeypatch.delenv("SETUPTOOLS_SCM_DEBUG")

    # we should get the version from pkg-info if git is broken
    p = tmpdir.ensure('sub/package', dir=1)
    tmpdir.mkdir('.git')
    p.join('setup.py').write(
        'from setuptools import setup;'
        'setup(use_scm_version={"root": ".."})')

    _, stderr, ret = do_ex('python setup.py --version', p)
    assert 'setuptools-scm was unable to detect version for' in stderr
    assert ret == 1

    p.join("PKG-INFO").write('Version: 1.0')
    res = do('python setup.py --version', p)
    assert res == '1.0'

    do('git init', p.dirpath())
    res = do('python setup.py --version', p)
    assert res == '1.0'
예제 #21
0
def test_pyproject_support(tmpdir, monkeypatch):
    pytest.importorskip("toml")
    monkeypatch.delenv("SETUPTOOLS_SCM_DEBUG")
    pkg = tmpdir.ensure("package", dir=42)
    pkg.join("pyproject.toml").write_text(
        textwrap.dedent("""
            [tool.setuptools_scm]
            fallback_version = "12.34"
            [project]
            description = "Factory ⸻ A code generator 🏭"
            authors = [{name = "Łukasz Langa"}]
            """),
        encoding="utf-8",
    )
    pkg.join("setup.py").write("__import__('setuptools').setup()")
    res = do((sys.executable, "setup.py", "--version"), pkg)
    assert res == "12.34"
예제 #22
0
def test_use_scm_version_callable(tmpdir, monkeypatch):
    """use of callable as use_scm_version argument"""
    monkeypatch.delenv("SETUPTOOLS_SCM_DEBUG")

    p = tmpdir.ensure("sub/package", dir=1)
    p.join("setup.py").write("""from setuptools import setup
def vcfg():
    from setuptools_scm.version import guess_next_dev_version
    def vs(v):
        return guess_next_dev_version(v)
    return {"version_scheme": vs}
setup(use_scm_version=vcfg)
""")
    p.join("PKG-INFO").write("Version: 1.0")

    res = do((sys.executable, "setup.py", "--version"), p)
    assert res == "1.0"
예제 #23
0
def test_use_scm_version_callable(tmpdir, monkeypatch):
    """use of callable as use_scm_version argument"""
    monkeypatch.delenv("SETUPTOOLS_SCM_DEBUG")

    p = tmpdir.ensure('sub/package', dir=1)
    p.join('setup.py').write('''from setuptools import setup
def vcfg():
    from setuptools_scm.version import guess_next_dev_version
    def vs(v):
        return guess_next_dev_version(v)
    return {"version_scheme": vs}
setup(use_scm_version=vcfg)
''')
    p.join("PKG-INFO").write('Version: 1.0')

    res = do('python setup.py --version', p)
    assert res == '1.0'
예제 #24
0
def test_use_scm_version_callable(tmpdir, monkeypatch):
    """use of callable as use_scm_version argument"""
    monkeypatch.delenv("SETUPTOOLS_SCM_DEBUG")

    p = tmpdir.ensure('sub/package', dir=1)
    p.join('setup.py').write(
        '''from setuptools import setup
def vcfg():
    from setuptools_scm.version import guess_next_dev_version
    def vs(v):
        return guess_next_dev_version(v)
    return {"version_scheme": vs}
setup(use_scm_version=vcfg)
''')
    p.join("PKG-INFO").write('Version: 1.0')

    res = do('python setup.py --version', p)
    assert res == '1.0'
예제 #25
0
 def __call__(self, cmd):
     do(cmd, str(self.cwd))
예제 #26
0
 def __call__(self, cmd, **kw):
     if kw:
         cmd = cmd.format(**kw)
     from setuptools_scm.utils import do
     return do(cmd, self.cwd)
예제 #27
0
 def __call__(self, cmd):
     return do(cmd, self.cwd)
예제 #28
0
 def __call__(self, cmd, **kw):
     if kw:
         cmd = cmd.format(**kw)
     from setuptools_scm.utils import do
     return do(cmd, self.cwd)
예제 #29
0
def test_do(cmd, tmpdir):
    if not py.path.local.sysfind(cmd):
        pytest.skip(cmd + " not found")
    do(cmd, str(tmpdir))
예제 #30
0
def test_do(cmd, tmpdir):
    if not py.path.local.sysfind(cmd):
        pytest.skip(cmd + ' not found')
    do(cmd, str(tmpdir))
예제 #31
0
 def __call__(self, cmd):
     return do(cmd, self.cwd)