Skip to content

Commit

Permalink
Merge pull request #1232 from duggelz/dgreiman/issue1188
Browse files Browse the repository at this point in the history
Fix trailing slash handling in pkg_resources.ZipProvider
  • Loading branch information
jaraco authored Dec 25, 2017
2 parents e001996 + 0d0baed commit 1ad2c11
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
v38.2.5
-------

* #1232: Fix trailing slash handling in ``pkg_resources.ZipProvider``.

v38.2.4
-------

Expand Down
3 changes: 3 additions & 0 deletions pkg_resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1693,6 +1693,9 @@ def __init__(self, module):
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(
Expand Down
35 changes: 35 additions & 0 deletions pkg_resources/tests/test_pkg_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,52 @@ def setup_class(cls):
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
def teardown_class(cls):
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
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 38.2.4
current_version = 38.2.5
commit = True
tag = True

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 1ad2c11

Please sign in to comment.