diff options
author | Philip Thiem <ptthiem@gmail.com> | 2013-06-30 21:11:35 -0500 |
---|---|---|
committer | Philip Thiem <ptthiem@gmail.com> | 2013-06-30 21:11:35 -0500 |
commit | c7bd44256ce9f77a54e22561405b06690a805e94 (patch) | |
tree | 55966e8c684736d4995e8786e55c7fc029940f29 | |
parent | ec450c5e222fa97ff401ab80a650cbedf268f98c (diff) | |
download | external_python_setuptools-c7bd44256ce9f77a54e22561405b06690a805e94.tar.gz external_python_setuptools-c7bd44256ce9f77a54e22561405b06690a805e94.tar.bz2 external_python_setuptools-c7bd44256ce9f77a54e22561405b06690a805e94.zip |
Finished some 1.7 tests, and updated the zip file to include the .svn dirs
Several fixes to get the code to pass the tests
--HG--
extra : rebase_source : 76e13888a6efc871cc254076c7e58f201af24472
-rwxr-xr-x | setuptools/command/egg_info.py | 2 | ||||
-rw-r--r-- | setuptools/svn_utils.py | 69 | ||||
-rw-r--r-- | setuptools/tests/svn17_example.zip | bin | 1656 -> 19342 bytes | |||
-rw-r--r-- | setuptools/tests/test_svn.py | 85 |
4 files changed, 92 insertions, 64 deletions
diff --git a/setuptools/command/egg_info.py b/setuptools/command/egg_info.py index 43321119..9d30b125 100755 --- a/setuptools/command/egg_info.py +++ b/setuptools/command/egg_info.py @@ -231,7 +231,7 @@ class egg_info(Command): dirs[:] = [] continue - localrev = entries.parse_revsion() + localrev = entries.parse_revision() dirurl = entries.get_url() if base==os.curdir: diff --git a/setuptools/svn_utils.py b/setuptools/svn_utils.py index 52a1c07b..7d30d322 100644 --- a/setuptools/svn_utils.py +++ b/setuptools/svn_utils.py @@ -45,7 +45,8 @@ class SVNEntries(object): @staticmethod
def get_svn_tool_version():
proc = _Popen(['svn', '--version', '--quiet'],
- stdout=_PIPE, shell=(sys.platform=='win32'))
+ stdout=_PIPE, stderr=_PIPE,
+ shell=(sys.platform=='win32'))
data = unicode(proc.communicate()[0], encoding='utf-8')
if data:
return data.strip()
@@ -56,7 +57,7 @@ class SVNEntries(object): def load_dir(class_, base):
filename = os.path.join(base, '.svn', 'entries')
f = open(filename)
- result = SVNEntries.read(f, None)
+ result = SVNEntries.read(f, base)
f.close()
return result
@@ -66,16 +67,15 @@ class SVNEntries(object): if data.startswith('<?xml'):
#entries were originally xml so pre-1.4.x
- return SVNEntriesXML(data, path)
+ return SVNEntriesXML(path, data)
elif path is None:
- return SVNEntriesText(data, path)
+ return SVNEntriesText(path, data)
else:
- class_.svn_tool_version = class_.get_svn_tool_version()
- result = SVNEntriesText(data, path)
+ result = SVNEntriesText(path, data)
if result.is_valid():
- return SVNEntriesCMD(data, path)
- else:
return result
+ else:
+ return SVNEntriesCMD(path, data)
def parse_revision(self):
all_revs = self.parse_revision_numbers() + [0]
@@ -84,8 +84,11 @@ class SVNEntries(object): def __get_cached_external_dirs(self):
return self.external_dirs
- def __get_externals_data(self, filename):
+ def _get_externals_data(self, filename):
found = False
+ if not os.path.isfile(filename):
+ return
+
f = open(filename,'rt')
for line in iter(f.readline, ''): # can't use direct iter!
parts = line.split()
@@ -102,7 +105,9 @@ class SVNEntries(object): return ''
def get_external_dirs(self, filename):
- data = self.__get_externals_data(filename)
+ filename = os.path.join(self.path, '.svn', filename)
+
+ data = self._get_externals_data(filename)
if not data:
return
@@ -112,7 +117,7 @@ class SVNEntries(object): #but looks like we only need the local relative path names so it's just
#2 either the first column or the last (of 2 or 3) Looks like
#mix and matching is allowed.
- data = list()
+ externals = list()
for line in data:
line = line.split()
if not line:
@@ -120,11 +125,11 @@ class SVNEntries(object): #TODO: urlparse?
if "://" in line[-1] or ":\\\\" in line[-1]:
- data.append(line[-1])
+ externals.append(line[0])
else:
- data.append(line[0])
+ externals.append(line[-1])
- self.external_dirs = data
+ self.external_dirs = externals
self.get_external_dirs = self.__get_cached_external_dirs
return self.external_dirs
@@ -139,16 +144,20 @@ class SVNEntriesText(SVNEntries): return self.sections
def get_sections(self):
- SECTION_DIVIDER = '\f\n' # or '\n\x0c\n'?
- sections = self.data.split(SECTION_DIVIDER)
- sections = [section.splitlines() for section in sections]
+ # remove the SVN version number from the first line
+ svn_version, _, sections = self.data.partition("\n")
try:
- # remove the SVN version number from the first line
- svn_version = int(sections[0].pop(0))
+ svn_version = int(svn_version)
if not svn_version in self.known_svn_versions.values():
- log.warn("Unknown subversion verson %d", svn_version)
+ log.warn("SVNEntriesText: Unknown subversion verson %d."
+ " Maybe another parser will work,", svn_version)
except ValueError:
return
+
+ SECTION_DIVIDER = '\f\n' # or '\n\x0c\n'?
+ sections = sections.split(SECTION_DIVIDER)
+ sections = [section.splitlines() for section in sections if section]
+
self.sections = sections
self.get_sections = self.__get_cached_sections
return self.sections
@@ -209,8 +218,8 @@ class SVNEntriesXML(SVNEntries): class SVNEntriesCMD(SVNEntries):
entrypathre = re.compile(r'<entry\s+[^>]*path="(\.+)">', re.I)
- entryre = re.compile(r'<entry.*?</entry>', re.M or re.I)
- urlre = re.compile(r'<root>(.*?)</root>', re.I)
+ entryre = re.compile(r'<entry.*?</entry>', re.DOTALL or re.I)
+ urlre = re.compile(r'<url>(.*?)</url>', re.I)
revre = re.compile(r'<commit\s+[^>]*revision="(\d+)"', re.I)
namere = re.compile(r'<name>(.*?)</name>', re.I)
@@ -238,12 +247,12 @@ class SVNEntriesCMD(SVNEntries): stdout=_PIPE, shell=(sys.platform=='win32'))
data = unicode(proc.communicate()[0], encoding='utf-8')
self.entries = self.entryre.findall(data)
- self.get_dir_data = self.__get_cached_dir_data
+ self.get_entries = self.__get_cached_entries
return self.entries
def get_url(self):
"Get repository URL"
- return self.urlre.search(self.get_entries()[0]).group(1)
+ return self.urlre.search(self.get_dir_data()[0]).group(1)
def parse_revision_numbers(self):
#NOTE: if one has recently committed,
@@ -253,7 +262,7 @@ class SVNEntriesCMD(SVNEntries): else:
return [
int(m.group(1))
- for entry in self.get_enries()
+ for entry in self.get_entries()
for m in self.revre.finditer(entry)
if m.group(1)
]
@@ -270,16 +279,18 @@ class SVNEntriesCMD(SVNEntries): if m.group(1)
]
- def __get_externals_data(self, filename):
+ def _get_externals_data(self, filename):
#othewise will be called twice.
- if filename.lower() != 'dir-props':
+ if os.path.basename(filename).lower() != 'dir-props':
return ''
#regard the shell argument, see: http://bugs.python.org/issue8557
- proc = _Popen(['svn', 'propget', self.path],
+ proc = _Popen(['svn', 'propget', 'svn:externals', self.path],
stdout=_PIPE, shell=(sys.platform=='win32'))
try:
- return unicode(proc.communicate()[0], encoding='utf-8').splitlines()
+ lines = unicode(proc.communicate()[0], encoding='utf-8')
+ lines = [line for line in lines.splitlines() if line]
+ return lines
except ValueError:
return ''
diff --git a/setuptools/tests/svn17_example.zip b/setuptools/tests/svn17_example.zip Binary files differindex d208f42c..cfabd2b2 100644 --- a/setuptools/tests/svn17_example.zip +++ b/setuptools/tests/svn17_example.zip diff --git a/setuptools/tests/test_svn.py b/setuptools/tests/test_svn.py index 90f213b4..1a41e427 100644 --- a/setuptools/tests/test_svn.py +++ b/setuptools/tests/test_svn.py @@ -3,18 +3,20 @@ import os +import zipfile import sys import tempfile import unittest import shutil import stat -import setuptools.command.egg_info as egg_info +from setuptools import svn_utils + #requires python >= 2.4 from subprocess import call as _call def _remove_dir(target): - + #on windows this seems to a problem for dir_path, dirs, files in os.walk(target): os.chmod(dir_path, stat.S_IWRITE) @@ -22,50 +24,65 @@ def _remove_dir(target): os.chmod(os.path.join(dir_path, filename), stat.S_IWRITE) shutil.rmtree(target) -class TestEmptySvn(unittest.TestCase): +class TestSvnVersion(unittest.TestCase): + def test_no_svn_found(self): + old_path = os.environ['path'] + os.environ['path'] = '' + try: + version = svn_utils.SVNEntries.get_svn_tool_version() + self.assertEqual(version, '') + finally: + os.environ['path'] = old_path + def test_svn_should_exist(self): + version = svn_utils.SVNEntries.get_svn_tool_version() + self.assertNotEqual(version, '') - def setUp(self): - self.temp_dir = tempfile.mkdtemp() - self.old_cwd = os.getcwd() - os.chdir(self.temp_dir) - #apparently there is a standing bug in python about having - #to use shell=True in windows to get a path search. - if _call(['svnadmin', 'create', 'svn'], shell=(sys.platform == 'win32')): - raise 'Failed to create SVN repository' - self.svnrepo = os.path.join(self.temp_dir, 'svn') +class TestSvn_1_7(unittest.TestCase): - if _call(['svn', 'checkout', 'file:///' + self.svnrepo.replace('\\','/'), 'co']): - os.chdir(self.old_cwd) - _remove_dir(self.temp_dir) - raise 'Failed to checkout SVN repository' + def setUp(self): + self.temp_dir = tempfile.mkdtemp() + zip_file, source, target = [None, None, None] + try: + zip_file = zipfile.ZipFile(os.path.join('setuptools', 'tests', + 'svn17_example.zip')) + for files in zip_file.namelist(): + zip_file.extract(files, self.temp_dir) + finally: + if zip_file: + zip_file.close() + del zip_file - os.chdir(os.path.join(self.temp_dir, 'co')) + self.old_cwd = os.getcwd() + os.chdir(os.path.join(self.temp_dir, 'svn17_example')) def tearDown(self): os.chdir(self.old_cwd) _remove_dir(self.temp_dir) - def test_can_get_revision_empty(self): - """Check that svn revision can be retrieved from an working set on an empty repository.""" - self.assertEquals('0', egg_info._get_svn_revision()) - - def test_can_get_revision_single_commit(self): - """Check that svn revision can be retrieved from an working set on an empty repository.""" - - open('README', 'w').close() - exitcode = _call(['svn', 'add', 'README'], shell=(sys.platform == 'win32')) - self.assertEqual(0, exitcode) - - exitcode = _call(['svn', 'commit', '-m', '"README added"'], shell=(sys.platform == 'win32')) - self.assertEqual(0, exitcode) - - exitcode = _call(['svn', 'update'], shell=(sys.platform == 'win32')) - self.assertEqual(0, exitcode) + def test_svnentrycmd_is_valid(self): + entries = svn_utils.SVNEntries.load_dir('.') + self.assertIsInstance(entries, svn_utils.SVNEntriesCMD) + self.assertTrue(entries.is_valid()) + + def test_svnentrycmd_is_valid(self): + entries = svn_utils.SVNEntries.load_dir('.') + self.assertIsInstance(entries, svn_utils.SVNEntriesCMD) + self.assertTrue(entries.is_valid()) + self.assertEqual(entries.get_url(), + 'file:///C:/development/svn_example/repo1') + + def test_svnentrycmd_enteries(self): + entries = svn_utils.SVNEntries.load_dir('.') + self.assertIsInstance(entries, svn_utils.SVNEntriesCMD) + self.assertEqual(entries.parse_revision(), 3) + self.assertEqual(set(entries.get_undeleted_records()), + set([u'readme.txt', u'other'])) + self.assertEqual(set(entries.get_external_dirs('dir-props')), + set([u'third_party3', u'third_party2', u'third_party'])) - self.assertEquals('1', egg_info._get_svn_revision()) def test_suite(): |