Skip to content

Commit

Permalink
Double-escape paths on Windows
Browse files Browse the repository at this point in the history
This helps ensure that they aren't improperly handled due to the newer
string-in-string design for the setuptools invocation script.
  • Loading branch information
pradyunsg committed Jan 25, 2022
1 parent 2e8e5ad commit 723b2df
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/pip/_internal/utils/setuptools_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from typing import List, Optional, Sequence

# Shim to wrap setup.py invocation with setuptools
# Note that __file__ is handled via two {!r} *and* %r, to ensure that paths on
# Windows are correctly handled (it should be "C:\\Users" not "C:\Users").
_SETUPTOOLS_SHIM = textwrap.dedent(
"""
exec(compile('''
Expand All @@ -27,7 +29,7 @@
)
sys.exit(1)
__file__ = {!r}
__file__ = %r
sys.argv[0] = __file__
if os.path.exists(__file__):
Expand All @@ -39,7 +41,7 @@
setup_py_code = "from setuptools import setup; setup()"
exec(compile(setup_py_code, filename, "exec"))
''', "<pip-setuptools-caller>", "exec"))
''' % ({!r},), "<pip-setuptools-caller>", "exec"))
"""
).rstrip()

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ def test_make_setuptools_shim_args() -> None:
shim = args[3]
# Spot-check key aspects of the command string.
assert "import setuptools" in shim
assert "__file__ = '/dir/path/setup.py'" in args[3]
assert "'/dir/path/setup.py'" in args[3]
assert "sys.argv[0] = __file__" in args[3]


Expand Down

0 comments on commit 723b2df

Please sign in to comment.