Skip to content

Commit ff7693b

Browse files
introduce CommandNotFoundError for require_command
1 parent 55a0acb commit ff7693b

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

src/setuptools_scm/_run_cmd.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ def has_command(
189189
return res
190190

191191

192+
class CommandNotFoundError(LookupError, FileNotFoundError):
193+
pass
194+
195+
192196
def require_command(name: str) -> None:
193197
if not has_command(name, warn=False):
194-
raise OSError(f"{name!r} was not found")
198+
raise CommandNotFoundError(name)

testing/test_git.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from setuptools_scm import git
2525
from setuptools_scm import NonNormalizedVersion
2626
from setuptools_scm._file_finders.git import git_find_files
27+
from setuptools_scm._run_cmd import CommandNotFoundError
2728
from setuptools_scm._run_cmd import CompletedProcess
2829
from setuptools_scm._run_cmd import has_command
2930
from setuptools_scm._run_cmd import run
@@ -93,8 +94,8 @@ def test_root_search_parent_directories(
9394

9495
def test_git_gone(wd: WorkDir, monkeypatch: pytest.MonkeyPatch) -> None:
9596
monkeypatch.setenv("PATH", str(wd.cwd / "not-existing"))
96-
with pytest.raises(EnvironmentError, match="'git' was not found"):
97-
git.parse(str(wd.cwd), Configuration(), git.DEFAULT_DESCRIBE)
97+
with pytest.raises(CommandNotFoundError, match=r"git"):
98+
git.parse(wd.cwd, Configuration(), git.DEFAULT_DESCRIBE)
9899

99100

100101
@pytest.mark.issue("https://github.com/pypa/setuptools_scm/issues/298")

testing/test_mercurial.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import setuptools_scm._file_finders
99
from setuptools_scm import Configuration
10+
from setuptools_scm._run_cmd import CommandNotFoundError
1011
from setuptools_scm._run_cmd import has_command
1112
from setuptools_scm.hg import archival_to_version
1213
from setuptools_scm.hg import parse
@@ -55,8 +56,8 @@ def test_archival_to_version(expected: str, data: dict[str, str]) -> None:
5556
def test_hg_gone(wd: WorkDir, monkeypatch: pytest.MonkeyPatch) -> None:
5657
monkeypatch.setenv("PATH", str(wd.cwd / "not-existing"))
5758
config = Configuration()
58-
with pytest.raises(EnvironmentError, match="'hg' was not found"):
59-
parse(str(wd.cwd), config=config)
59+
with pytest.raises(CommandNotFoundError, match=r"hg"):
60+
parse(wd.cwd, config=config)
6061

6162

6263
def test_find_files_stop_at_root_hg(

0 commit comments

Comments
 (0)