From a8bc5337a471dfc617c355ad1cda6efa756069b3 Mon Sep 17 00:00:00 2001 From: DongHun Kwak Date: Mon, 14 Jan 2019 10:40:47 +0900 Subject: [PATCH] Imported Upstream version 38.2.5 --- CHANGES.rst | 5 +++++ pkg_resources/__init__.py | 3 +++ pkg_resources/tests/test_pkg_resources.py | 35 +++++++++++++++++++++++++++++++ setup.cfg | 2 +- setup.py | 2 +- 5 files changed, 45 insertions(+), 2 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 3694b15..7227b7f 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,8 @@ +v38.2.5 +------- + +* #1232: Fix trailing slash handling in ``pkg_resources.ZipProvider``. + v38.2.4 ------- diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py index 7333464..08f9bbe 100644 --- a/pkg_resources/__init__.py +++ b/pkg_resources/__init__.py @@ -1693,6 +1693,9 @@ class ZipProvider(EggProvider): def _zipinfo_name(self, fspath): # Convert a virtual filename (full path to file) into a zipfile subpath # usable with the zipimport directory cache for our target archive + fspath = fspath.rstrip(os.sep) + if fspath == self.loader.archive: + return '' if fspath.startswith(self.zip_pre): return fspath[len(self.zip_pre):] raise AssertionError( diff --git a/pkg_resources/tests/test_pkg_resources.py b/pkg_resources/tests/test_pkg_resources.py index c6a7ac9..f2c00b2 100644 --- a/pkg_resources/tests/test_pkg_resources.py +++ b/pkg_resources/tests/test_pkg_resources.py @@ -62,10 +62,21 @@ class TestZipProvider(object): zip_info.filename = 'data.dat' zip_info.date_time = cls.ref_time.timetuple() zip_egg.writestr(zip_info, 'hello, world!') + zip_info = zipfile.ZipInfo() + zip_info.filename = 'subdir/mod2.py' + zip_info.date_time = cls.ref_time.timetuple() + zip_egg.writestr(zip_info, 'x = 6\n') + zip_info = zipfile.ZipInfo() + zip_info.filename = 'subdir/data2.dat' + zip_info.date_time = cls.ref_time.timetuple() + zip_egg.writestr(zip_info, 'goodbye, world!') zip_egg.close() egg.close() sys.path.append(egg.name) + subdir = os.path.join(egg.name, 'subdir') + sys.path.append(subdir) + cls.finalizers.append(EggRemover(subdir)) cls.finalizers.append(EggRemover(egg.name)) @classmethod @@ -73,6 +84,30 @@ class TestZipProvider(object): for finalizer in cls.finalizers: finalizer() + def test_resource_listdir(self): + import mod + zp = pkg_resources.ZipProvider(mod) + + expected_root = ['data.dat', 'mod.py', 'subdir'] + assert sorted(zp.resource_listdir('')) == expected_root + assert sorted(zp.resource_listdir('/')) == expected_root + + expected_subdir = ['data2.dat', 'mod2.py'] + assert sorted(zp.resource_listdir('subdir')) == expected_subdir + assert sorted(zp.resource_listdir('subdir/')) == expected_subdir + + assert zp.resource_listdir('nonexistent') == [] + assert zp.resource_listdir('nonexistent/') == [] + + import mod2 + zp2 = pkg_resources.ZipProvider(mod2) + + assert sorted(zp2.resource_listdir('')) == expected_subdir + assert sorted(zp2.resource_listdir('/')) == expected_subdir + + assert zp2.resource_listdir('subdir') == [] + assert zp2.resource_listdir('subdir/') == [] + def test_resource_filename_rewrites_on_change(self): """ If a previous call to get_resource_filename has saved the file, but diff --git a/setup.cfg b/setup.cfg index d6f1a19..0a33329 100755 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 38.2.4 +current_version = 38.2.5 commit = True tag = True diff --git a/setup.py b/setup.py index 0e3e42c..af799e4 100755 --- a/setup.py +++ b/setup.py @@ -89,7 +89,7 @@ def pypi_link(pkg_filename): setup_params = dict( name="setuptools", - version="38.2.4", + version="38.2.5", description="Easily download, build, install, upgrade, and uninstall " "Python packages", author="Python Packaging Authority", -- 2.7.4