From b47da272aa849a79b950425ec7bae3cd1b0f1311 Mon Sep 17 00:00:00 2001 From: Bertil Hatt Date: Sat, 27 Oct 2018 12:51:21 +0100 Subject: [PATCH] Set sys.argv[0] to the underlying setup.py in the setuptools shim. --- news/1890.bugfix | 2 ++ src/pip/_internal/req/req_install.py | 6 +++--- src/pip/_internal/utils/setuptools_build.py | 7 ++++++- src/pip/_internal/wheel.py | 2 +- 4 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 news/1890.bugfix diff --git a/news/1890.bugfix b/news/1890.bugfix new file mode 100644 index 00000000000..8f85e1255a2 --- /dev/null +++ b/news/1890.bugfix @@ -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``. diff --git a/src/pip/_internal/req/req_install.py b/src/pip/_internal/req/req_install.py index 5192ab2fd42..59305df02be 100644 --- a/src/pip/_internal/req/req_install.py +++ b/src/pip/_internal/req/req_install.py @@ -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"] @@ -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'] + @@ -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'] diff --git a/src/pip/_internal/utils/setuptools_build.py b/src/pip/_internal/utils/setuptools_build.py index 03973e976ca..207c6fb96da 100644 --- a/src/pip/_internal/utils/setuptools_build.py +++ b/src/pip/_internal/utils/setuptools_build.py @@ -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();" diff --git a/src/pip/_internal/wheel.py b/src/pip/_internal/wheel.py index a7350c9eca9..a3934acba24 100644 --- a/src/pip/_internal/wheel.py +++ b/src/pip/_internal/wheel.py @@ -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):