From 75727f87e94a50ecc5c3ef10c794303875b79b15 Mon Sep 17 00:00:00 2001 From: Trishank K Kuppusamy Date: Fri, 16 Mar 2018 15:16:03 -0400 Subject: [PATCH 1/4] correctly(?) escape distribution names for wheels per PEP 427 --- libpip2pi/commands.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libpip2pi/commands.py b/libpip2pi/commands.py index 3079b50..dbd2791 100644 --- a/libpip2pi/commands.py +++ b/libpip2pi/commands.py @@ -115,7 +115,8 @@ 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. + to_safe_name = lambda x: re.sub("[^\w\d.]+", "_", x, re.UNICODE) to_safe_rest = lambda x: x else: match = re.search(r"(?P.*?)-(?P\d+.*)", file) From ae49c1a4e0bdc5f0877d41ae9d862969be7830b5 Mon Sep 17 00:00:00 2001 From: Trishank K Kuppusamy Date: Fri, 16 Mar 2018 15:23:57 -0400 Subject: [PATCH 2/4] fix an ordering bug in printing a debug statement --- libpip2pi/commands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libpip2pi/commands.py b/libpip2pi/commands.py index dbd2791..732b4f2 100644 --- a/libpip2pi/commands.py +++ b/libpip2pi/commands.py @@ -345,7 +345,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: From 6742e2ba6422548f1fcf4ebe4a4e4521964cff8c Mon Sep 17 00:00:00 2001 From: Trishank K Kuppusamy Date: Fri, 16 Mar 2018 15:25:49 -0400 Subject: [PATCH 3/4] add link to pep 427 --- libpip2pi/commands.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libpip2pi/commands.py b/libpip2pi/commands.py index 732b4f2..0dafbd6 100644 --- a/libpip2pi/commands.py +++ b/libpip2pi/commands.py @@ -115,7 +115,8 @@ def file_to_package(file, basedir=None): elif file_ext == ".whl": bits = file.rsplit("-", 4) split = (bits[0], "-".join(bits[1:])) - # Correctly escape filenames according to PEP 427. + # 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: From 2daed1b2a64c4e50cad972d8f38559da7928cb1d Mon Sep 17 00:00:00 2001 From: Trishank K Kuppusamy Date: Fri, 16 Mar 2018 15:43:54 -0400 Subject: [PATCH 4/4] turns out hyphens are needed in standard distribution names --- libpip2pi/commands.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/libpip2pi/commands.py b/libpip2pi/commands.py index 0dafbd6..3c1e0f1 100644 --- a/libpip2pi/commands.py +++ b/libpip2pi/commands.py @@ -327,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)