Skip to content

Commit

Permalink
[breaking] fix pypa#339: error when targetted scm parsing fails for m…
Browse files Browse the repository at this point in the history
…issing command
  • Loading branch information
RonnyPfannschmidt committed Dec 6, 2020
1 parent c4523c6 commit fdde8f8
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 25 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
v4.2.0
v5.0.0
======


Breaking changes:
* fix #339: strict errors on missing scms when parsing a scm dir to avoid false version lookups

Bugfixes:

* fix #352: add support for generally ignoring specific vcs roots
* fix #471: better error for version bump failing on complex but accepted tag
* fix #479: raise indicative error when tags carry non-parsable information
Expand Down
5 changes: 2 additions & 3 deletions src/setuptools_scm/git.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .config import Configuration
from .utils import do_ex, trace, has_command
from .utils import do_ex, trace, require_command
from .version import meta

from os.path import isfile, join
Expand Down Expand Up @@ -92,8 +92,7 @@ def parse(
if not config:
config = Configuration(root=root)

if not has_command("git"):
return
require_command("git")

wd = GitWorkdir.from_potential_worktree(config.absolute_root)
if wd is None:
Expand Down
5 changes: 2 additions & 3 deletions src/setuptools_scm/hg.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
from .config import Configuration
from .utils import do, trace, data_from_mime, has_command
from .utils import do, trace, data_from_mime, require_command
from .version import meta, tags_to_versions


Expand Down Expand Up @@ -36,8 +36,7 @@ def parse(root, config=None):
if not config:
config = Configuration(root=root)

if not has_command("hg"):
return
require_command("hg")
identity_data = do("hg id -i -b -t", config.absolute_root).split()
if not identity_data:
return
Expand Down
11 changes: 8 additions & 3 deletions src/setuptools_scm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def function_has_arg(fn, argname):
return argname in argspec


def has_command(name):
def has_command(name, warn=True):
try:
p = _popen_pipes([name, "help"], ".")
except OSError:
Expand All @@ -141,6 +141,11 @@ def has_command(name):
else:
p.communicate()
res = not p.returncode
if not res:
warnings.warn("%r was not found" % name)
if not res and warn:
warnings.warn("%r was not found" % name, category=RuntimeWarning)
return res


def require_command(name):
if not has_command(name, warn=False):
raise EnvironmentError("%r was not found" % name)
14 changes: 9 additions & 5 deletions testing/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from datetime import datetime
from os.path import join as opj
from setuptools_scm.file_finder_git import git_find_files
import warnings


skip_if_win_27 = pytest.mark.skipif(
Expand All @@ -16,10 +15,9 @@
)


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


@pytest.fixture
Expand Down Expand Up @@ -59,6 +57,12 @@ def test_root_relative_to(tmpdir, wd, monkeypatch):
assert res == "0.1.dev0"


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)


@pytest.mark.issue("https://github.com/pypa/setuptools_scm/issues/298")
@pytest.mark.issue(403)
def test_file_finder_no_history(wd, caplog):
Expand Down
6 changes: 1 addition & 5 deletions testing/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@

@pytest.fixture
def wd(wd):
try:
wd("git init")
except OSError:
pytest.skip("git executable not found")

wd("git init")
wd("git config user.email [email protected]")
wd('git config user.name "a test"')
wd.add_command = "git add ."
Expand Down
14 changes: 9 additions & 5 deletions testing/test_mercurial.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
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")
pytestmark = pytest.mark.skipif(
not has_command("hg", warn=False), reason="hg executable not found"
)


@pytest.fixture
Expand Down Expand Up @@ -46,6 +44,12 @@ def test_archival_to_version(expected, data):
)


def test_hg_gone(wd, monkeypatch):
monkeypatch.setenv("PATH", str(wd.cwd / "not-existing"))
with pytest.raises(EnvironmentError, match="'hg' was not found"):
parse(str(wd.cwd))


def test_find_files_stop_at_root_hg(wd, monkeypatch):
wd.commit_testfile()
project = wd.cwd / "project"
Expand Down

0 comments on commit fdde8f8

Please sign in to comment.