Skip to content

Commit 723b2df

Browse files
committed
Double-escape paths on Windows
This helps ensure that they aren't improperly handled due to the newer string-in-string design for the setuptools invocation script.
1 parent 2e8e5ad commit 723b2df

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/pip/_internal/utils/setuptools_build.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from typing import List, Optional, Sequence
44

55
# Shim to wrap setup.py invocation with setuptools
6+
# Note that __file__ is handled via two {!r} *and* %r, to ensure that paths on
7+
# Windows are correctly handled (it should be "C:\\Users" not "C:\Users").
68
_SETUPTOOLS_SHIM = textwrap.dedent(
79
"""
810
exec(compile('''
@@ -27,7 +29,7 @@
2729
)
2830
sys.exit(1)
2931
30-
__file__ = {!r}
32+
__file__ = %r
3133
sys.argv[0] = __file__
3234
3335
if os.path.exists(__file__):
@@ -39,7 +41,7 @@
3941
setup_py_code = "from setuptools import setup; setup()"
4042
4143
exec(compile(setup_py_code, filename, "exec"))
42-
''', "<pip-setuptools-caller>", "exec"))
44+
''' % ({!r},), "<pip-setuptools-caller>", "exec"))
4345
"""
4446
).rstrip()
4547

tests/unit/test_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ def test_make_setuptools_shim_args() -> None:
948948
shim = args[3]
949949
# Spot-check key aspects of the command string.
950950
assert "import setuptools" in shim
951-
assert "__file__ = '/dir/path/setup.py'" in args[3]
951+
assert "'/dir/path/setup.py'" in args[3]
952952
assert "sys.argv[0] = __file__" in args[3]
953953

954954

0 commit comments

Comments
 (0)