diff options
| author | ?ric Araujo <merwok@netwok.org> | 2010-10-31 15:35:43 +0100 |
|---|---|---|
| committer | ?ric Araujo <merwok@netwok.org> | 2010-10-31 15:35:43 +0100 |
| commit | 88277323bd97db95c0f2bd29964818f4f10f9b25 (patch) | |
| tree | d12d972c542c0ddf680e7a57b024fbd79d391537 /distutils2 | |
| parent | 4bd85dd75325b4f4c64d55e0c9d0ac219ce0cb33 (diff) | |
| download | disutils2-88277323bd97db95c0f2bd29964818f4f10f9b25.tar.gz | |
Touch up some comments, fix pyflakes and pep8 warnings
Diffstat (limited to 'distutils2')
| -rw-r--r-- | distutils2/_backport/pkgutil.py | 45 | ||||
| -rw-r--r-- | distutils2/_backport/tests/test_pkgutil.py | 10 |
2 files changed, 28 insertions, 27 deletions
diff --git a/distutils2/_backport/pkgutil.py b/distutils2/_backport/pkgutil.py index 8125573..d15becd 100644 --- a/distutils2/_backport/pkgutil.py +++ b/distutils2/_backport/pkgutil.py @@ -1,8 +1,5 @@ """Utilities to support packages.""" -# NOTE: This module must remain compatible with Python 2.3, as it is shared -# by setuptools for distribution with Python 2.3 and up. - import os import sys import imp @@ -30,6 +27,10 @@ __all__ = [ ] +########################## +# PEP 302 Implementation # +########################## + def read_code(stream): # This helper is needed in order for the :pep:`302` emulation to # correctly handle compiled files @@ -39,7 +40,7 @@ def read_code(stream): if magic != imp.get_magic(): return None - stream.read(4) # Skip timestamp + stream.read(4) # Skip timestamp return marshal.load(stream) @@ -171,7 +172,6 @@ def iter_modules(path=None, prefix=''): #@simplegeneric def iter_importer_modules(importer, prefix=''): - "" if not hasattr(importer, 'iter_modules'): return [] return importer.iter_modules(prefix) @@ -329,9 +329,9 @@ class ImpLoader(object): def get_filename(self, fullname=None): fullname = self._fix_name(fullname) mod_type = self.etc[2] - if self.etc[2] == imp.PKG_DIRECTORY: + if mod_type == imp.PKG_DIRECTORY: return self._get_delegate().get_filename() - elif self.etc[2] in (imp.PY_SOURCE, imp.PY_COMPILED, imp.C_EXTENSION): + elif mod_type in (imp.PY_SOURCE, imp.PY_COMPILED, imp.C_EXTENSION): return self.filename return None @@ -430,7 +430,8 @@ def iter_importers(fullname=""): import mechanism will find the latter. Items of the following types can be affected by this discrepancy: - ``imp.C_EXTENSION, imp.PY_SOURCE, imp.PY_COMPILED, imp.PKG_DIRECTORY`` + :data:`imp.C_EXTENSION`, :data:`imp.PY_SOURCE`, :data:`imp.PY_COMPILED`, + :data:`imp.PKG_DIRECTORY` """ if fullname.startswith('.'): raise ImportError("Relative module names not supported") @@ -532,13 +533,13 @@ def extend_path(path, name): # frozen package. Return the path unchanged in that case. return path - pname = os.path.join(*name.split('.')) # Reconstitute as relative path + pname = os.path.join(*name.split('.')) # Reconstitute as relative path # Just in case os.extsep != '.' sname = os.extsep.join(name.split('.')) sname_pkg = sname + os.extsep + "pkg" init_py = "__init__" + os.extsep + "py" - path = path[:] # Start with a copy of the existing path + path = path[:] # Start with a copy of the existing path for dir in sys.path: if not isinstance(dir, basestring) or not os.path.isdir(dir): @@ -563,7 +564,7 @@ def extend_path(path, name): line = line.rstrip('\n') if not line or line.startswith('#'): continue - path.append(line) # Don't check for existence! + path.append(line) # Don't check for existence! f.close() return path @@ -607,6 +608,7 @@ def get_data(package, resource): resource_name = os.path.join(*parts) return loader.get_data(resource_name) + ########################## # PEP 376 Implementation # ########################## @@ -614,12 +616,12 @@ def get_data(package, resource): DIST_FILES = ('INSTALLER', 'METADATA', 'RECORD', 'REQUESTED',) # Cache -_cache_name = {} # maps names to Distribution instances -_cache_name_egg = {} # maps names to EggInfoDistribution instances -_cache_path = {} # maps paths to Distribution instances -_cache_path_egg = {} # maps paths to EggInfoDistribution instances -_cache_generated = False # indicates if .dist-info distributions are cached -_cache_generated_egg = False # indicates if .dist-info and .egg are cached +_cache_name = {} # maps names to Distribution instances +_cache_name_egg = {} # maps names to EggInfoDistribution instances +_cache_path = {} # maps paths to Distribution instances +_cache_path_egg = {} # maps paths to EggInfoDistribution instances +_cache_generated = False # indicates if .dist-info distributions are cached +_cache_generated_egg = False # indicates if .dist-info and .egg are cached _cache_enabled = True @@ -634,6 +636,7 @@ def enable_cache(): _cache_enabled = True + def disable_cache(): """ Disables the internal cache. @@ -645,6 +648,7 @@ def disable_cache(): _cache_enabled = False + def clear_cache(): """ Clears the internal cache. """ global _cache_name, _cache_name_egg, _cache_path, _cache_path_egg, \ @@ -868,7 +872,8 @@ class EggInfoDistribution(object): if isinstance(strs, basestring): for s in strs.splitlines(): s = s.strip() - if s and not s.startswith('#'): # skip blank lines/comments + # skip blank lines/comments + if s and not s.startswith('#'): yield s else: for ss in strs: @@ -939,7 +944,7 @@ class EggInfoDistribution(object): version = match.group('first') if match.group('rest'): version += match.group('rest') - version = version.replace(' ', '') # trim spaces + version = version.replace(' ', '') # trim spaces if version is None: reqs.append(name) else: @@ -1126,7 +1131,7 @@ def provides_distribution(name, version=None, use_egg_info=False): raise DistutilsError(('Distribution %s has invalid ' + 'provides field: %s') \ % (dist.name, p)) - p_ver = p_ver[1:-1] # trim off the parenthesis + p_ver = p_ver[1:-1] # trim off the parenthesis if p_name == name and predicate.match(p_ver): yield dist break diff --git a/distutils2/_backport/tests/test_pkgutil.py b/distutils2/_backport/tests/test_pkgutil.py index 5af95a9..2d733c2 100644 --- a/distutils2/_backport/tests/test_pkgutil.py +++ b/distutils2/_backport/tests/test_pkgutil.py @@ -216,7 +216,7 @@ class TestPkgUtilDistribution(unittest.TestCase): record_writer.writerow(record_pieces( os.path.join(distinfo_dir, file))) record_writer.writerow([relpath(record_file, sys.prefix)]) - del record_writer # causes the RECORD file to close + del record_writer # causes the RECORD file to close record_reader = csv.reader(open(record_file, 'rb')) record_data = [] for row in record_reader: @@ -346,7 +346,7 @@ class TestPkgUtilPEP376(unittest.TestCase): # Given a name and a version, we expect the distinfo_dirname function # to return a standard distribution information directory name. - items = [# (name, version, standard_dirname) + items = [ # (name, version, standard_dirname) # Test for a very simple single word name and decimal # version number ('docutils', '0.5', 'docutils-0.5.dist-info'), @@ -411,7 +411,7 @@ class TestPkgUtilPEP376(unittest.TestCase): def test_get_distribution(self): # Test for looking up a distribution by name. # Test the lookup of the towel-stuff distribution - name = 'towel-stuff' # Note: This is different from the directory name + name = 'towel-stuff' # Note: This is different from the directory name # Lookup the distribution dist = get_distribution(name) @@ -508,12 +508,10 @@ class TestPkgUtilPEP376(unittest.TestCase): use_egg_info=True)] checkLists(l, ['strawberry']) - l = [dist.name for dist in provides_distribution('strawberry', '>0.6', use_egg_info=True)] checkLists(l, []) - l = [dist.name for dist in provides_distribution('banana', '0.4', use_egg_info=True)] checkLists(l, ['banana']) @@ -522,7 +520,6 @@ class TestPkgUtilPEP376(unittest.TestCase): use_egg_info=True)] checkLists(l, ['banana']) - l = [dist.name for dist in provides_distribution('banana', '!=0.4', use_egg_info=True)] checkLists(l, []) @@ -538,7 +535,6 @@ class TestPkgUtilPEP376(unittest.TestCase): use_egg_info=True)] checkLists(l, ['cheese', 'bacon']) - l = [dist.name for dist in obsoletes_distribution('truffles', '0.8')] checkLists(l, ['choxie']) |
