Skip to content

Commit

Permalink
Merge pull request #5936 from bertilhatt/subprocess_invocation_out_se…
Browse files Browse the repository at this point in the history
…tuptools_args

Fix #1890: set sys.argv[0] to the setup.py path in the setuptools shim
  • Loading branch information
cjerdonek authored Jul 8, 2019
2 parents 9311049 + b47da27 commit ca017ca
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
2 changes: 2 additions & 0 deletions news/1890.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Set ``sys.argv[0]`` to the underlying ``setup.py`` when invoking ``setup.py``
via the setuptools shim so setuptools doesn't think the path is ``-c``.
6 changes: 3 additions & 3 deletions src/pip/_internal/req/req_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ def run_egg_info(self):
'Running setup.py (path:%s) egg_info for package from %s',
self.setup_py_path, self.link,
)
script = SETUPTOOLS_SHIM % self.setup_py_path
script = SETUPTOOLS_SHIM.format(self.setup_py_path)
base_cmd = [sys.executable, '-c', script]
if self.isolated:
base_cmd += ["--no-user-cfg"]
Expand Down Expand Up @@ -757,7 +757,7 @@ def install_editable(
[
sys.executable,
'-c',
SETUPTOOLS_SHIM % self.setup_py_path
SETUPTOOLS_SHIM.format(self.setup_py_path)
] +
list(global_options) +
['develop', '--no-deps'] +
Expand Down Expand Up @@ -1004,7 +1004,7 @@ def get_install_args(
# type: (...) -> List[str]
install_args = [sys.executable, "-u"]
install_args.append('-c')
install_args.append(SETUPTOOLS_SHIM % self.setup_py_path)
install_args.append(SETUPTOOLS_SHIM.format(self.setup_py_path))
install_args += list(global_options) + \
['install', '--record', record_filename]
install_args += ['--single-version-externally-managed']
Expand Down
7 changes: 6 additions & 1 deletion src/pip/_internal/utils/setuptools_build.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Shim to wrap setup.py invocation with setuptools
#
# We set sys.argv[0] to the path to the underlying setup.py file so
# setuptools / distutils don't take the path to the setup.py to be "-c" when
# invoking via the shim. This avoids e.g. the following manifest_maker
# warning: "warning: manifest_maker: standard file '-c' not found".
SETUPTOOLS_SHIM = (
"import setuptools, tokenize;__file__=%r;"
"import sys, setuptools, tokenize; sys.argv[0] = {0!r}; __file__={0!r};"
"f=getattr(tokenize, 'open', open)(__file__);"
"code=f.read().replace('\\r\\n', '\\n');"
"f.close();"
Expand Down
2 changes: 1 addition & 1 deletion src/pip/_internal/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ def _base_setup_args(self, req):
# virtualenv.
return [
sys.executable, '-u', '-c',
SETUPTOOLS_SHIM % req.setup_py_path,
SETUPTOOLS_SHIM.format(req.setup_py_path)
] + list(self.global_options)

def _build_one_pep517(self, req, tempd, python_tag=None):
Expand Down

0 comments on commit ca017ca

Please sign in to comment.