From 593b409fb66efcabe046e240a868b7dbcf1fc01b Mon Sep 17 00:00:00 2001 From: Arnon Yaari Date: Mon, 14 May 2018 17:10:29 +0300 Subject: [PATCH 1/2] Use canonicalize_name to look for .dist-info in wheel files Fixes issue #1350 --- setuptools/tests/test_wheel.py | 33 +++++++++++++++++++++++++++++++++ setuptools/wheel.py | 16 ++++++++++++++-- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/setuptools/tests/test_wheel.py b/setuptools/tests/test_wheel.py index 150ac4c1b5..cf6508686d 100644 --- a/setuptools/tests/test_wheel.py +++ b/setuptools/tests/test_wheel.py @@ -9,12 +9,15 @@ import glob import inspect import os +import shutil import subprocess import sys +import zipfile import pytest from pkg_resources import Distribution, PathMetadata, PY_MAJOR +from setuptools.extern.packaging.utils import canonicalize_name from setuptools.wheel import Wheel from .contexts import tempdir @@ -506,3 +509,33 @@ def test_wheel_install(params): _check_wheel_install(filename, install_dir, install_tree, project_name, version, requires_txt) + + +def test_wheel_install_pep_503(): + project_name = 'Foo_Bar' # PEP 503 canonicalized name is "foo-bar" + version = '1.0' + with build_wheel( + name=project_name, + version=version, + ) as filename, tempdir() as install_dir: + new_filename = filename.replace(project_name, + canonicalize_name(project_name)) + shutil.move(filename, new_filename) + _check_wheel_install(new_filename, install_dir, None, + canonicalize_name(project_name), + version, None) + + +def test_wheel_no_dist_dir(): + project_name = 'nodistinfo' + version = '1.0' + wheel_name = '{0}-{1}-py2.py3-none-any.whl'.format(project_name, version) + with tempdir() as source_dir: + wheel_path = os.path.join(source_dir, wheel_name) + # create an empty zip file + zipfile.ZipFile(wheel_path, 'w').close() + with tempdir() as install_dir: + with pytest.raises(ValueError): + _check_wheel_install(wheel_path, install_dir, None, + project_name, + version, None) diff --git a/setuptools/wheel.py b/setuptools/wheel.py index 37dfa53103..4a33b20324 100644 --- a/setuptools/wheel.py +++ b/setuptools/wheel.py @@ -4,10 +4,12 @@ import email import itertools import os +import posixpath import re import zipfile from pkg_resources import Distribution, PathMetadata, parse_version +from setuptools.extern.packaging.utils import canonicalize_name from setuptools.extern.six import PY3 from setuptools import Distribution as SetuptoolsDistribution from setuptools import pep425tags @@ -77,14 +79,24 @@ def egg_name(self): platform=(None if self.platform == 'any' else get_platform()), ).egg_name() + '.egg' + def get_dist_info(self, zf): + # find the correct name of the .dist-info dir in the wheel file + for member in zf.namelist(): + dirname = posixpath.dirname(member) + if (dirname.endswith('.dist-info') and + canonicalize_name(dirname).startswith( + canonicalize_name(self.project_name))): + return dirname + raise ValueError("unsupported wheel format. .dist-info not found") + def install_as_egg(self, destination_eggdir): '''Install wheel as an egg directory.''' with zipfile.ZipFile(self.filename) as zf: dist_basename = '%s-%s' % (self.project_name, self.version) - dist_info = '%s.dist-info' % dist_basename + dist_info = self.get_dist_info(zf) dist_data = '%s.data' % dist_basename def get_metadata(name): - with zf.open('%s/%s' % (dist_info, name)) as fp: + with zf.open(posixpath.join(dist_info, name)) as fp: value = fp.read().decode('utf-8') if PY3 else fp.read() return email.parser.Parser().parsestr(value) wheel_metadata = get_metadata('WHEEL') From 70c786bb62973a1b8284bceef1321ece79ceb7ee Mon Sep 17 00:00:00 2001 From: Paul Ganssle Date: Tue, 15 May 2018 13:04:44 -0400 Subject: [PATCH 2/2] Add changelog for #1360 --- changelog.d/1360.change.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/1360.change.rst diff --git a/changelog.d/1360.change.rst b/changelog.d/1360.change.rst new file mode 100644 index 0000000000..36f40483b3 --- /dev/null +++ b/changelog.d/1360.change.rst @@ -0,0 +1 @@ +Fixed issue with a mismatch between the name of the package and the name of the .dist-info file in wheel files