summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRonny Pfannschmidt <ronny.pfannschmidt@redhat.com>2020-12-06 18:24:55 +0100
committerRonny Pfannschmidt <ronny.pfannschmidt@redhat.com>2020-12-06 18:24:55 +0100
commitfdde8f81ae161e92d42aea7f063d2a0ca199d2e1 (patch)
tree15b1f5635cb60cb4146a806700d176f477190a02
parentc4523c65a3e8ce3d3481cea42ade9b657bb6546f (diff)
downloadsetuptools-scm-fdde8f81ae161e92d42aea7f063d2a0ca199d2e1.tar.gz
[breaking] fix #339: error when targetted scm parsing fails for missing command
-rw-r--r--CHANGELOG.rst8
-rw-r--r--src/setuptools_scm/git.py5
-rw-r--r--src/setuptools_scm/hg.py5
-rw-r--r--src/setuptools_scm/utils.py11
-rw-r--r--testing/test_git.py14
-rw-r--r--testing/test_integration.py6
-rw-r--r--testing/test_mercurial.py14
7 files changed, 38 insertions, 25 deletions
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index c570357..83666ae 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -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
diff --git a/src/setuptools_scm/git.py b/src/setuptools_scm/git.py
index 76be436..4fd5d49 100644
--- a/src/setuptools_scm/git.py
+++ b/src/setuptools_scm/git.py
@@ -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
@@ -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:
diff --git a/src/setuptools_scm/hg.py b/src/setuptools_scm/hg.py
index d699d45..2ac9141 100644
--- a/src/setuptools_scm/hg.py
+++ b/src/setuptools_scm/hg.py
@@ -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
@@ -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
diff --git a/src/setuptools_scm/utils.py b/src/setuptools_scm/utils.py
index 15ca83e..413e98a 100644
--- a/src/setuptools_scm/utils.py
+++ b/src/setuptools_scm/utils.py
@@ -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:
@@ -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)
diff --git a/testing/test_git.py b/testing/test_git.py
index 6f5246c..1b57fed 100644
--- a/testing/test_git.py
+++ b/testing/test_git.py
@@ -7,7 +7,6 @@ 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
skip_if_win_27 = pytest.mark.skipif(
@@ -16,10 +15,9 @@ skip_if_win_27 = pytest.mark.skipif(
)
-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
@@ -59,6 +57,12 @@ setup(use_scm_version={"root": "../..",
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):
diff --git a/testing/test_integration.py b/testing/test_integration.py
index 4564897..446aac0 100644
--- a/testing/test_integration.py
+++ b/testing/test_integration.py
@@ -8,11 +8,7 @@ from setuptools_scm import PRETEND_KEY, PRETEND_KEY_NAMED
@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 test@example.com")
wd('git config user.name "a test"')
wd.add_command = "git add ."
diff --git a/testing/test_mercurial.py b/testing/test_mercurial.py
index 815ca00..265e207 100644
--- a/testing/test_mercurial.py
+++ b/testing/test_mercurial.py
@@ -4,13 +4,11 @@ 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")
+pytestmark = pytest.mark.skipif(
+ not has_command("hg", warn=False), reason="hg executable not found"
+)
@pytest.fixture
@@ -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"