Commit 5832e763 authored by Paul Ganssle's avatar Paul Ganssle Committed by GitHub

Merge pull request #1360 from Infinidat/issue1350

Use canonicalize_name to look for .dist-info in wheel files
parents 41b39539 70c786bb
Fixed issue with a mismatch between the name of the package and the name of the .dist-info file in wheel files
......@@ -9,12 +9,15 @@ import contextlib
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)
......@@ -4,10 +4,12 @@ from distutils.util import get_platform
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 @@ class Wheel(object):
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')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment