8000 look for both git.cmd and git.exe on windows. Might help #14. · drinkingjava/python-versioneer@bb95819 · GitHub
[go: up one dir, main page]

Skip to content

Commit bb95819

Browse files
committed
look for both git.cmd and git.exe on windows. Might help python-versioneer#14.
1 parent 70a55cc commit bb95819

File tree

4 files changed

+36
-19
lines changed

4 files changed

+36
-19
lines changed

src/git/install.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ def os_path_relpath(path, start=os.path.curdir):
2020
return os.path.join(*rel_list)
2121

2222
def do_vcs_install(versionfile_source, ipy):
23-
GIT = "git"
23+
GITs = ["git"]
2424
if sys.platform == "win32":
25-
GIT = "git.cmd"
25+
GITS = ["git.cmd", "git.exe"]
2626
files = [versionfile_source, ipy]
2727
try:
2828
me = __file__
@@ -47,4 +47,4 @@ def do_vcs_install(versionfile_source, ipy):
4747
f.write("%s export-subst\n" % versionfile_source)
4848
f.close()
4949
files.append(".gitattributes")
50-
run_command([GIT, "add", "--"] + files)
50+
run_command(GITS, ["add", "--"] + files)

src/git/middle.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ def versions_from_vcs(tag_prefix, root, verbose=False):
7474
print("no .git in %s" % root)
7575
return {}
7676

77-
GIT = "git"
77+
GITs = ["git"]
7878
if sys.platform == "win32":
79-
GIT = "git.cmd"
80-
stdout = run_command([GIT, "describe", "--tags", "--dirty", "--always"],
79+
GITS = ["git.cmd", "git.exe"]
80+
stdout = run_command(GITS, ["describe", "--tags", "--dirty", "--always"],
8181
cwd=root)
8282
if stdout is None:
8383
return {}
@@ -86,7 +86,7 @@ def versions_from_vcs(tag_prefix, root, verbose=False):
8686
print("tag '%s' doesn't start with prefix '%s'" % (stdout, tag_prefix))
8787
return {}
8888
tag = stdout[len(tag_prefix):]
89-
stdout = run_command([GIT, "rev-parse", "HEAD"], cwd=root)
89+
stdout = run_command(GITS, ["rev-parse", "HEAD"], cwd=root)
9090
if stdout is None:
9191
return {}
9292
full = stdout.strip()

src/subprocess_helper.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
11

22
import subprocess
33
import sys
4+
import errno
45

5-
def run_command(args, cwd=None, verbose=False, hide_stderr=False):
6-
try:
7-
# remember shell=False, so use git.cmd on windows, not just git
8-
p = subprocess.Popen(args, cwd=cwd, stdout=subprocess.PIPE,
9-
stderr=(subprocess.PIPE if hide_stderr else None))
10-
except EnvironmentError:
11-
e = sys.exc_info()[1]
6+
7+
def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False):
8+
assert isinstance(commands, list)
9+
p = None
10+
for c in commands:
11+
try:
12+
# remember shell=False, so use git.cmd on windows, not just git
13+
p = subprocess.Popen([c] + args, cwd=cwd, stdout=subprocess.PIPE,
14+
stderr=(subprocess.PIPE if hide_stderr
15+
else None))
16+
break
17+
except EnvironmentError:
18+
e = sys.exc_info()[1]
19+
if e.errno == errno.ENOENT:
20+
continue
21+
if verbose:
22+
print("unable to run %s" % args[0])
23+
print(e)
24+
return None
25+
else:
1226
if verbose:
13-
print("unable to run %s" % args[0])
14-
print(e)
27+
print("unable to find command, tried %s" % (commands,))
1528
return None
1629
stdout = p.communicate()[0].strip()
1730
if sys.version >= '3':

test/test_git.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
from git.middle import versions_from_expanded_variables
1111
from subprocess_helper import run_command
1212

13+
GITS = ["git"]
14+
if sys.platform == "win32":
15+
GITS = ["git.cmd", "git.exe"]
16+
1317
class Variables(unittest.TestCase):
1418
def parse(self, refnames, full, prefix=""):
1519
return versions_from_expanded_variables({"refnames": refnames,
@@ -50,14 +54,14 @@ class Repo(unittest.TestCase):
5054
def git(self, *args, **kwargs):
5155
workdir = kwargs.pop("workdir", self.subpath("demoapp"))
5256
assert not kwargs, kwargs.keys()
53-
output = run_command(["git"]+list(args), workdir, True)
57+
output = run_command(GITS, list(args), workdir, True)
5458
if output is None:
5559
self.fail("problem running git")
5660
return output
5761
def python(self, *args, **kwargs):
5862
workdir = kwargs.pop("workdir", self.subpath("demoapp"))
5963
assert not kwargs, kwargs.keys()
60-
output = run_command([sys.executable]+list(args), workdir, True)
64+
output = run_command([sys.executable], list(args), workdir, True)
6165
if output is None:
6266
self.fail("problem running python")
6367
return output
@@ -247,6 +251,6 @@ def check_version(self, workdir, exp_short, exp_long, dirty, state, tree):
247251

248252

249253
if __name__ == '__main__':
250-
ver = run_command(["git", "--version"], ".", True)
254+
ver = run_command(GITS, ["--version"], ".", True)
251255
print("git --version: %s" % ver.strip())
252256
unittest.main()

0 commit comments

Comments
 (0)
0