8000 fix tests by restoring some imports · drinkingjava/python-versioneer@96b655a · GitHub
[go: up one dir, main page]

Skip to content

Commit 96b655a

Browse files
committed
fix tests by restoring some imports
A few source files are imported by tests, so they need to import their dependencies. The new scheme strips these known-to-be-duplicate import lines (marked with a special comment) during 'setup.py make_versioneer'.
1 parent fa98fa6 commit 96b655a

File tree

3 files changed

+37
-25
lines changed

3 files changed

+37
-25
lines changed

setup.py

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515
# as nice as it'd be to versioneer ourselves, that sounds messy.
1616
VERSION = "0.10+"
1717

18-
def get(fn):
18+
19+
def ver(s):
20+
return s.replace("@VERSIONEER-VERSION@", VERSION)
21+
22+
def get(fn, add_ver=False, unquote=False, do_strip=False, do_readme=False):
1923
with open(fn) as f:
2024
text = f.read()
2125

@@ -24,20 +28,24 @@ def get(fn):
2428
try:
2529
__builtins__.unicode
2630
except AttributeError:
27-
return text
31+
pass
2832
else:
29-
return text.decode('ASCII')
33+
text = text.decode('ASCII')
34+
if add_ver:
35+
text = ver(text)
36+
if unquote:
37+
text = text.replace("%", "%%")
38+
if do_strip:
39+
lines = [line for line in text.split("\n")
40+
if not line.endswith("# --STRIP DURING BUILD")]
41+
text = "\n".join(lines)
42+
if do_readme:
43+
text = text.replace("@README@", get("README.md"))
44+
return text
3045

3146
def u(s): # so u("foo") yields unicode on all of py2.6/py2.7/py3.2/py3.3
3247
return s.encode("ascii").decode("ascii")
3348

34-
def unquote(s):
35-
return s.replace("%", "%%")
36-
def ver(s):
37-
return s.replace("@VERSIONEER-VERSION@", VERSION)
38-
def readme(s):
39-
return s.replace("@README@", get("README.md"))
40-
4149
def get_vcs_list():
4250
project_path = path.join(path.abspath(path.dirname(__file__)), 'src')
4351
return [filename
@@ -47,28 +55,30 @@ def get_vcs_list():
4755

4856
def generate_versioneer():
4957
s = io.StringIO()
50-
s.write(readme(ver(get("src/header.py"))))
51-
s.write(get("src/subprocess_helper.py"))
58+
s.write(get("src/header.py", add_ver=True, do_readme=True))
59+
s.write(get("src/subprocess_helper.py", do_strip=True))
5260

5361
for VCS in get_vcs_list():
5462
s.write(u("LONG_VERSION_PY['%s'] = '''\n" % VCS))
55-
s.write(ver(get("src/%s/long_header.py" % VCS)))
56-
s.write(unquote(get("src/subprocess_helper.py")))
57-
s.write(unquote(get("src/from_parentdir.py")))
58-
s.write(unquote(get("src/%s/from_keywords.py" % VCS)))
59-
s.write(unquote(get("src/%s/from_vcs.py" % VCS)))
60-
s.write(unquote(get("src/%s/long_get_versions.py" % VCS)))
63+
s.write(get("src/%s/long_header.py" % VCS, add_ver=True, do_strip=True))
64+
s.write(get("src/subprocess_helper.py", unquote=True, do_strip=True))
65+
s.write(get("src/from_parentdir.py", unquote=True, do_strip=True))
66+
s.write(get("src/%s/from_keywords.py" % VCS,
67+
unquote=True, do_strip=True))
68+
s.write(get("src/%s/from_vcs.py" % VCS, unquote=True, do_strip=True))
69+
s.write(get("src/%s/long_get_versions.py" % VCS,
70+
unquote=True, do_strip=True))
6171
s.write(u("'''\n"))
6272

63-
s.write(get("src/%s/from_keywords.py" % VCS))
64-
s.write(get("src/%s/from_vcs.py" % VCS))
73+
s.write(get("src/%s/from_keywords.py" % VCS, do_strip=True))
74+
s.write(get("src/%s/from_vcs.py" % VCS, do_strip=True))
6575

66-
s.write(get("src/%s/install.py" % VCS))
76+
s.write(get("src/%s/install.py" % VCS, do_strip=True))
6777

68-
s.write(get("src/from_parentdir.py"))
69-
s.write(ver(get("src/from_file.py")))
70-
s.write(ver(get("src/get_versions.py")))
71-
s.write(ver(get("src/cmdclass.py")))
78+
s.write(get("src/from_parentdir.py", do_strip=True))
79+
s.write(get("src/from_file.py", add_ver=True, do_strip=True))
80+
s.write(get("src/get_versions.py", add_ver=True, do_strip=True))
81+
s.write(get("src/cmdclass.py", add_ver=True, do_strip=True))
7282

7383
return s.getvalue().encode("utf-8")
7484

src/git/from_keywords.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import re # --STRIP DURING BUILD
12

23
def git_get_keywords(versionfile_abs):
34
# the code embedded in _version.py can just fetch the value of these

src/subprocess_helper.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import sys, subprocess, errno # --STRIP DURING BUILD
12

23
def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False):
34
assert isinstance(commands, list)

0 commit comments

Comments
 (0)
0