Skip to content

Commit fdde8f8

Browse files
[breaking] fix #339: error when targetted scm parsing fails for missing command
1 parent c4523c6 commit fdde8f8

File tree

7 files changed

+38
-25
lines changed

7 files changed

+38
-25
lines changed

CHANGELOG.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
v4.2.0
1+
v5.0.0
22
======
33

4+
5+
Breaking changes:
6+
* fix #339: strict errors on missing scms when parsing a scm dir to avoid false version lookups
7+
8+
Bugfixes:
9+
410
* fix #352: add support for generally ignoring specific vcs roots
511
* fix #471: better error for version bump failing on complex but accepted tag
612
* fix #479: raise indicative error when tags carry non-parsable information

src/setuptools_scm/git.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from .config import Configuration
2-
from .utils import do_ex, trace, has_command
2+
from .utils import do_ex, trace, require_command
33
from .version import meta
44

55
from os.path import isfile, join
@@ -92,8 +92,7 @@ def parse(
9292
if not config:
9393
config = Configuration(root=root)
9494

95-
if not has_command("git"):
96-
return
95+
require_command("git")
9796

9897
wd = GitWorkdir.from_potential_worktree(config.absolute_root)
9998
if wd is None:

src/setuptools_scm/hg.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22
from .config import Configuration
3-
from .utils import do, trace, data_from_mime, has_command
3+
from .utils import do, trace, data_from_mime, require_command
44
from .version import meta, tags_to_versions
55

66

@@ -36,8 +36,7 @@ def parse(root, config=None):
3636
if not config:
3737
config = Configuration(root=root)
3838

39-
if not has_command("hg"):
40-
return
39+
require_command("hg")
4140
identity_data = do("hg id -i -b -t", config.absolute_root).split()
4241
if not identity_data:
4342
return

src/setuptools_scm/utils.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def function_has_arg(fn, argname):
132132
return argname in argspec
133133

134134

135-
def has_command(name):
135+
def has_command(name, warn=True):
136136
try:
137137
p = _popen_pipes([name, "help"], ".")
138138
except OSError:
@@ -141,6 +141,11 @@ def has_command(name):
141141
else:
142142
p.communicate()
143143
res = not p.returncode
144-
if not res:
145-
warnings.warn("%r was not found" % name)
144+
if not res and warn:
145+
warnings.warn("%r was not found" % name, category=RuntimeWarning)
146146
return res
147+
148+
149+
def require_command(name):
150+
if not has_command(name, warn=False):
151+
raise EnvironmentError("%r was not found" % name)

testing/test_git.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from datetime import datetime
88
from os.path import join as opj
99
from setuptools_scm.file_finder_git import git_find_files
10-
import warnings
1110

1211

1312
skip_if_win_27 = pytest.mark.skipif(
@@ -16,10 +15,9 @@
1615
)
1716

1817

19-
with warnings.catch_warnings():
20-
warnings.filterwarnings("ignore")
21-
if not has_command("git"):
22-
pytestmark = pytest.mark.skip(reason="git executable not found")
18+
pytestmark = pytest.mark.skipif(
19+
not has_command("git", warn=False), reason="git executable not found"
20+
)
2321

2422

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

6159

60+
def test_git_gone(wd, monkeypatch):
61+
monkeypatch.setenv("PATH", str(wd.cwd / "not-existing"))
62+
with pytest.raises(EnvironmentError, match="'git' was not found"):
63+
git.parse(str(wd.cwd), git.DEFAULT_DESCRIBE)
64+
65+
6266
@pytest.mark.issue("https://github.com/pypa/setuptools_scm/issues/298")
6367
@pytest.mark.issue(403)
6468
def test_file_finder_no_history(wd, caplog):

testing/test_integration.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@
88

99
@pytest.fixture
1010
def wd(wd):
11-
try:
12-
wd("git init")
13-
except OSError:
14-
pytest.skip("git executable not found")
15-
11+
wd("git init")
1612
wd("git config user.email [email protected]")
1713
wd('git config user.name "a test"')
1814
wd.add_command = "git add ."

testing/test_mercurial.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44
from setuptools_scm.config import Configuration
55
from setuptools_scm.utils import has_command
66
import pytest
7-
import warnings
87

98

10-
with warnings.catch_warnings():
11-
warnings.filterwarnings("ignore")
12-
if not has_command("hg"):
13-
pytestmark = pytest.mark.skip(reason="hg executable not found")
9+
pytestmark = pytest.mark.skipif(
10+
not has_command("hg", warn=False), reason="hg executable not found"
11+
)
1412

1513

1614
@pytest.fixture
@@ -46,6 +44,12 @@ def test_archival_to_version(expected, data):
4644
)
4745

4846

47+
def test_hg_gone(wd, monkeypatch):
48+
monkeypatch.setenv("PATH", str(wd.cwd / "not-existing"))
49+
with pytest.raises(EnvironmentError, match="'hg' was not found"):
50+
parse(str(wd.cwd))
51+
52+
4953
def test_find_files_stop_at_root_hg(wd, monkeypatch):
5054
wd.commit_testfile()
5155
project = wd.cwd / "project"

0 commit comments

Comments
 (0)