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.
上级 2e8e5ad3
......@@ -3,6 +3,8 @@ import textwrap
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('''
......@@ -27,7 +29,7 @@ _SETUPTOOLS_SHIM = textwrap.dedent(
)
sys.exit(1)
__file__ = {!r}
__file__ = %r
sys.argv[0] = __file__
if os.path.exists(__file__):
......@@ -39,7 +41,7 @@ _SETUPTOOLS_SHIM = textwrap.dedent(
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()
......
......@@ -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]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册