From 37f97140afe2c4178d519645815471d94af62192 Mon Sep 17 00:00:00 2001 From: Tzu-ping Chung Date: Thu, 9 Jan 2020 13:00:49 +0530 Subject: [PATCH 1/4] Also use rmtree to remove tmpdir_factory Same as e2c345100152fc7f2638ec8c3fd117cb67959c26 --- tests/conftest.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index 16b5c6202..bd3ca171f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -83,7 +83,10 @@ def tmpdir_factory(request, tmpdir_factory): """ yield tmpdir_factory if not request.config.getoption("--keep-tmpdir"): - tmpdir_factory.getbasetemp().remove(ignore_errors=True) + shutil.rmtree( + six.text_type(tmpdir_factory.getbasetemp()), + ignore_errors=True, + ) @pytest.fixture From 7a80acaf446c018bd4be0b970a38466dee240d4d Mon Sep 17 00:00:00 2001 From: Tzu-ping Chung Date: Thu, 9 Jan 2020 13:01:31 +0530 Subject: [PATCH 2/4] Tell shutil.make_archive to use Unicode paths By default, make_archive uses str paths on Python 2, which causes it to skip files with unencodable names. By passing in a unicode base_dir explicitly, it is smart enough to use unicode all the way down instead. --- tests/lib/__init__.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/lib/__init__.py b/tests/lib/__init__.py index 10c9e47d6..de30829a3 100644 --- a/tests/lib/__init__.py +++ b/tests/lib/__init__.py @@ -15,7 +15,7 @@ from textwrap import dedent from zipfile import ZipFile import pytest -from pip._vendor.six import PY2, ensure_binary +from pip._vendor.six import PY2, ensure_binary, text_type from scripttest import FoundDir, TestFileEnvironment from pip._internal.index.collector import LinkCollector @@ -1053,7 +1053,12 @@ def create_basic_wheel_for_package( path.write_bytes(ensure_binary(files[fname])) retval = script.scratch_path / archive_name - generated = shutil.make_archive(retval, 'zip', script.temp_path) + generated = shutil.make_archive( + retval, + 'zip', + root_dir=script.temp_path, + base_dir=text_type(os.curdir), + ) shutil.move(generated, retval) shutil.rmtree(script.temp_path) From facf5c8894bce519066e9f5c108100a59a7116dd Mon Sep 17 00:00:00 2001 From: Tzu-ping Chung Date: Thu, 9 Jan 2020 13:11:30 +0530 Subject: [PATCH 3/4] Add comments to unicode workarounds --- tests/conftest.py | 6 ++++++ tests/lib/__init__.py | 3 +++ 2 files changed, 9 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index bd3ca171f..fd8204713 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -83,6 +83,9 @@ def tmpdir_factory(request, tmpdir_factory): """ yield tmpdir_factory if not request.config.getoption("--keep-tmpdir"): + # py.path.remove() uses str paths on Python 2 and cannot + # handle non-ASCII file names. This works around the problem by + # passing a unicode object to rmtree(). shutil.rmtree( six.text_type(tmpdir_factory.getbasetemp()), ignore_errors=True, @@ -106,6 +109,9 @@ def tmpdir(request, tmpdir): # This should prevent us from needing a multiple gigabyte temporary # directory while running the tests. if not request.config.getoption("--keep-tmpdir"): + # py.path.remove() uses str paths on Python 2 and cannot + # handle non-ASCII file names. This works around the problem by + # passing a unicode object to rmtree(). shutil.rmtree(six.text_type(tmpdir), ignore_errors=True) diff --git a/tests/lib/__init__.py b/tests/lib/__init__.py index de30829a3..9a55c156e 100644 --- a/tests/lib/__init__.py +++ b/tests/lib/__init__.py @@ -1052,6 +1052,9 @@ def create_basic_wheel_for_package( path.parent.mkdir(exist_ok=True, parents=True) path.write_bytes(ensure_binary(files[fname])) + # The base_dir cast is required to make `shutil.make_archive()` use + # Unicode paths on Python 2, making it able to properly archive + # files with non-ASCII names. retval = script.scratch_path / archive_name generated = shutil.make_archive( retval, From ff4ee68470d63c1f018324b8d1df8eb52cb99a23 Mon Sep 17 00:00:00 2001 From: Tzu-ping Chung Date: Thu, 9 Jan 2020 13:15:35 +0530 Subject: [PATCH 4/4] News --- news/7577.trivial | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 news/7577.trivial diff --git a/news/7577.trivial b/news/7577.trivial new file mode 100644 index 000000000..e69de29bb