Skip to content

Commit e917508

Browse files
committed
Merged in philip_thiem/setuptools (pull request #24)
Issue #101 and tweak legacy fallback
2 parents bc18704 + d01db08 commit e917508

File tree

5 files changed

+227
-83
lines changed

5 files changed

+227
-83
lines changed

setuptools/svn_utils.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,13 @@ def get_svn_version():
219219
def load(cls, dirname=''):
220220
normdir = os.path.normpath(dirname)
221221
code, data = _run_command(['svn', 'info', normdir])
222-
has_svn = os.path.isdir(os.path.join(normdir, '.svn'))
222+
# Must check for some contents, as some use empty directories
223+
# in testcases
224+
svn_dir = os.path.join(normdir, '.svn')
225+
has_svn = (os.path.isfile(os.path.join(svn_dir, 'entries')) or
226+
os.path.isfile(os.path.join(svn_dir, 'dir-props')) or
227+
os.path.isfile(os.path.join(svn_dir, 'dir-prop-base')))
228+
223229
svn_version = tuple(cls.get_svn_version().split('.'))
224230

225231
try:
@@ -229,7 +235,6 @@ def load(cls, dirname=''):
229235

230236
if has_svn and (code or not base_svn_version
231237
or base_svn_version < (1, 3)):
232-
log.warn('Fallback onto .svn parsing')
233238
warnings.warn(("No SVN 1.3+ command found: falling back "
234239
"on pre 1.7 .svn parsing"), DeprecationWarning)
235240
return SvnFileInfo(dirname)

setuptools/tests/environment.py

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
import unittest
66
import shutil
77
import stat
8+
import unicodedata
9+
10+
from subprocess import Popen as _Popen, PIPE as _PIPE
811

912

1013
def _extract(self, member, path=None, pwd=None):
@@ -25,13 +28,14 @@ def _extract_from_zip(self, name, dest_path):
2528
finally:
2629
dest_file.close()
2730

31+
2832
def _extract_member(self, member, targetpath, pwd):
2933
"""for zipfile py2.5 borrowed from cpython"""
3034
# build the destination pathname, replacing
3135
# forward slashes to platform specific separators.
3236
# Strip trailing path separator, unless it represents the root.
3337
if (targetpath[-1:] in (os.path.sep, os.path.altsep)
34-
and len(os.path.splitdrive(targetpath)[1]) > 1):
38+
and len(os.path.splitdrive(targetpath)[1]) > 1):
3539
targetpath = targetpath[:-1]
3640

3741
# don't include leading "/" from file name if present
@@ -102,3 +106,53 @@ def tearDown(self):
102106
#sigh?
103107
pass
104108

109+
110+
def _which_dirs(cmd):
111+
result = set()
112+
for path in os.environ.get('PATH', '').split(os.pathsep):
113+
filename = os.path.join(path, cmd)
114+
if os.access(filename, os.X_OK):
115+
result.add(path)
116+
return result
117+
118+
119+
def run_setup_py(cmd, pypath=None, path=None,
120+
data_stream=0, env=None):
121+
"""
122+
Execution command for tests, separate from those used by the
123+
code directly to prevent accidental behavior issues
124+
"""
125+
if env is None:
126+
env = dict()
127+
for envname in os.environ:
128+
env[envname] = os.environ[envname]
129+
130+
#override the python path if needed
131+
if pypath is not None:
132+
env["PYTHONPATH"] = pypath
133+
134+
#overide the execution path if needed
135+
if path is not None:
136+
env["PATH"] = path
137+
if not env.get("PATH", ""):
138+
env["PATH"] = _which_dirs("tar").union(_which_dirs("gzip"))
139+
env["PATH"] = os.pathsep.join(env["PATH"])
140+
141+
cmd = [sys.executable, "setup.py"] + list(cmd)
142+
143+
#regarding the shell argument, see: http://bugs.python.org/issue8557
144+
try:
145+
proc = _Popen(cmd, stdout=_PIPE, stderr=_PIPE,
146+
shell=(sys.platform == 'win32'), env=env)
147+
148+
data = proc.communicate()[data_stream]
149+
except OSError:
150+
return 1, ''
151+
152+
#decode the console string if needed
153+
if hasattr(data, "decode"):
154+
data = data.decode() # should use the preffered encoding
155+
data = unicodedata.normalize('NFC', data)
156+
157+
#communciate calls wait()
158+
return proc.returncode, data

setuptools/tests/svn_data/dummy.zip

1.73 KB
Binary file not shown.

setuptools/tests/test_egg_info.py

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1+
12
import os
23
import sys
34
import tempfile
45
import shutil
56
import unittest
67

