Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly(?) escape distribution names for wheels #72

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions libpip2pi/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ def file_to_package(file, basedir=None):
elif file_ext == ".whl":
bits = file.rsplit("-", 4)
split = (bits[0], "-".join(bits[1:]))
to_safe_name = pkg_resources.safe_name
# Correctly escape filenames according to PEP 427:
# https://www.python.org/dev/peps/pep-0427/#escaping-and-unicode
to_safe_name = lambda x: re.sub("[^\w\d.]+", "_", x, re.UNICODE)
to_safe_rest = lambda x: x
else:
match = re.search(r"(?P<pkg>.*?)-(?P<rest>\d+.*)", file)
Expand Down Expand Up @@ -325,7 +327,14 @@ def _dir2pi(option, argv):
continue
pkg_name, pkg_rest = file_to_package(pkg_basename, pkgdir)

pkg_dir_name = pkg_name
# FIXME: A hack to workaround what are considered safe names for
# distributions in wheels vs standard distribution names.
# https://github.com/pypa/setuptools/blob/16187afb3f532199f4951801d4e39939c560facc/pkg_resources/__init__.py#L1416-L1421
if file.endswith(".whl"):
pkg_dir_name = pkg_resources.safe_name(pkg_name)
else:
pkg_dir_name = pkg_name

if option.normalize_package_names:
pkg_dir_name = normalize_pep503(pkg_dir_name)

Expand All @@ -344,7 +353,7 @@ def _dir2pi(option, argv):
try_symlink(option, symlink_source, symlink_target)
else:
if option.verbose:
print('copying %s to %s' % (symlink_target, pkg_filepath))
print('copying %s to %s' % (pkg_filepath, symlink_target))
shutil.copy2(pkg_filepath, symlink_target)

if pkg_name not in processed_pkg:
Expand Down