예제 #1
0
def _check_hg_git():
    if not has_command("hg", warn=False):
        pytest.skip("hg executable not found")

    python_hg, err, ret = do_ex("hg debuginstall --template {pythonexe}")

    if ret:
        skip_no_hggit = True
    else:
        out, err, ret = do_ex([python_hg.strip(), "-c", "import hggit"])
    skip_no_hggit = bool(ret)
    if skip_no_hggit:
        pytest.skip("hg-git not installed")
예제 #2
0
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)
예제 #3
0
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
예제 #4
0
def test_has_command(recwarn):
    assert not has_command("yadayada_setuptools_aint_ne")
    msg = recwarn.pop()
    assert "yadayada" in str(msg.message)
예제 #5
0
from setuptools_scm import format_version
from setuptools_scm.hg import archival_to_version, parse
from setuptools_scm import integration
from setuptools_scm.config import Configuration
from setuptools_scm.utils import has_command
import pytest
import warnings

with warnings.catch_warnings():
    warnings.filterwarnings("ignore")
    if not has_command("hg"):
        pytestmark = pytest.mark.skip(reason="hg executable not found")


@pytest.fixture
def wd(wd):
    wd("hg init")
    wd.add_command = "hg add ."
    wd.commit_command = 'hg commit -m test-{reason} -u test -d "0 0"'
    return wd


archival_mapping = {
    "1.0": {
        "tag": "1.0"
    },
    "1.1.dev3+h000000000000": {
        "latesttag": "1.0",
        "latesttagdistance": "3",
        "node": "0" * 20,
    },
예제 #6
0
import sys

from setuptools_scm import integration
from setuptools_scm.utils import do, has_command
from setuptools_scm import git
import pytest
from datetime import datetime
from os.path import join as opj
from setuptools_scm.file_finder_git import git_find_files

skip_if_win_27 = pytest.mark.skipif(
    sys.platform == "win32" and sys.version_info[0] < 3,
    reason="Not supported on Windows + Python 2.7",
)

pytestmark = pytest.mark.skipif(not has_command("git", warn=False),
                                reason="git executable not found")


@pytest.fixture
def wd(wd, monkeypatch):
    monkeypatch.delenv("HOME", raising=False)
    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}"
    return wd


@pytest.mark.parametrize(
예제 #7
0
import sys

from setuptools_scm import integration
from setuptools_scm.utils import do, has_command
from setuptools_scm import git
import pytest
from datetime import datetime
from os.path import join as opj
from setuptools_scm.file_finder_git import git_find_files
import warnings

with warnings.catch_warnings():
    warnings.filterwarnings("ignore")
    if not has_command("git"):
        pytestmark = pytest.mark.skip(reason="git executable not found")


@pytest.fixture
def wd(wd, monkeypatch):
    monkeypatch.delenv("HOME", raising=False)
    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}"
    return wd


@pytest.mark.parametrize(
    "given, tag, number, node, dirty",
    [
예제 #8
0
def parse(root,
          describe_command=DEFAULT_DESCRIBE,
          pre_parse=warn_on_shallow,
          config=None):
    """
    :param pre_parse: experimental pre_parse action, may change at any time
    """
    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
    if pre_parse:
        pre_parse(wd)

    if config.git_describe_command:
        describe_command = config.git_describe_command

    out, unused_err, ret = wd.do_ex(describe_command)
    if ret:
        # If 'git git_describe_command' failed, try to get the information otherwise.
        branch, err, ret = wd.do_ex("git symbolic-ref --short HEAD")

        rev_node = wd.node()
        dirty = wd.is_dirty()

        if rev_node is None:
            return meta("0.0",
                        distance=0,
                        dirty=dirty,
                        branch=branch,
                        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,
                config=config,
                distance=number,
                node=node,
                dirty=dirty,
                branch=branch,
            )
        else:
            return meta(tag,
                        config=config,
                        node=node,
                        dirty=dirty,
                        branch=branch)
예제 #9
0
def test_has_command(recwarn):
    assert not has_command("yadayada_setuptools_aint_ne")
    msg = recwarn.pop()
    assert "yadayada" in str(msg.message)
예제 #10
0
import sys
import os
from setuptools_scm import integration
from setuptools_scm.utils import do, has_command
from setuptools_scm import git
import pytest
from datetime import datetime
from os.path import join as opj
from setuptools_scm.file_finder_git import git_find_files
from datetime import date
from unittest.mock import patch, Mock

pytestmark = pytest.mark.skipif(
    not has_command("git", warn=False), reason="git executable not found"
)


@pytest.fixture
def wd(wd, monkeypatch):
    monkeypatch.delenv("HOME", raising=False)
    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}"
    return wd


@pytest.mark.parametrize(
    "given, tag, number, node, dirty",
    [
    def __str__(self):
        return "Unable to find SCM information (/.git or /.hg folder, typically) " \
               "in the parent folders of %s" % self.path


class SetupToolsScmNotInstalled(Exception):
    def __str__(self):
        return "`setuptools_scm` package does not seem to be available in your python environment. Please install it" \
               " to enable SCM version discovery (git, hg)."


try:
    from setuptools_scm import get_version
    from setuptools_scm.utils import has_command
    has_git_command = has_command('git')

    def scm_get_version_recursive_root(abs_path, initial_path):
        """
        Recursively climbs the parent folders, searching for a git root

        :param abs_path:
        :return:
        """
        try:
            return get_version(abs_path)
        except LookupError as e:
            parent_dir = dirname(abs_path)
            if parent_dir == abs_path:
                # cannot recurse anymore
                raise ScmInformationNotFound(initial_path)