From dbbfab8fe8a8c146c2353f751d617c8761f6ddc4 Mon Sep 17 00:00:00 2001 From: Erik Bray Date: Tue, 11 Sep 2012 13:53:29 -0400 Subject: Fixes and adds a regression test for #323; required adding some new keyword arguments to existing pkg_resources methods. Also had to update how __path__ is handled for namespace packages to ensure that when a new egg distribution containing a namespace package is placed on sys.path, the entries in __path__ are in the same order they would have been in had that egg been on the path when pkg_resources was first imported --HG-- branch : distribute extra : rebase_source : 63a120c9397f6619d2768ec982e5c6b664c97e40 --- pkg_resources.py | 60 ++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 19 deletions(-) (limited to 'pkg_resources.py') diff --git a/pkg_resources.py b/pkg_resources.py index 060db644..7495f1b6 100644 --- a/pkg_resources.py +++ b/pkg_resources.py @@ -517,7 +517,7 @@ class WorkingSet(object): seen[key]=1 yield self.by_key[key] - def add(self, dist, entry=None, insert=True): + def add(self, dist, entry=None, insert=True, replace=False): """Add `dist` to working set, associated with `entry` If `entry` is unspecified, it defaults to the ``.location`` of `dist`. @@ -525,8 +525,9 @@ class WorkingSet(object): set's ``.entries`` (if it wasn't already present). `dist` is only added to the working set if it's for a project that - doesn't already have a distribution in the set. If it's added, any - callbacks registered with the ``subscribe()`` method will be called. + doesn't already have a distribution in the set, unless `replace=True`. + If it's added, any callbacks registered with the ``subscribe()`` method + will be called. """ if insert: dist.insert_on(self.entries, entry) @@ -535,7 +536,7 @@ class WorkingSet(object): entry = dist.location keys = self.entry_keys.setdefault(entry,[]) keys2 = self.entry_keys.setdefault(dist.location,[]) - if dist.key in self.by_key: + if not replace and dist.key in self.by_key: return # ignore hidden distros self.by_key[dist.key] = dist @@ -545,7 +546,8 @@ class WorkingSet(object): keys2.append(dist.key) self._added_new(dist) - def resolve(self, requirements, env=None, installer=None, replacement=True): + def resolve(self, requirements, env=None, installer=None, + replacement=True, replace_conflicting=False): """List all distributions needed to (recursively) meet `requirements` `requirements` must be a sequence of ``Requirement`` objects. `env`, @@ -555,6 +557,12 @@ class WorkingSet(object): will be invoked with each requirement that cannot be met by an already-installed distribution; it should return a ``Distribution`` or ``None``. + + Unless `replace_conflicting=True`, raises a VersionConflict exception if + any requirements are found on the path that have the correct name but + the wrong version. Otherwise, if an `installer` is supplied it will be + invoked to obtain the correct version of the requirement and activate + it. """ requirements = list(requirements)[::-1] # set up the stack @@ -574,10 +582,18 @@ class WorkingSet(object): if dist is None: # Find the best distribution and add it to the map dist = self.by_key.get(req.key) - if dist is None: + if dist is None or (dist not in req and replace_conflicting): + ws = self if env is None: - env = Environment(self.entries) - dist = best[req.key] = env.best_match(req, self, installer) + if dist is None: + env = Environment(self.entries) + else: + # Use an empty environment and workingset to avoid + # any further conflicts with the conflicting + # distribution + env = Environment([]) + ws = WorkingSet([]) + dist = best[req.key] = env.best_match(req, ws, installer) if dist is None: #msg = ("The '%s' distribution was not found on this " # "system, and is required by this application.") @@ -1798,6 +1814,7 @@ def register_namespace_handler(importer_type, namespace_handler): def _handle_ns(packageName, path_item): """Ensure that named package includes a subpath of path_item (if needed)""" + importer = get_importer(path_item) if importer is None: return None @@ -1807,14 +1824,19 @@ def _handle_ns(packageName, path_item): module = sys.modules.get(packageName) if module is None: module = sys.modules[packageName] = types.ModuleType(packageName) - module.__path__ = []; _set_parent_ns(packageName) + module.__path__ = [] + _set_parent_ns(packageName) elif not hasattr(module,'__path__'): raise TypeError("Not a package:", packageName) handler = _find_adapter(_namespace_handlers, importer) - subpath = handler(importer,path_item,packageName,module) + subpath = handler(importer, path_item, packageName, module) if subpath is not None: - path = module.__path__; path.append(subpath) - loader.load_module(packageName); module.__path__ = path + path = module.__path__ + path.append(subpath) + loader.load_module(packageName) + for path_item in path: + if path_item not in module.__path__: + module.__path__.append(path_item) return subpath def declare_namespace(packageName): @@ -2120,7 +2142,7 @@ def _remove_md5_fragment(location): class Distribution(object): """Wrap an actual or potential sys.path entry w/metadata""" PKG_INFO = 'PKG-INFO' - + def __init__(self, location=None, metadata=None, project_name=None, version=None, py_version=PY_MAJOR, platform=None, precedence = EGG_DIST @@ -2459,7 +2481,7 @@ class DistInfoDistribution(Distribution): from email.parser import Parser self._pkg_info = Parser().parsestr(self.get_metadata(self.PKG_INFO)) return self._pkg_info - + @property def _dep_map(self): try: @@ -2470,7 +2492,7 @@ class DistInfoDistribution(Distribution): def _preparse_requirement(self, requires_dist): """Convert 'Foobar (1); baz' to ('Foobar ==1', 'baz') - Split environment marker, add == prefix to version specifiers as + Split environment marker, add == prefix to version specifiers as necessary, and remove parenthesis. """ parts = requires_dist.split(';', 1) + [''] @@ -2479,7 +2501,7 @@ class DistInfoDistribution(Distribution): distvers = re.sub(self.EQEQ, r"\1==\2\3", distvers) distvers = distvers.replace('(', '').replace(')', '') return (distvers, mark) - + def _compute_dependencies(self): """Recompute this distribution's dependencies.""" def dummy_marker(marker): @@ -2501,7 +2523,7 @@ class DistInfoDistribution(Distribution): parsed = parse_requirements(distvers).next() parsed.marker_fn = compile_marker(mark) reqs.append(parsed) - + def reqs_for_extra(extra): for req in reqs: if req.marker_fn(override={'extra':extra}): @@ -2509,13 +2531,13 @@ class DistInfoDistribution(Distribution): common = frozenset(reqs_for_extra(None)) dm[None].extend(common) - + for extra in self._parsed_pkg_info.get_all('Provides-Extra') or []: extra = safe_extra(extra.strip()) dm[extra] = list(frozenset(reqs_for_extra(extra)) - common) return dm - + _distributionImpl = {'.egg': Distribution, '.egg-info': Distribution, -- cgit v1.2.1 From ceb03af882740ae02ef4be004a30b45c7b25b9ce Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Mon, 26 Nov 2012 09:20:11 -0500 Subject: Backed out changeset: 98a9f9dcce0e; Fixes #335. --HG-- branch : distribute extra : rebase_source : 3f4ff1c880688e6dd72d2fa8fab3c07e7f486a7e --- pkg_resources.py | 60 ++++++++++++++++++-------------------------------------- 1 file changed, 19 insertions(+), 41 deletions(-) (limited to 'pkg_resources.py') diff --git a/pkg_resources.py b/pkg_resources.py index a39a32dc..a5a10eb4 100644 --- a/pkg_resources.py +++ b/pkg_resources.py @@ -517,7 +517,7 @@ class WorkingSet(object): seen[key]=1 yield self.by_key[key] - def add(self, dist, entry=None, insert=True, replace=False): + def add(self, dist, entry=None, insert=True): """Add `dist` to working set, associated with `entry` If `entry` is unspecified, it defaults to the ``.location`` of `dist`. @@ -525,9 +525,8 @@ class WorkingSet(object): set's ``.entries`` (if it wasn't already present). `dist` is only added to the working set if it's for a project that - doesn't already have a distribution in the set, unless `replace=True`. - If it's added, any callbacks registered with the ``subscribe()`` method - will be called. + doesn't already have a distribution in the set. If it's added, any + callbacks registered with the ``subscribe()`` method will be called. """ if insert: dist.insert_on(self.entries, entry) @@ -536,7 +535,7 @@ class WorkingSet(object): entry = dist.location keys = self.entry_keys.setdefault(entry,[]) keys2 = self.entry_keys.setdefault(dist.location,[]) - if not replace and dist.key in self.by_key: + if dist.key in self.by_key: return # ignore hidden distros self.by_key[dist.key] = dist @@ -546,8 +545,7 @@ class WorkingSet(object): keys2.append(dist.key) self._added_new(dist) - def resolve(self, requirements, env=None, installer=None, - replacement=True, replace_conflicting=False): + def resolve(self, requirements, env=None, installer=None, replacement=True): """List all distributions needed to (recursively) meet `requirements` `requirements` must be a sequence of ``Requirement`` objects. `env`, @@ -557,12 +555,6 @@ class WorkingSet(object): will be invoked with each requirement that cannot be met by an already-installed distribution; it should return a ``Distribution`` or ``None``. - - Unless `replace_conflicting=True`, raises a VersionConflict exception if - any requirements are found on the path that have the correct name but - the wrong version. Otherwise, if an `installer` is supplied it will be - invoked to obtain the correct version of the requirement and activate - it. """ requirements = list(requirements)[::-1] # set up the stack @@ -582,18 +574,10 @@ class WorkingSet(object): if dist is None: # Find the best distribution and add it to the map dist = self.by_key.get(req.key) - if dist is None or (dist not in req and replace_conflicting): - ws = self + if dist is None: if env is None: - if dist is None: - env = Environment(self.entries) - else: - # Use an empty environment and workingset to avoid - # any further conflicts with the conflicting - # distribution - env = Environment([]) - ws = WorkingSet([]) - dist = best[req.key] = env.best_match(req, ws, installer) + env = Environment(self.entries) + dist = best[req.key] = env.best_match(req, self, installer) if dist is None: #msg = ("The '%s' distribution was not found on this " # "system, and is required by this application.") @@ -1814,7 +1798,6 @@ def register_namespace_handler(importer_type, namespace_handler): def _handle_ns(packageName, path_item): """Ensure that named package includes a subpath of path_item (if needed)""" - importer = get_importer(path_item) if importer is None: return None @@ -1824,19 +1807,14 @@ def _handle_ns(packageName, path_item): module = sys.modules.get(packageName) if module is None: module = sys.modules[packageName] = types.ModuleType(packageName) - module.__path__ = [] - _set_parent_ns(packageName) + module.__path__ = []; _set_parent_ns(packageName) elif not hasattr(module,'__path__'): raise TypeError("Not a package:", packageName) handler = _find_adapter(_namespace_handlers, importer) - subpath = handler(importer, path_item, packageName, module) + subpath = handler(importer,path_item,packageName,module) if subpath is not None: - path = module.__path__ - path.append(subpath) - loader.load_module(packageName) - for path_item in path: - if path_item not in module.__path__: - module.__path__.append(path_item) + path = module.__path__; path.append(subpath) + loader.load_module(packageName); module.__path__ = path return subpath def declare_namespace(packageName): @@ -2142,7 +2120,7 @@ def _remove_md5_fragment(location): class Distribution(object): """Wrap an actual or potential sys.path entry w/metadata""" PKG_INFO = 'PKG-INFO' - + def __init__(self, location=None, metadata=None, project_name=None, version=None, py_version=PY_MAJOR, platform=None, precedence = EGG_DIST @@ -2481,7 +2459,7 @@ class DistInfoDistribution(Distribution): from email.parser import Parser self._pkg_info = Parser().parsestr(self.get_metadata(self.PKG_INFO)) return self._pkg_info - + @property def _dep_map(self): try: @@ -2492,7 +2470,7 @@ class DistInfoDistribution(Distribution): def _preparse_requirement(self, requires_dist): """Convert 'Foobar (1); baz' to ('Foobar ==1', 'baz') - Split environment marker, add == prefix to version specifiers as + Split environment marker, add == prefix to version specifiers as necessary, and remove parenthesis. """ parts = requires_dist.split(';', 1) + [''] @@ -2501,7 +2479,7 @@ class DistInfoDistribution(Distribution): distvers = re.sub(self.EQEQ, r"\1==\2\3", distvers) distvers = distvers.replace('(', '').replace(')', '') return (distvers, mark) - + def _compute_dependencies(self): """Recompute this distribution's dependencies.""" from _markerlib import compile as compile_marker @@ -2514,7 +2492,7 @@ class DistInfoDistribution(Distribution): parsed = parse_requirements(distvers).next() parsed.marker_fn = compile_marker(mark) reqs.append(parsed) - + def reqs_for_extra(extra): for req in reqs: if req.marker_fn(override={'extra':extra}): @@ -2522,13 +2500,13 @@ class DistInfoDistribution(Distribution): common = frozenset(reqs_for_extra(None)) dm[None].extend(common) - + for extra in self._parsed_pkg_info.get_all('Provides-Extra') or []: extra = safe_extra(extra.strip()) dm[extra] = list(frozenset(reqs_for_extra(extra)) - common) return dm - + _distributionImpl = {'.egg': Distribution, '.egg-info': Distribution, -- cgit v1.2.1 From 20e832ab13ec7544d5fb014b25cb733e515119c7 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Mon, 17 Dec 2012 13:03:16 +0100 Subject: Minimize impact of namespace package support for CPython 3.3. This solves a regression with an admittedly obscure use case involving Mercurial's demandimport implementation, but it also seems like neater code. --HG-- branch : distribute extra : rebase_source : 10fb05d0391607140ced288a2c134f4463eddf5a --- pkg_resources.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'pkg_resources.py') diff --git a/pkg_resources.py b/pkg_resources.py index a5a10eb4..cf0ef7b4 100644 --- a/pkg_resources.py +++ b/pkg_resources.py @@ -1325,12 +1325,8 @@ class DefaultProvider(EggProvider): register_loader_type(type(None), DefaultProvider) -try: - # CPython >=3.3 +if sys.version_info[:2] >= 3.3: import _frozen_importlib -except ImportError: - pass -else: register_loader_type(_frozen_importlib.SourceFileLoader, DefaultProvider) -- cgit v1.2.1 From 4607463e4a161e557f411b85eb193024b60c45ac Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Mon, 17 Dec 2012 15:13:17 -0500 Subject: Resave with excess whitespace removed --HG-- branch : distribute extra : rebase_source : 5ed95bbd6e5742422dba402aa88707287be44d2e --- pkg_resources.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'pkg_resources.py') diff --git a/pkg_resources.py b/pkg_resources.py index cf0ef7b4..8f88db4d 100644 --- a/pkg_resources.py +++ b/pkg_resources.py @@ -2116,7 +2116,7 @@ def _remove_md5_fragment(location): class Distribution(object): """Wrap an actual or potential sys.path entry w/metadata""" PKG_INFO = 'PKG-INFO' - + def __init__(self, location=None, metadata=None, project_name=None, version=None, py_version=PY_MAJOR, platform=None, precedence = EGG_DIST @@ -2455,7 +2455,7 @@ class DistInfoDistribution(Distribution): from email.parser import Parser self._pkg_info = Parser().parsestr(self.get_metadata(self.PKG_INFO)) return self._pkg_info - + @property def _dep_map(self): try: @@ -2466,7 +2466,7 @@ class DistInfoDistribution(Distribution): def _preparse_requirement(self, requires_dist): """Convert 'Foobar (1); baz' to ('Foobar ==1', 'baz') - Split environment marker, add == prefix to version specifiers as + Split environment marker, add == prefix to version specifiers as necessary, and remove parenthesis. """ parts = requires_dist.split(';', 1) + [''] @@ -2475,7 +2475,7 @@ class DistInfoDistribution(Distribution): distvers = re.sub(self.EQEQ, r"\1==\2\3", distvers) distvers = distvers.replace('(', '').replace(')', '') return (distvers, mark) - + def _compute_dependencies(self): """Recompute this distribution's dependencies.""" from _markerlib import compile as compile_marker @@ -2488,7 +2488,7 @@ class DistInfoDistribution(Distribution): parsed = parse_requirements(distvers).next() parsed.marker_fn = compile_marker(mark) reqs.append(parsed) - + def reqs_for_extra(extra): for req in reqs: if req.marker_fn(override={'extra':extra}): @@ -2496,13 +2496,13 @@ class DistInfoDistribution(Distribution): common = frozenset(reqs_for_extra(None)) dm[None].extend(common) - + for extra in self._parsed_pkg_info.get_all('Provides-Extra') or []: extra = safe_extra(extra.strip()) dm[extra] = list(frozenset(reqs_for_extra(extra)) - common) return dm - + _distributionImpl = {'.egg': Distribution, '.egg-info': Distribution, -- cgit v1.2.1 From 5854afbb1e30152e38dca1d9c70c1c4cb990e87d Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Mon, 17 Dec 2012 15:14:50 -0500 Subject: Fix issue with version detection --HG-- branch : distribute extra : rebase_source : 7e9dfc000ca44eaed1054d72144408530ec49741 --- pkg_resources.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pkg_resources.py') diff --git a/pkg_resources.py b/pkg_resources.py index 8f88db4d..53978086 100644 --- a/pkg_resources.py +++ b/pkg_resources.py @@ -1325,7 +1325,7 @@ class DefaultProvider(EggProvider): register_loader_type(type(None), DefaultProvider) -if sys.version_info[:2] >= 3.3: +if sys.version_info[:2] >= (3,3): import _frozen_importlib register_loader_type(_frozen_importlib.SourceFileLoader, DefaultProvider) -- cgit v1.2.1 From cd1e33d5567d9f892f8145beb4b39eeeafa760b9 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Mon, 17 Dec 2012 15:15:53 -0500 Subject: Update changelog and add comment to registering of SourceFileLoader --HG-- branch : distribute extra : rebase_source : 2701f50b3375f9c2f2378ff22f274aade0b03107 --- pkg_resources.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'pkg_resources.py') diff --git a/pkg_resources.py b/pkg_resources.py index 53978086..717c1e6a 100644 --- a/pkg_resources.py +++ b/pkg_resources.py @@ -1325,6 +1325,9 @@ class DefaultProvider(EggProvider): register_loader_type(type(None), DefaultProvider) +# Python 3.3 also supplies the SourceFileLoader. +# Don't be tempted to do a try/except block here - it will break Mercurial +# hooks due to the demandimport functionality. if sys.version_info[:2] >= (3,3): import _frozen_importlib register_loader_type(_frozen_importlib.SourceFileLoader, DefaultProvider) -- cgit v1.2.1 From 73e70541ad60633c5b373eeafab1cfba6e81606c Mon Sep 17 00:00:00 2001 From: Arfrever Frehtes Taifersar Arahesis Date: Tue, 18 Dec 2012 04:09:33 +0100 Subject: Clean handling of _frozen_importlib / importlib._bootstrap. --HG-- branch : distribute extra : rebase_source : 52fd775f637dfa40c401ef590708ffeaf47fd3a9 --- pkg_resources.py | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) (limited to 'pkg_resources.py') diff --git a/pkg_resources.py b/pkg_resources.py index 717c1e6a..85e008a2 100644 --- a/pkg_resources.py +++ b/pkg_resources.py @@ -33,6 +33,12 @@ except ImportError: from os import open as os_open from os.path import isdir, split +# Avoid try/except due to potential problems with delayed import mechanisms. +if sys.version_info >= (3, 3) and sys.implementation.name == "cpython": + import importlib._bootstrap as importlib_bootstrap +else: + importlib_bootstrap = None + # This marker is used to simplify the process that checks is the # setuptools package was installed by the Setuptools project # or by the Distribute project, in case Setuptools creates @@ -1325,12 +1331,8 @@ class DefaultProvider(EggProvider): register_loader_type(type(None), DefaultProvider) -# Python 3.3 also supplies the SourceFileLoader. -# Don't be tempted to do a try/except block here - it will break Mercurial -# hooks due to the demandimport functionality. -if sys.version_info[:2] >= (3,3): - import _frozen_importlib - register_loader_type(_frozen_importlib.SourceFileLoader, DefaultProvider) +if importlib_bootstrap is not None: + register_loader_type(importlib_bootstrap.SourceFileLoader, DefaultProvider) class EmptyProvider(NullProvider): @@ -1766,13 +1768,8 @@ def find_on_path(importer, path_item, only=False): break register_finder(ImpWrapper,find_on_path) -try: - # CPython >=3.3 - import _frozen_importlib -except ImportError: - pass -else: - register_finder(_frozen_importlib.FileFinder, find_on_path) +if importlib_bootstrap is not None: + register_finder(importlib_bootstrap.FileFinder, find_on_path) _declare_state('dict', _namespace_handlers={}) _declare_state('dict', _namespace_packages={}) @@ -1873,13 +1870,8 @@ def file_ns_handler(importer, path_item, packageName, module): register_namespace_handler(ImpWrapper,file_ns_handler) register_namespace_handler(zipimport.zipimporter,file_ns_handler) -try: - # CPython >=3.3 - import _frozen_importlib -except ImportError: - pass -else: - register_namespace_handler(_frozen_importlib.FileFinder, file_ns_handler) +if importlib_bootstrap is not None: + register_namespace_handler(importlib_bootstrap.FileFinder, file_ns_handler) def null_ns_handler(importer, path_item, packageName, module): -- cgit v1.2.1 From 5f6ebc0579291a7dd316e2a64466e688ef7bdb69 Mon Sep 17 00:00:00 2001 From: Arfrever Frehtes Taifersar Arahesis Date: Sat, 29 Dec 2012 05:27:56 +0100 Subject: Issue #341: Fix a ResourceWarning. --HG-- branch : distribute extra : rebase_source : 63fc40de80b49769d8463e04c1590ea4b1e751fc --- pkg_resources.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'pkg_resources.py') diff --git a/pkg_resources.py b/pkg_resources.py index 85e008a2..939a7c64 100644 --- a/pkg_resources.py +++ b/pkg_resources.py @@ -1761,11 +1761,13 @@ def find_on_path(importer, path_item, only=False): for dist in find_distributions(os.path.join(path_item, entry)): yield dist elif not only and lower.endswith('.egg-link'): - for line in open(os.path.join(path_item, entry)): + entry_file = open(os.path.join(path_item, entry)) + for line in entry_file: if not line.strip(): continue for item in find_distributions(os.path.join(path_item,line.rstrip())): yield item break + entry_file.close() register_finder(ImpWrapper,find_on_path) if importlib_bootstrap is not None: -- cgit v1.2.1 From d73c8722858cc7aaca77a22d0e84795bc6262420 Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Sat, 29 Dec 2012 12:54:21 -0500 Subject: Harden fix for issue #341 against exceptins. --HG-- branch : distribute extra : rebase_source : 5cb7f22523a741e678b03a699f0ef09f09ed8070 --- pkg_resources.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'pkg_resources.py') diff --git a/pkg_resources.py b/pkg_resources.py index 939a7c64..cb8d3dcf 100644 --- a/pkg_resources.py +++ b/pkg_resources.py @@ -1762,12 +1762,14 @@ def find_on_path(importer, path_item, only=False): yield dist elif not only and lower.endswith('.egg-link'): entry_file = open(os.path.join(path_item, entry)) - for line in entry_file: - if not line.strip(): continue - for item in find_distributions(os.path.join(path_item,line.rstrip())): - yield item - break - entry_file.close() + try: + for line in entry_file: + if not line.strip(): continue + for item in find_distributions(os.path.join(path_item,line.rstrip())): + yield item + break + finally: + entry_file.close() register_finder(ImpWrapper,find_on_path) if importlib_bootstrap is not None: -- cgit v1.2.1 From 2f8c8bd5de518bd1b42cb99f1a6644543520154b Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Sun, 30 Dec 2012 23:45:44 -0500 Subject: Close issue #341: 0.6.33 fails to build under python 2.4 --HG-- branch : distribute extra : rebase_source : 065aad71143a72cb6abd3064e0e947fc4568422f --- pkg_resources.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'pkg_resources.py') diff --git a/pkg_resources.py b/pkg_resources.py index cb8d3dcf..49aab675 100644 --- a/pkg_resources.py +++ b/pkg_resources.py @@ -1763,13 +1763,14 @@ def find_on_path(importer, path_item, only=False): elif not only and lower.endswith('.egg-link'): entry_file = open(os.path.join(path_item, entry)) try: - for line in entry_file: - if not line.strip(): continue - for item in find_distributions(os.path.join(path_item,line.rstrip())): - yield item - break + entry_lines = entry_file.readlines() finally: entry_file.close() + for line in entry_lines: + if not line.strip(): continue + for item in find_distributions(os.path.join(path_item,line.rstrip())): + yield item + break register_finder(ImpWrapper,find_on_path) if importlib_bootstrap is not None: -- cgit v1.2.1 From b5cd47fbd96ae900dd835b68484084ab1219f260 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 16 Feb 2013 02:13:45 -0500 Subject: Backed out changeset: d0a8d1a83053 In the discussion in #278, it became clear that the deviance in behavior from setuptools is problemmatic. For compatibility, defer to the setuptools version scheme as specifically intended. --HG-- branch : distribute extra : rebase_source : 1d5cc8c216f974b247e2dc84d8d40c868d6d3639 --- pkg_resources.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'pkg_resources.py') diff --git a/pkg_resources.py b/pkg_resources.py index 49aab675..69601480 100644 --- a/pkg_resources.py +++ b/pkg_resources.py @@ -1936,7 +1936,7 @@ replace = {'pre':'c', 'preview':'c','-':'final-','rc':'c','dev':'@'}.get def _parse_version_parts(s): for part in component_re.split(s): part = replace(part,part) - if part in ['', '.']: + if not part or part=='.': continue if part[:1] in '0123456789': yield part.zfill(8) # pad for numeric comparison @@ -1979,6 +1979,8 @@ def parse_version(s): parts = [] for part in _parse_version_parts(s.lower()): if part.startswith('*'): + if part<'*final': # remove '-' before a prerelease tag + while parts and parts[-1]=='*final-': parts.pop() # remove trailing zeros from each series of numeric parts while parts and parts[-1]=='00000000': parts.pop() -- cgit v1.2.1 From 065e8eb834d65b4e0572611c16f7f2950db4512b Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 11 May 2013 10:59:30 +0100 Subject: Verified that not isinstance(IOError(), os.error), so there's no value in this statement being in the try block. --HG-- branch : distribute extra : rebase_source : 79dc86f2251503336feaa3d3f99c744d0ea45887 --- pkg_resources.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'pkg_resources.py') diff --git a/pkg_resources.py b/pkg_resources.py index 69601480..9d406e38 100644 --- a/pkg_resources.py +++ b/pkg_resources.py @@ -1409,10 +1409,10 @@ class ZipProvider(EggProvider): ) timestamp = time.mktime(date_time) + if not WRITE_SUPPORT: + raise IOError('"os.rename" and "os.unlink" are not supported ' + 'on this platform') try: - if not WRITE_SUPPORT: - raise IOError('"os.rename" and "os.unlink" are not supported ' - 'on this platform') real_path = manager.get_cache_path( self.egg_name, self._parts(zip_path) -- cgit v1.2.1 From 9027ce5419a346e068927df72dbfcd650cdee33f Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 11 May 2013 12:43:23 +0100 Subject: Extract static method for calculating size and timestamp on a zip resource --HG-- branch : distribute extra : rebase_source : 3acd099bb90d9abf4d3b265946e0c59b8edcae6e --- pkg_resources.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'pkg_resources.py') diff --git a/pkg_resources.py b/pkg_resources.py index 9d406e38..579e3b46 100644 --- a/pkg_resources.py +++ b/pkg_resources.py @@ -1392,6 +1392,16 @@ class ZipProvider(EggProvider): self._extract_resource(manager, self._eager_to_zip(name)) return self._extract_resource(manager, zip_path) + @staticmethod + def _get_date_and_size(zip_stat): + t,d,size = zip_stat[5], zip_stat[6], zip_stat[3] + date_time = ( + (d>>9)+1980, (d>>5)&0xF, d&0x1F, # ymd + (t&0xFFFF)>>11, (t>>5)&0x3F, (t&0x1F) * 2, 0, 0, -1 # hms, etc. + ) + timestamp = time.mktime(date_time) + return timestamp, size + def _extract_resource(self, manager, zip_path): if zip_path in self._index(): @@ -1401,13 +1411,7 @@ class ZipProvider(EggProvider): ) return os.path.dirname(last) # return the extracted directory name - zip_stat = self.zipinfo[zip_path] - t,d,size = zip_stat[5], zip_stat[6], zip_stat[3] - date_time = ( - (d>>9)+1980, (d>>5)&0xF, d&0x1F, # ymd - (t&0xFFFF)>>11, (t>>5)&0x3F, (t&0x1F) * 2, 0, 0, -1 # hms, etc. - ) - timestamp = time.mktime(date_time) + timestamp, size = self._get_date_and_size(self.zipinfo[zip_path]) if not WRITE_SUPPORT: raise IOError('"os.rename" and "os.unlink" are not supported ' -- cgit v1.2.1 From 7adfcead12a21b2ed6b13f5a75477914b524cb12 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 11 May 2013 12:54:26 +0100 Subject: Extract method to determine if a temporary file is current. --HG-- branch : distribute extra : rebase_source : ec2c1860f0ce9abbc3ea999aa54304ea9cc6ecd7 --- pkg_resources.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'pkg_resources.py') diff --git a/pkg_resources.py b/pkg_resources.py index 579e3b46..b59f1703 100644 --- a/pkg_resources.py +++ b/pkg_resources.py @@ -1422,11 +1422,8 @@ class ZipProvider(EggProvider): self.egg_name, self._parts(zip_path) ) - if os.path.isfile(real_path): - stat = os.stat(real_path) - if stat.st_size==size and stat.st_mtime==timestamp: - # size and stamp match, don't bother extracting - return real_path + if self.is_current(real_path, zip_path): + return real_path outf, tmpnam = _mkstemp(".$extract", dir=os.path.dirname(real_path)) os.write(outf, self.loader.get_data(zip_path)) @@ -1439,11 +1436,9 @@ class ZipProvider(EggProvider): except os.error: if os.path.isfile(real_path): - stat = os.stat(real_path) - - if stat.st_size==size and stat.st_mtime==timestamp: - # size and stamp match, somebody did it just ahead of - # us, so we're done + if self._is_current(real_path, zip_path): + # the file became current since it was checked above, + # so proceed. return real_path elif os.name=='nt': # Windows, del old file and retry unlink(real_path) @@ -1456,6 +1451,16 @@ class ZipProvider(EggProvider): return real_path + def _is_current(self, file_path, zip_path): + """ + Return True if the file_path is current for this zip_path + """ + timestamp, size = self._get_date_and_size(self.zipinfo[zip_path]) + if not os.path.isfile(file_path): + return False + stat = os.stat(file_path) + return stat.st_size==size and stat.st_mtime==timestamp + def _get_eager_resources(self): if self.eagers is None: eagers = [] -- cgit v1.2.1 From f0a3905357e596c9a2a85358fda0f41384ff3d39 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 11 May 2013 13:05:32 +0100 Subject: Fix for yet unpublished issue to ensure that get_resource_filename always re-extracts the content of a temporary filename if it does not match that of the source content. --HG-- branch : distribute extra : rebase_source : 5605ee258010cde1237db058b770c62264c215e2 --- pkg_resources.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'pkg_resources.py') diff --git a/pkg_resources.py b/pkg_resources.py index b59f1703..2ec645d3 100644 --- a/pkg_resources.py +++ b/pkg_resources.py @@ -1459,7 +1459,14 @@ class ZipProvider(EggProvider): if not os.path.isfile(file_path): return False stat = os.stat(file_path) - return stat.st_size==size and stat.st_mtime==timestamp + if stat.st_size!=size or stat.st_mtime!=timestamp: + return False + # check that the contents match + zip_contents = self.loader.get_data(zip_path) + f = open(file_path, 'rb') + file_contents = f.read() + f.close() + return zip_contents == file_contents def _get_eager_resources(self): if self.eagers is None: -- cgit v1.2.1 From b9661afd506c7c5f43d01c092ce313f33e730892 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 12 May 2013 13:34:15 -0400 Subject: Fix AttributeError on underscore-prefixed method name. --HG-- branch : distribute extra : rebase_source : 8ceb2c2f067a60225bb83817a8584d93f489a3d0 --- pkg_resources.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pkg_resources.py') diff --git a/pkg_resources.py b/pkg_resources.py index 2ec645d3..f8de449e 100644 --- a/pkg_resources.py +++ b/pkg_resources.py @@ -1422,7 +1422,7 @@ class ZipProvider(EggProvider): self.egg_name, self._parts(zip_path) ) - if self.is_current(real_path, zip_path): + if self._is_current(real_path, zip_path): return real_path outf, tmpnam = _mkstemp(".$extract", dir=os.path.dirname(real_path)) -- cgit v1.2.1 From 1f43ab9b03178a3eb3a00f509338dc1bd40808a1 Mon Sep 17 00:00:00 2001 From: Philip Thiem Date: Sat, 2 Feb 2013 18:26:56 -0600 Subject: This changes distribute to use zipfile for obtaining a manifest of zip files instead of zipimpot._zip_directory_cache. As I don't see any place that the cache is being clear, should in effect remove the zipimport private variable dependency --HG-- branch : distribute extra : rebase_source : 275dd3d5a2f55dba541f7f12a1bf8ee7c3465825 --- pkg_resources.py | 48 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 11 deletions(-) (limited to 'pkg_resources.py') diff --git a/pkg_resources.py b/pkg_resources.py index f8de449e..e1bf9ee0 100644 --- a/pkg_resources.py +++ b/pkg_resources.py @@ -13,7 +13,8 @@ The package resource API is designed to work with normal filesystem packages, method. """ -import sys, os, zipimport, time, re, imp, types +import sys, os, zipimport, time, re, imp, types +import zipfile from urlparse import urlparse, urlunparse try: @@ -1348,7 +1349,33 @@ class EmptyProvider(NullProvider): empty_provider = EmptyProvider() - +def build_zipmanifest(path): + """ + This builds a similar dictionary to the zipimport directory + caches. However instead of tuples, ZipInfo objects are stored. + + The translation of the tuple is as follows: + * [0] - zipinfo.filename on stock pythons this needs "/" --> os.sep + on pypy it is the same (one reason why distribute did work + in some cases on pypy and win32). + * [1] - zipinfo.compress_type + * [2] - zipinfo.compress_size + * [3] - zipinfo.file_size + * [4] - len(utf-8 encoding of filename) if zipinfo & 0x800 + len(ascii encoding of filename) otherwise + * [5] - (zipinfo.date_time[0] - 1980) << 9 | + zipinfo.date_time[1] << 5 | zipinfo.date_time[2] + * [6] - (zipinfo.date_time[3] - 1980) << 11 | + zipinfo.date_time[4] << 5 | (zipinfo.date_time[5] // 2) + * [7] - zipinfo.CRC + """ + zipinfo = dict() + with zipfile.ZipFile(path) as zfile: + for zitem in zfile.namelist(): + zpath = zitem.replace('/', os.sep) + zipinfo[zpath] = zfile.getinfo(zitem) + assert zipinfo[zpath] is not None + return zipinfo class ZipProvider(EggProvider): @@ -1358,7 +1385,7 @@ class ZipProvider(EggProvider): def __init__(self, module): EggProvider.__init__(self,module) - self.zipinfo = zipimport._zip_directory_cache[self.loader.archive] + self.zipinfo = build_zipmanifest(self.load.archive) self.zip_pre = self.loader.archive+os.sep def _zipinfo_name(self, fspath): @@ -1393,12 +1420,10 @@ class ZipProvider(EggProvider): return self._extract_resource(manager, zip_path) @staticmethod - def _get_date_and_size(zip_stat): - t,d,size = zip_stat[5], zip_stat[6], zip_stat[3] - date_time = ( - (d>>9)+1980, (d>>5)&0xF, d&0x1F, # ymd - (t&0xFFFF)>>11, (t>>5)&0x3F, (t&0x1F) * 2, 0, 0, -1 # hms, etc. - ) + def _get_date_and_size(zip_stat): + size = zip_stat.file_size + date_time = zip_stat.date_time + (0, 0, -1) #ymdhms+wday, yday, dst + #1980 offset already done timestamp = time.mktime(date_time) return timestamp, size @@ -1411,7 +1436,7 @@ class ZipProvider(EggProvider): ) return os.path.dirname(last) # return the extracted directory name - timestamp, size = self._get_date_and_size(self.zipinfo[zip_path]) + timestamp, size = self._get_date_and_size(self.zipinfo[zip_path]) if not WRITE_SUPPORT: raise IOError('"os.rename" and "os.unlink" are not supported ' @@ -1610,7 +1635,7 @@ class EggMetadata(ZipProvider): def __init__(self, importer): """Create a metadata provider from a zipimporter""" - self.zipinfo = zipimport._zip_directory_cache[importer.archive] + self.zipinfo = build_zipmanifest(importer.archive) self.zip_pre = importer.archive+os.sep self.loader = importer if importer.prefix: @@ -2841,3 +2866,4 @@ run_main = run_script # backward compatibility add_activation_listener(lambda dist: dist.activate()) working_set.entries=[]; map(working_set.add_entry,sys.path) # match order + -- cgit v1.2.1 From 0c10ea7a063c2d3f3c3c539c1d601fd8d95429dd Mon Sep 17 00:00:00 2001 From: Philip Thiem Date: Tue, 5 Feb 2013 09:55:53 -0600 Subject: minor cleanups --HG-- branch : distribute extra : rebase_source : a872a0ee0700a60994fea3417193998d9e9456a3 --- pkg_resources.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'pkg_resources.py') diff --git a/pkg_resources.py b/pkg_resources.py index e1bf9ee0..144323cb 100644 --- a/pkg_resources.py +++ b/pkg_resources.py @@ -1349,6 +1349,7 @@ class EmptyProvider(NullProvider): empty_provider = EmptyProvider() + def build_zipmanifest(path): """ This builds a similar dictionary to the zipimport directory @@ -1363,9 +1364,9 @@ def build_zipmanifest(path): * [3] - zipinfo.file_size * [4] - len(utf-8 encoding of filename) if zipinfo & 0x800 len(ascii encoding of filename) otherwise - * [5] - (zipinfo.date_time[0] - 1980) << 9 | + * [5] - (zipinfo.date_time[0] - 1980) << 9 | zipinfo.date_time[1] << 5 | zipinfo.date_time[2] - * [6] - (zipinfo.date_time[3] - 1980) << 11 | + * [6] - (zipinfo.date_time[3] - 1980) << 11 | zipinfo.date_time[4] << 5 | (zipinfo.date_time[5] // 2) * [7] - zipinfo.CRC """ @@ -1422,7 +1423,7 @@ class ZipProvider(EggProvider): @staticmethod def _get_date_and_size(zip_stat): size = zip_stat.file_size - date_time = zip_stat.date_time + (0, 0, -1) #ymdhms+wday, yday, dst + date_time = zip_stat.date_time + (0, 0, -1) # ymdhms+wday, yday, dst #1980 offset already done timestamp = time.mktime(date_time) return timestamp, size -- cgit v1.2.1 From 4e2823bc3f2f5505ee15fc72ebcc287e5061199d Mon Sep 17 00:00:00 2001 From: Philip Thiem Date: Sat, 16 Feb 2013 10:46:33 -0600 Subject: Seems to be an issue with using ZipFile as a context on python 3.1 --HG-- branch : distribute extra : rebase_source : d81c62a1c2efbeefc848979e07b16506213c0949 --- pkg_resources.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'pkg_resources.py') diff --git a/pkg_resources.py b/pkg_resources.py index 144323cb..c29afb56 100644 --- a/pkg_resources.py +++ b/pkg_resources.py @@ -1371,11 +1371,15 @@ def build_zipmanifest(path): * [7] - zipinfo.CRC """ zipinfo = dict() - with zipfile.ZipFile(path) as zfile: + zfile = zipfile.ZipFile(path) + #Got ZipFile has not __exit__ on python 3.1 + try: for zitem in zfile.namelist(): zpath = zitem.replace('/', os.sep) zipinfo[zpath] = zfile.getinfo(zitem) assert zipinfo[zpath] is not None + finally: + zfile.close() return zipinfo -- cgit v1.2.1 From 6f6de308e3ade9a262308297f0a96af261c9dde5 Mon Sep 17 00:00:00 2001 From: Philip Thiem Date: Sat, 16 Feb 2013 11:34:11 -0600 Subject: Backout the pkg_resources.py fix --HG-- branch : distribute extra : rebase_source : d144d2afc763c9ed6420d32bad3015075d265226 --- pkg_resources.py | 51 ++++++++++----------------------------------------- 1 file changed, 10 insertions(+), 41 deletions(-) (limited to 'pkg_resources.py') diff --git a/pkg_resources.py b/pkg_resources.py index c29afb56..fbae7b57 100644 --- a/pkg_resources.py +++ b/pkg_resources.py @@ -13,8 +13,7 @@ The package resource API is designed to work with normal filesystem packages, method. """ -import sys, os, zipimport, time, re, imp, types -import zipfile +import sys, os, zipimport, time, re, imp, types from urlparse import urlparse, urlunparse try: @@ -1350,37 +1349,6 @@ class EmptyProvider(NullProvider): empty_provider = EmptyProvider() -def build_zipmanifest(path): - """ - This builds a similar dictionary to the zipimport directory - caches. However instead of tuples, ZipInfo objects are stored. - - The translation of the tuple is as follows: - * [0] - zipinfo.filename on stock pythons this needs "/" --> os.sep - on pypy it is the same (one reason why distribute did work - in some cases on pypy and win32). - * [1] - zipinfo.compress_type - * [2] - zipinfo.compress_size - * [3] - zipinfo.file_size - * [4] - len(utf-8 encoding of filename) if zipinfo & 0x800 - len(ascii encoding of filename) otherwise - * [5] - (zipinfo.date_time[0] - 1980) << 9 | - zipinfo.date_time[1] << 5 | zipinfo.date_time[2] - * [6] - (zipinfo.date_time[3] - 1980) << 11 | - zipinfo.date_time[4] << 5 | (zipinfo.date_time[5] // 2) - * [7] - zipinfo.CRC - """ - zipinfo = dict() - zfile = zipfile.ZipFile(path) - #Got ZipFile has not __exit__ on python 3.1 - try: - for zitem in zfile.namelist(): - zpath = zitem.replace('/', os.sep) - zipinfo[zpath] = zfile.getinfo(zitem) - assert zipinfo[zpath] is not None - finally: - zfile.close() - return zipinfo class ZipProvider(EggProvider): @@ -1390,7 +1358,7 @@ class ZipProvider(EggProvider): def __init__(self, module): EggProvider.__init__(self,module) - self.zipinfo = build_zipmanifest(self.load.archive) + self.zipinfo = zipimport._zip_directory_cache[self.loader.archive] self.zip_pre = self.loader.archive+os.sep def _zipinfo_name(self, fspath): @@ -1425,10 +1393,12 @@ class ZipProvider(EggProvider): return self._extract_resource(manager, zip_path) @staticmethod - def _get_date_and_size(zip_stat): - size = zip_stat.file_size - date_time = zip_stat.date_time + (0, 0, -1) # ymdhms+wday, yday, dst - #1980 offset already done + def _get_date_and_size(zip_stat): + t,d,size = zip_stat[5], zip_stat[6], zip_stat[3] + date_time = ( + (d>>9)+1980, (d>>5)&0xF, d&0x1F, # ymd + (t&0xFFFF)>>11, (t>>5)&0x3F, (t&0x1F) * 2, 0, 0, -1 # hms, etc. + ) timestamp = time.mktime(date_time) return timestamp, size @@ -1441,7 +1411,7 @@ class ZipProvider(EggProvider): ) return os.path.dirname(last) # return the extracted directory name - timestamp, size = self._get_date_and_size(self.zipinfo[zip_path]) + timestamp, size = self._get_date_and_size(self.zipinfo[zip_path]) if not WRITE_SUPPORT: raise IOError('"os.rename" and "os.unlink" are not supported ' @@ -1640,7 +1610,7 @@ class EggMetadata(ZipProvider): def __init__(self, importer): """Create a metadata provider from a zipimporter""" - self.zipinfo = build_zipmanifest(importer.archive) + self.zipinfo = zipimport._zip_directory_cache[importer.archive] self.zip_pre = importer.archive+os.sep self.loader = importer if importer.prefix: @@ -2871,4 +2841,3 @@ run_main = run_script # backward compatibility add_activation_listener(lambda dist: dist.activate()) working_set.entries=[]; map(working_set.add_entry,sys.path) # match order - -- cgit v1.2.1 From e183ab7e708f7875f15f0a4651aaa85b6693882f Mon Sep 17 00:00:00 2001 From: Philip Thiem Date: Sat, 16 Feb 2013 11:35:08 -0600 Subject: Reapply with unix file endings, to make a better diff --HG-- branch : distribute extra : rebase_source : 8fdc661ab1dd38af6d692df15ff65392860a60d1 --- pkg_resources.py | 46 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 8 deletions(-) (limited to 'pkg_resources.py') diff --git a/pkg_resources.py b/pkg_resources.py index fbae7b57..878c4ea1 100644 --- a/pkg_resources.py +++ b/pkg_resources.py @@ -13,7 +13,7 @@ The package resource API is designed to work with normal filesystem packages, method. """ -import sys, os, zipimport, time, re, imp, types +import sys, os, time, re, imp, types, zipfile, zipimport from urlparse import urlparse, urlunparse try: @@ -1349,6 +1349,37 @@ class EmptyProvider(NullProvider): empty_provider = EmptyProvider() +def build_zipmanifest(path): + """ + This builds a similar dictionary to the zipimport directory + caches. However instead of tuples, ZipInfo objects are stored. + + The translation of the tuple is as follows: + * [0] - zipinfo.filename on stock pythons this needs "/" --> os.sep + on pypy it is the same (one reason why distribute did work + in some cases on pypy and win32). + * [1] - zipinfo.compress_type + * [2] - zipinfo.compress_size + * [3] - zipinfo.file_size + * [4] - len(utf-8 encoding of filename) if zipinfo & 0x800 + len(ascii encoding of filename) otherwise + * [5] - (zipinfo.date_time[0] - 1980) << 9 | + zipinfo.date_time[1] << 5 | zipinfo.date_time[2] + * [6] - (zipinfo.date_time[3] - 1980) << 11 | + zipinfo.date_time[4] << 5 | (zipinfo.date_time[5] // 2) + * [7] - zipinfo.CRC + """ + zipinfo = dict() + zfile = zipfile.ZipFile(path) + #Got ZipFile has not __exit__ on python 3.1 + try: + for zitem in zfile.namelist(): + zpath = zitem.replace('/', os.sep) + zipinfo[zpath] = zfile.getinfo(zitem) + assert zipinfo[zpath] is not None + finally: + zfile.close() + return zipinfo class ZipProvider(EggProvider): @@ -1358,7 +1389,7 @@ class ZipProvider(EggProvider): def __init__(self, module): EggProvider.__init__(self,module) - self.zipinfo = zipimport._zip_directory_cache[self.loader.archive] + self.zipinfo = build_zipmanifest(self.load.archive) self.zip_pre = self.loader.archive+os.sep def _zipinfo_name(self, fspath): @@ -1394,11 +1425,9 @@ class ZipProvider(EggProvider): @staticmethod def _get_date_and_size(zip_stat): - t,d,size = zip_stat[5], zip_stat[6], zip_stat[3] - date_time = ( - (d>>9)+1980, (d>>5)&0xF, d&0x1F, # ymd - (t&0xFFFF)>>11, (t>>5)&0x3F, (t&0x1F) * 2, 0, 0, -1 # hms, etc. - ) + size = zip_stat.file_size + date_time = zip_stat.date_time + (0, 0, -1) # ymdhms+wday, yday, dst + #1980 offset already done timestamp = time.mktime(date_time) return timestamp, size @@ -1610,7 +1639,7 @@ class EggMetadata(ZipProvider): def __init__(self, importer): """Create a metadata provider from a zipimporter""" - self.zipinfo = zipimport._zip_directory_cache[importer.archive] + self.zipinfo = build_zipmanifest(importer.archive) self.zip_pre = importer.archive+os.sep self.loader = importer if importer.prefix: @@ -2841,3 +2870,4 @@ run_main = run_script # backward compatibility add_activation_listener(lambda dist: dist.activate()) working_set.entries=[]; map(working_set.add_entry,sys.path) # match order + -- cgit v1.2.1 From c7444dbad6e996c53b3f73f0dba71b3b3a33f8bf Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 24 May 2013 09:18:49 -0400 Subject: Correct reference to self.loader. --HG-- branch : distribute --- pkg_resources.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'pkg_resources.py') diff --git a/pkg_resources.py b/pkg_resources.py index 878c4ea1..74acecd5 100644 --- a/pkg_resources.py +++ b/pkg_resources.py @@ -1348,7 +1348,7 @@ class EmptyProvider(NullProvider): empty_provider = EmptyProvider() - + def build_zipmanifest(path): """ This builds a similar dictionary to the zipimport directory @@ -1389,7 +1389,7 @@ class ZipProvider(EggProvider): def __init__(self, module): EggProvider.__init__(self,module) - self.zipinfo = build_zipmanifest(self.load.archive) + self.zipinfo = build_zipmanifest(self.loader.archive) self.zip_pre = self.loader.archive+os.sep def _zipinfo_name(self, fspath): -- cgit v1.2.1