Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions src/from_parentdir.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@

def versions_from_parentdir(parentdir_prefix, root, verbose=False):
# Source tarballs conventionally unpack into a directory that includes
# both the project name and a version string.
dirname = os.path.basename(root)
if not dirname.startswith(parentdir_prefix):
if verbose:
print("guessing rootdir is '%s', but '%s' doesn't start with prefix '%s'" %
(root, dirname, parentdir_prefix))
return None
return {"version": dirname[len(parentdir_prefix):], "full": ""}
# both the project name and a version string. We will also support searching
# up two directory levels for an appropriately named parent directory
rootdirs = []

for i in range(3):
dirname = os.path.basename(root)
if dirname.startswith(parentdir_prefix):
return {"version": dirname[len(parentdir_prefix):], "full": ""}
else:
rootdirs.append(root)
root = os.path.dirname(root) # up a level
if verbose:
print("Tried directories %s but none started with prefix %s" %
(str(rootdirs), parentdir_prefix) )
return None
11 changes: 6 additions & 5 deletions src/git/from_vcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ def git_versions_from_vcs(tag_prefix, root, verbose=False):
# if the git-archive 'subst' keywords were *not* expanded, and
# _version.py hasn't already been rewritten with a short version string,
# meaning we're inside a checked out source tree.
GITS = ["git"]
if sys.platform == "win32":
GITS = ["git.cmd", "git.exe"]

if not os.path.exists(os.path.join(root, ".git")):
retcode = run_command_for_return_code(GITS, ["rev-parse", "--git-dir"], cwd=root)
if retcode == 128:
if verbose:
print("no .git in %s" % root)
print("Directory %s not under git control" % root)
return {}

GITS = ["git"]
if sys.platform == "win32":
GITS = ["git.cmd", "git.exe"]
stdout = run_command(GITS, ["describe", "--tags", "--dirty", "--always"],
cwd=root)
if stdout is None:
Expand Down
27 changes: 27 additions & 0 deletions src/subprocess_helper.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
import sys, subprocess, errno # --STRIP DURING BUILD

def run_command_for_return_code(commands, args, cwd=None, verbose=False, hide_stderr=True):
assert isinstance(commands, list)
p = None
for c in commands:
try:
# remember shell=False, so use git.cmd on windows, not just git
p = subprocess.Popen([c] + args, cwd=cwd, stdout=subprocess.PIPE,
stderr=(subprocess.PIPE if hide_stderr
else None))
break
except EnvironmentError:
e = sys.exc_info()[1]
if e.errno == errno.ENOENT:
continue
if verbose:
print("unable to run %s" % args[0])
print(e)
return None
else:
if verbose:
print("unable to find command, tried %s" % (commands,))
return None
stdout = p.communicate()[0].strip()
if sys.version >= '3':
stdout = stdout.decode()
return p.returncode

def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False):
assert isinstance(commands, list)
p = None
Expand Down
18 changes: 4 additions & 14 deletions test/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ def git(self, *args, **kwargs):
assert not kwargs, kwargs.keys()
output = run_command(GITS, list(args), workdir, True)
if output is None:
self.fail("problem running git")
self.fail("problem running git (workdir: %s)" % workdir)
return output
def python(self, *args, **kwargs):
workdir = kwargs.pop("workdir", self.projpath())
assert not kwargs, kwargs.keys()
output = run_command([sys.executable], list(args), workdir, True)
if output is None:
self.fail("problem running python")
self.fail("problem running python (workdir: %s)" % workdir)
return output
def subpath(self, path, base_dir = ""):
return os.path.join(self.testdir, base_dir, path)
Expand Down Expand Up @@ -124,17 +124,7 @@ def run_test(self, demoapp_dir, script_only, sub_dir=False):
self.projdir = "project" if sub_dir else ""
self.gitdir = "demoapp"

# create an unrelated git tree above the testdir. Some tests will run
# from this directory, and they should use the demoapp git
# environment instead of the deceptive parent
os.mkdir(self.testdir)
self.git("init", workdir=self.testdir)
f = open(os.path.join(self.testdir, "false-repo"), "w")
f.write("don't look at me\n")
f.close()
self.git("add", "false-repo", workdir=self.testdir)
self.git("commit", "-m", "first false commit", workdir=self.testdir)
self.git("tag", "demo-4.0", workdir=self.testdir)

shutil.copytree(demoapp_dir, self.projpath())
setup_py_fn = os.path.join(self.projpath(), "setup.py")
Expand Down Expand Up @@ -220,7 +210,7 @@ def run_test(self, demoapp_dir, script_only, sub_dir=False):
self.do_checks("1.0-dirty", full+"-dirty", dirty=True, state="SB")

# SC: now we make one commit past the tag
self.git("add", "setup.py")
self.git("add", "setup.py", workdir=self.projpath())
self.git("commit", "-m", "dirty")
full = self.git("rev-parse", "HEAD")
short = "1.0-1-g%s" % full[:7]
Expand Down Expand Up @@ -263,7 +253,7 @@ def do_checks(self, exp_short, exp_long, dirty, state):
# the short version to be like 1.0-1-gHEXID. The code falls back
# to short=long
exp_short_TD = exp_long
self.check_version(target, exp_short_TD, exp_long, False, state, tree="TD")
self.check_version(self.projpath(target), exp_short_TD, exp_long, False, state, tree="TD")

# TE: unpacked setup.py sdist tarball
dist_path = os.path.join(self.projpath(), "dist")
Expand Down