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

Ensure entry points are read as UTF-8 #8343

Merged
merged 4 commits into from
Jun 30, 2020
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion NEWS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Deprecations and Removals
Bug Fixes
---------

- Correctly treat wheels contenting non-ASCII file contents so they can be
- Correctly treat wheels containing non-ASCII file contents so they can be
installed on Windows. (`#5712 <https://github.com/pypa/pip/issues/5712>`_)
- Revert building of local directories in place, restoring the pre-20.1
behaviour of copying to a temporary directory. (`#7555 <https://github.com/pypa/pip/issues/7555>`_)
Expand Down
2 changes: 2 additions & 0 deletions news/8342.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Correctly treat non-ASCII entry point declarations in wheels so they can be
installed on Windows.
16 changes: 5 additions & 11 deletions src/pip/_internal/operations/install/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import compileall
import contextlib
import csv
import io
import logging
import os.path
import re
Expand All @@ -21,14 +22,7 @@
from pip._vendor import pkg_resources
from pip._vendor.distlib.scripts import ScriptMaker
from pip._vendor.distlib.util import get_export_entry
from pip._vendor.six import (
PY2,
StringIO,
ensure_str,
ensure_text,
itervalues,
text_type,
)
from pip._vendor.six import PY2, ensure_str, ensure_text, itervalues, text_type

from pip._internal.exceptions import InstallationError
from pip._internal.locations import get_major_minor_version
Expand Down Expand Up @@ -131,11 +125,11 @@ def get_entrypoints(filename):
# means that they may or may not be valid INI files. The attempt here is to
# strip leading and trailing whitespace in order to make them valid INI
# files.
with open(filename) as fp:
data = StringIO()
with io.open(filename, encoding="utf-8") as fp:
data = io.StringIO()
for line in fp:
data.write(line.strip())
data.write("\n")
data.write(u"\n")
data.seek(0)

# get the entry points and then the script names
Expand Down
22 changes: 22 additions & 0 deletions tests/functional/test_install_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,28 @@ def test_install_from_wheel_gen_uppercase_entrypoint(
assert bool(os.access(script.base_path / wrapper_file, os.X_OK))


# pkg_resources.EntryPoint() does not parse unicode correctly on Python 2.
@skip_if_python2
def test_install_from_wheel_gen_unicode_entrypoint(script):
make_wheel(
"script_wheel_unicode",
"1.0",
console_scripts=["進入點 = 模組:函式"],
).save_to_dir(script.scratch_path)

result = script.pip(
"install",
"--no-index",
"--find-links",
script.scratch_path,
"script_wheel_unicode",
)
if os.name == "nt":
result.did_create(script.bin.joinpath("進入點.exe"))
else:
result.did_create(script.bin.joinpath("進入點"))


def test_install_from_wheel_with_legacy(script, shared_data, tmpdir):
"""
Test installing scripts (legacy scripts are preserved)
Expand Down
18 changes: 12 additions & 6 deletions tests/unit/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

"""Tests for wheel binary packages and .dist-info."""
import csv
import io
import logging
import os
import textwrap
Expand Down Expand Up @@ -29,7 +30,7 @@
from pip._internal.utils.compat import WINDOWS
from pip._internal.utils.misc import hash_file
from pip._internal.utils.unpacking import unpack_file
from tests.lib import DATA_DIR, assert_paths_equal
from tests.lib import DATA_DIR, assert_paths_equal, skip_if_python2


def call_get_legacy_build_wheel_path(caplog, names):
Expand Down Expand Up @@ -81,13 +82,18 @@ def test_get_legacy_build_wheel_path__multiple_names(caplog):
]


@pytest.mark.parametrize("console_scripts",
["pip = pip._internal.main:pip",
"pip:pip = pip._internal.main:pip"])
@pytest.mark.parametrize(
"console_scripts",
[
u"pip = pip._internal.main:pip",
u"pip:pip = pip._internal.main:pip",
pytest.param(u"進入點 = 套件.模組:函式", marks=skip_if_python2),
],
)
def test_get_entrypoints(tmpdir, console_scripts):
entry_points = tmpdir.joinpath("entry_points.txt")
with open(str(entry_points), "w") as fp:
fp.write("""
with io.open(str(entry_points), "w", encoding="utf-8") as fp:
fp.write(u"""
[console_scripts]
{}
[section]
Expand Down