78
import pkg_resources
9+
import warnings
810
from setuptools.command import egg_info
11+
from setuptools.tests import environment
912
from setuptools import svn_utils
1013

1114
ENTRIES_V10 = pkg_resources.resource_string(__name__, 'entries-v10')
1215
"An entries file generated with svn 1.6.17 against the legacy Setuptools repo"
1316

17+
1418
class TestEggInfo(unittest.TestCase):
1519

1620
def setUp(self):
@@ -37,7 +41,7 @@ def test_version_10_format(self):
3741
#to ensure I return using svnversion what would had been returned
3842
version_str = svn_utils.SvnInfo.get_svn_version()
3943
version = [int(x) for x in version_str.split('.')[:2]]
40-
if version != [1,6]:
44+
if version != [1, 6]:
4145
if hasattr(self, 'skipTest'):
4246
self.skipTest('')
4347
else:
@@ -61,14 +65,104 @@ def test_version_10_format_legacy_parser(self):
6165

6266
old_path = os.environ[path_variable]
6367
os.environ[path_variable] = ''
68+
#catch_warnings not available until py26
69+
warning_filters = warnings.filters
70+
warnings.filters = warning_filters[:]
6471
try:
72+
warnings.simplefilter("ignore", DeprecationWarning)
6573
self._write_entries(ENTRIES_V10)
6674
rev = egg_info.egg_info.get_svn_revision()
6775
finally:
76+
#restore the warning filters
77+
warnings.filters = warning_filters
78+
#restore the os path
6879
os.environ[path_variable] = old_path
6980

7081
self.assertEqual(rev, '89000')
7182

83+
DUMMY_SOURCE_TXT = """CHANGES.txt
84+
CONTRIBUTORS.txt
85+
HISTORY.txt
86+
LICENSE
87+
MANIFEST.in
88+
README.txt
89+
setup.py
90+
dummy/__init__.py
91+
dummy/test.txt
92+
dummy.egg-info/PKG-INFO
93+
dummy.egg-info/SOURCES.txt
94+
dummy.egg-info/dependency_links.txt
95+
dummy.egg-info/top_level.txt"""
96+
97+
98+
class TestSvnDummy(environment.ZippedEnvironment):
99+
100+
def setUp(self):
101+
version = svn_utils.SvnInfo.get_svn_version()
102+
self.base_version = tuple([int(x) for x in version.split('.')][:2])
103+
104+
if not self.base_version:
105+
raise ValueError('No SVN tools installed')
106+
elif self.base_version < (1, 3):
107+
raise ValueError('Insufficient SVN Version %s' % version)
108+
elif self.base_version >= (1, 9):
109+
#trying the latest version
110+
self.base_version = (1, 8)
111+
112+
self.dataname = "dummy%i%i" % self.base_version
113+
self.datafile = os.path.join('setuptools', 'tests',
114+
'svn_data', self.dataname + ".zip")
115+
super(TestSvnDummy, self).setUp()
116+
117+
def test_sources(self):
118+
code, data = environment.run_setup_py(["sdist"],
119+
pypath=self.old_cwd,
120+
data_stream=1)
121+
if code:
122+
raise AssertionError(data)
123+
124+
sources = os.path.join('dummy.egg-info', 'SOURCES.txt')
125+
infile = open(sources, 'r')
126+
try:
127+
read_contents = infile.read()
128+
finally:
129+
infile.close()
130+
del infile
131+
132+
self.assertEqual(DUMMY_SOURCE_TXT, read_contents)
133+
134+
return data
135+
136+
137+
class TestSvnDummyLegacy(environment.ZippedEnvironment):
138+
139+
def setUp(self):
140+
self.base_version = (1, 6)
141+
self.dataname = "dummy%i%i" % self.base_version
142+
self.datafile = os.path.join('setuptools', 'tests',
143+
'svn_data', self.dataname + ".zip")
144+
super(TestSvnDummyLegacy, self).setUp()
145+
146+
def test_sources(self):
147+
code, data = environment.run_setup_py(["sdist"],
148+
pypath=self.old_cwd,
149+
path="",
150+
data_stream=1)
151+
if code:
152+
raise AssertionError(data)
153+
154+
sources = os.path.join('dummy.egg-info', 'SOURCES.txt')
155+
infile = open(sources, 'r')
156+
try:
157+
read_contents = infile.read()
158+
finally:
159+
infile.close()
160+
del infile
161+
162+
self.assertEqual(DUMMY_SOURCE_TXT, read_contents)
163+
164+
return data
165+
72166

73167
def test_suite():
74168
return unittest.defaultTestLoader.loadTestsFromName(__name__)

0 commit comments

Comments
 (0)