Skip to content

Commit dccfea9

Browse files
Merge pull request #119 from RonnyPfannschmidt/fix-81
fix #81 - fail more nice if git/hg is not availiable
2 parents 3a1f72f + a446485 commit dccfea9

File tree

5 files changed

+38
-7
lines changed

5 files changed

+38
-7
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ v1.15.0
88
and ensure its always correctly usign itself
99
* update trove classifiers
1010
* fix issue #84: document using the installed package metadata for sphinx
11+
* fix issue #81: fail more gracious when git/hg are missing
1112

1213
v1.14.1
1314
=======

setuptools_scm/git.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from .utils import do_ex, trace
1+
from .utils import do_ex, trace, has_command
22
from .version import meta
33
from os.path import abspath, normcase, realpath
44

@@ -44,6 +44,8 @@ def count_all_nodes(self):
4444

4545

4646
def parse(root, describe_command=DEFAULT_DESCRIBE):
47+
if not has_command('git'):
48+
return
4749
wd = GitWorkdir(root)
4850

4951
rev_node = wd.node()

setuptools_scm/hg.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import os
2-
from .utils import do, trace, data_from_mime
2+
from .utils import do, trace, data_from_mime, has_command
33
from .version import meta, tags_to_versions
44

55
FILES_COMMAND = 'hg locate -I .'
@@ -23,6 +23,8 @@ def _hg_tagdist_normalize_tagcommit(root, tag, dist, node):
2323

2424

2525
def parse(root):
26+
if not has_command('hg'):
27+
return
2628
l = do('hg id -i -t', root).split()
2729
node = l.pop(0)
2830
tags = tags_to_versions(l)

setuptools_scm/utils.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
utils
33
"""
44
from __future__ import print_function, unicode_literals
5+
import warnings
56
import sys
67
import shlex
78
import subprocess
@@ -41,12 +42,9 @@ def _always_strings(env_dict):
4142
return env_dict
4243

4344

44-
def do_ex(cmd, cwd='.'):
45-
trace('cmd', repr(cmd))
46-
if not isinstance(cmd, (list, tuple)):
47-
cmd = shlex.split(cmd)
45+
def _popen_pipes(cmd, cwd):
4846

49-
p = subprocess.Popen(
47+
return subprocess.Popen(
5048
cmd,
5149
stdout=subprocess.PIPE,
5250
stderr=subprocess.PIPE,
@@ -60,6 +58,13 @@ def do_ex(cmd, cwd='.'):
6058
))
6159
)
6260

61+
62+
def do_ex(cmd, cwd='.'):
63+
trace('cmd', repr(cmd))
64+
if not isinstance(cmd, (list, tuple)):
65+
cmd = shlex.split(cmd)
66+
67+
p = _popen_pipes(cmd, cwd)
6368
out, err = p.communicate()
6469
if out:
6570
trace('out', repr(out))
@@ -88,3 +93,17 @@ def data_from_mime(path):
8893
if ': ' in x)
8994
trace('data', data)
9095
return data
96+
97+
98+
def has_command(name):
99+
try:
100+
p = _popen_pipes([name, 'help'], '.')
101+
except OSError:
102+
trace(*sys.exc_info())
103+
res = False
104+
else:
105+
p.communicate()
106+
res = not p.returncode
107+
if not res:
108+
warnings.warn("%r was not found" % name)
109+
return res

testing/test_functions.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import pkg_resources
33
from setuptools_scm import dump_version, get_version, PRETEND_KEY
44
from setuptools_scm.version import guess_next_version, meta, format_version
5+
from setuptools_scm.utils import has_command
56

67

78
class MockTime(object):
@@ -62,3 +63,9 @@ def test_dump_version_works_with_pretend(tmpdir, monkeypatch):
6263
monkeypatch.setenv(PRETEND_KEY, '1.0')
6364
get_version(write_to=str(tmpdir.join('VERSION.txt')))
6465
assert tmpdir.join('VERSION.txt').read() == '1.0'
66+
67+
68+
def test_has_command(recwarn):
69+
assert not has_command('yadayada_setuptools_aint_ne')
70+
msg = recwarn.pop()
71+
assert 'yadayada' in str(msg.message)

0 commit comments

Comments
 (0)