From e8b71ea33ee0fd4ab06d96bf5411d5958999b04c Mon Sep 17 00:00:00 2001 From: Chris Hunt Date: Fri, 11 Oct 2019 19:15:51 -0400 Subject: [PATCH 01/11] Simplify constructing editable install args --- src/pip/_internal/req/req_install.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/pip/_internal/req/req_install.py b/src/pip/_internal/req/req_install.py index 5f1fdb74b1e..517d7d009c2 100644 --- a/src/pip/_internal/req/req_install.py +++ b/src/pip/_internal/req/req_install.py @@ -687,20 +687,23 @@ def install_editable( # type: (...) -> None logger.info('Running setup.py develop for %s', self.name) - if prefix: - prefix_param = ['--prefix={}'.format(prefix)] - install_options = list(install_options) + prefix_param - base_cmd = make_setuptools_shim_args( + args = make_setuptools_shim_args( self.setup_py_path, global_options=global_options, no_user_config=self.isolated ) + + args.extend(["develop", "--no-deps"]) + + args.extend(install_options) + + if prefix: + args.extend(["--prefix", prefix]) + with indent_log(): with self.build_env: call_subprocess( - base_cmd + - ['develop', '--no-deps'] + - list(install_options), + args, cwd=self.unpacked_source_directory, ) From c202ae9d7e9bdc471a9c9c718bfd384bdbd3b6f9 Mon Sep 17 00:00:00 2001 From: Chris Hunt Date: Fri, 11 Oct 2019 19:29:26 -0400 Subject: [PATCH 02/11] Make editable install args in setuptools_build --- src/pip/_internal/req/req_install.py | 18 +++++++------- src/pip/_internal/utils/setuptools_build.py | 26 ++++++++++++++++++++- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/pip/_internal/req/req_install.py b/src/pip/_internal/req/req_install.py index 517d7d009c2..4c07a9bc93b 100644 --- a/src/pip/_internal/req/req_install.py +++ b/src/pip/_internal/req/req_install.py @@ -48,7 +48,10 @@ rmtree, ) from pip._internal.utils.packaging import get_metadata -from pip._internal.utils.setuptools_build import make_setuptools_shim_args +from pip._internal.utils.setuptools_build import ( + make_setuptools_develop_args, + make_setuptools_shim_args, +) from pip._internal.utils.subprocess import ( call_subprocess, runner_with_spinner_message, @@ -687,19 +690,14 @@ def install_editable( # type: (...) -> None logger.info('Running setup.py develop for %s', self.name) - args = make_setuptools_shim_args( + args = make_setuptools_develop_args( self.setup_py_path, global_options=global_options, - no_user_config=self.isolated + install_options=install_options, + no_user_config=self.isolated, + prefix=prefix, ) - args.extend(["develop", "--no-deps"]) - - args.extend(install_options) - - if prefix: - args.extend(["--prefix", prefix]) - with indent_log(): with self.build_env: call_subprocess( diff --git a/src/pip/_internal/utils/setuptools_build.py b/src/pip/_internal/utils/setuptools_build.py index 12d866e00a0..4d8b0e1dda0 100644 --- a/src/pip/_internal/utils/setuptools_build.py +++ b/src/pip/_internal/utils/setuptools_build.py @@ -3,7 +3,7 @@ from pip._internal.utils.typing import MYPY_CHECK_RUNNING if MYPY_CHECK_RUNNING: - from typing import List, Sequence + from typing import List, Optional, Sequence # Shim to wrap setup.py invocation with setuptools # @@ -45,3 +45,27 @@ def make_setuptools_shim_args( if no_user_config: args.append('--no-user-cfg') return args + + +def make_setuptools_develop_args( + setup_py_path, # type: str + global_options, # type: Sequence[str] + install_options, # type: Sequence[str] + no_user_config, # type: bool + prefix, # type: Optional[str] +): + # type: (...) -> List[str] + args = make_setuptools_shim_args( + setup_py_path, + global_options=global_options, + no_user_config=no_user_config, + ) + + args.extend(["develop", "--no-deps"]) + + args.extend(install_options) + + if prefix: + args.extend(["--prefix", prefix]) + + return args From 1a6d4036903727946c4cb738ad0fd764873b43fc Mon Sep 17 00:00:00 2001 From: Chris Hunt Date: Fri, 11 Oct 2019 20:09:39 -0400 Subject: [PATCH 03/11] Parameterize member access before moving function --- src/pip/_internal/req/req_install.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/pip/_internal/req/req_install.py b/src/pip/_internal/req/req_install.py index 4c07a9bc93b..cd3c8f03e36 100644 --- a/src/pip/_internal/req/req_install.py +++ b/src/pip/_internal/req/req_install.py @@ -881,7 +881,13 @@ def install( with TempDirectory(kind="record") as temp_dir: record_filename = os.path.join(temp_dir.path, 'install-record.txt') install_args = self.get_install_args( - global_options, record_filename, root, prefix, pycompile, + self.setup_py_path, + global_options=global_options, + record_filename=record_filename, + root=root, + prefix=prefix, + no_user_config=self.isolated, + pycompile=pycompile, ) runner = runner_with_spinner_message( @@ -936,17 +942,19 @@ def prepend_root(path): def get_install_args( self, + setup_py_path, # type: str global_options, # type: Sequence[str] record_filename, # type: str root, # type: Optional[str] prefix, # type: Optional[str] + no_user_config, # type: bool pycompile # type: bool ): # type: (...) -> List[str] install_args = make_setuptools_shim_args( - self.setup_py_path, + setup_py_path, global_options=global_options, - no_user_config=self.isolated, + no_user_config=no_user_config, unbuffered_output=True ) install_args += ['install', '--record', record_filename] From dcd3509eea842179d01f22ad77aeba5452d2d705 Mon Sep 17 00:00:00 2001 From: Chris Hunt Date: Fri, 11 Oct 2019 20:16:26 -0400 Subject: [PATCH 04/11] Finish extracting InstallRequirement.get_install_args --- src/pip/_internal/req/req_install.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/pip/_internal/req/req_install.py b/src/pip/_internal/req/req_install.py index cd3c8f03e36..1f07f77e4e8 100644 --- a/src/pip/_internal/req/req_install.py +++ b/src/pip/_internal/req/req_install.py @@ -878,14 +878,23 @@ def install( install_options = list(install_options) + \ self.options.get('install_options', []) + header_dir = None # type: Optional[str] + if running_under_virtualenv(): + py_ver_str = 'python' + sysconfig.get_python_version() + header_dir = os.path.join( + sys.prefix, 'include', 'site', py_ver_str, self.name + ) + with TempDirectory(kind="record") as temp_dir: record_filename = os.path.join(temp_dir.path, 'install-record.txt') install_args = self.get_install_args( self.setup_py_path, global_options=global_options, + install_options=install_options, record_filename=record_filename, root=root, prefix=prefix, + header_dir=header_dir, no_user_config=self.isolated, pycompile=pycompile, ) @@ -895,7 +904,7 @@ def install( ) with indent_log(), self.build_env: runner( - cmd=install_args + install_options, + cmd=install_args, cwd=self.unpacked_source_directory, ) @@ -944,9 +953,11 @@ def get_install_args( self, setup_py_path, # type: str global_options, # type: Sequence[str] + install_options, # type: Sequence[str] record_filename, # type: str root, # type: Optional[str] prefix, # type: Optional[str] + header_dir, # type: Optional[str] no_user_config, # type: bool pycompile # type: bool ): @@ -970,10 +981,9 @@ def get_install_args( else: install_args += ["--no-compile"] - if running_under_virtualenv(): - py_ver_str = 'python' + sysconfig.get_python_version() - install_args += ['--install-headers', - os.path.join(sys.prefix, 'include', 'site', - py_ver_str, self.name)] + if header_dir: + install_args += ['--install-headers', header_dir] + + install_args += install_options return install_args From c69d194d642546df95187b940f39ff892584effb Mon Sep 17 00:00:00 2001 From: Chris Hunt Date: Fri, 11 Oct 2019 20:25:50 -0400 Subject: [PATCH 05/11] Move install args construction to setuptools_build --- src/pip/_internal/req/req_install.py | 43 +-------------------- src/pip/_internal/utils/setuptools_build.py | 39 +++++++++++++++++++ 2 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/pip/_internal/req/req_install.py b/src/pip/_internal/req/req_install.py index 1f07f77e4e8..e520d167c8e 100644 --- a/src/pip/_internal/req/req_install.py +++ b/src/pip/_internal/req/req_install.py @@ -50,7 +50,7 @@ from pip._internal.utils.packaging import get_metadata from pip._internal.utils.setuptools_build import ( make_setuptools_develop_args, - make_setuptools_shim_args, + make_setuptools_install_args, ) from pip._internal.utils.subprocess import ( call_subprocess, @@ -887,7 +887,7 @@ def install( with TempDirectory(kind="record") as temp_dir: record_filename = os.path.join(temp_dir.path, 'install-record.txt') - install_args = self.get_install_args( + install_args = make_setuptools_install_args( self.setup_py_path, global_options=global_options, install_options=install_options, @@ -948,42 +948,3 @@ def prepend_root(path): inst_files_path = os.path.join(egg_info_dir, 'installed-files.txt') with open(inst_files_path, 'w') as f: f.write('\n'.join(new_lines) + '\n') - - def get_install_args( - self, - setup_py_path, # type: str - global_options, # type: Sequence[str] - install_options, # type: Sequence[str] - record_filename, # type: str - root, # type: Optional[str] - prefix, # type: Optional[str] - header_dir, # type: Optional[str] - no_user_config, # type: bool - pycompile # type: bool - ): - # type: (...) -> List[str] - install_args = make_setuptools_shim_args( - setup_py_path, - global_options=global_options, - no_user_config=no_user_config, - unbuffered_output=True - ) - install_args += ['install', '--record', record_filename] - install_args += ['--single-version-externally-managed'] - - if root is not None: - install_args += ['--root', root] - if prefix is not None: - install_args += ['--prefix', prefix] - - if pycompile: - install_args += ["--compile"] - else: - install_args += ["--no-compile"] - - if header_dir: - install_args += ['--install-headers', header_dir] - - install_args += install_options - - return install_args diff --git a/src/pip/_internal/utils/setuptools_build.py b/src/pip/_internal/utils/setuptools_build.py index 4d8b0e1dda0..495a703e9a0 100644 --- a/src/pip/_internal/utils/setuptools_build.py +++ b/src/pip/_internal/utils/setuptools_build.py @@ -69,3 +69,42 @@ def make_setuptools_develop_args( args.extend(["--prefix", prefix]) return args + + +def make_setuptools_install_args( + setup_py_path, # type: str + global_options, # type: Sequence[str] + install_options, # type: Sequence[str] + record_filename, # type: str + root, # type: Optional[str] + prefix, # type: Optional[str] + header_dir, # type: Optional[str] + no_user_config, # type: bool + pycompile # type: bool +): + # type: (...) -> List[str] + install_args = make_setuptools_shim_args( + setup_py_path, + global_options=global_options, + no_user_config=no_user_config, + unbuffered_output=True + ) + install_args += ['install', '--record', record_filename] + install_args += ['--single-version-externally-managed'] + + if root is not None: + install_args += ['--root', root] + if prefix is not None: + install_args += ['--prefix', prefix] + + if pycompile: + install_args += ["--compile"] + else: + install_args += ["--no-compile"] + + if header_dir: + install_args += ['--install-headers', header_dir] + + install_args += install_options + + return install_args From 440d4c2002275457663d657befd6525a2d785e30 Mon Sep 17 00:00:00 2001 From: Chris Hunt Date: Fri, 11 Oct 2019 20:34:40 -0400 Subject: [PATCH 06/11] Clean up egg_info arg construction --- src/pip/_internal/operations/generate_metadata.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/pip/_internal/operations/generate_metadata.py b/src/pip/_internal/operations/generate_metadata.py index 984748d7fdd..f37d0c7da2d 100644 --- a/src/pip/_internal/operations/generate_metadata.py +++ b/src/pip/_internal/operations/generate_metadata.py @@ -12,7 +12,8 @@ from pip._internal.vcs import vcs if MYPY_CHECK_RUNNING: - from typing import Callable, List + from typing import Callable, List, Optional + from pip._internal.req.req_install import InstallRequirement logger = logging.getLogger(__name__) @@ -104,22 +105,26 @@ def _generate_metadata_legacy(install_req): if install_req.isolated: base_cmd += ["--no-user-cfg"] + base_cmd += ["egg_info"] + + egg_info_dir = None # type: Optional[str] # For non-editable installs, don't put the .egg-info files at the root, # to avoid confusion due to the source code being considered an installed # egg. - egg_base_option = [] # type: List[str] if not install_req.editable: egg_info_dir = os.path.join( install_req.unpacked_source_directory, 'pip-egg-info', ) - egg_base_option = ['--egg-base', egg_info_dir] # setuptools complains if the target directory does not exist. ensure_dir(egg_info_dir) + if egg_info_dir: + base_cmd += ['--egg-base', egg_info_dir] + with install_req.build_env: call_subprocess( - base_cmd + ["egg_info"] + egg_base_option, + base_cmd, cwd=install_req.unpacked_source_directory, command_desc='python setup.py egg_info', ) From f00d7a13749c96e8a18df5b59481a77fc0da55d9 Mon Sep 17 00:00:00 2001 From: Chris Hunt Date: Fri, 11 Oct 2019 20:40:52 -0400 Subject: [PATCH 07/11] Move egg_info args construction to setuptools_build --- .../_internal/operations/generate_metadata.py | 18 +++++++----------- src/pip/_internal/utils/setuptools_build.py | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/pip/_internal/operations/generate_metadata.py b/src/pip/_internal/operations/generate_metadata.py index f37d0c7da2d..bfdeae517a1 100644 --- a/src/pip/_internal/operations/generate_metadata.py +++ b/src/pip/_internal/operations/generate_metadata.py @@ -6,7 +6,7 @@ from pip._internal.exceptions import InstallationError from pip._internal.utils.misc import ensure_dir -from pip._internal.utils.setuptools_build import make_setuptools_shim_args +from pip._internal.utils.setuptools_build import make_setuptools_egg_info_args from pip._internal.utils.subprocess import call_subprocess from pip._internal.utils.typing import MYPY_CHECK_RUNNING from pip._internal.vcs import vcs @@ -100,13 +100,6 @@ def _generate_metadata_legacy(install_req): install_req.setup_py_path, req_details_str, ) - # Compose arguments for subprocess call - base_cmd = make_setuptools_shim_args(install_req.setup_py_path) - if install_req.isolated: - base_cmd += ["--no-user-cfg"] - - base_cmd += ["egg_info"] - egg_info_dir = None # type: Optional[str] # For non-editable installs, don't put the .egg-info files at the root, # to avoid confusion due to the source code being considered an installed @@ -119,12 +112,15 @@ def _generate_metadata_legacy(install_req): # setuptools complains if the target directory does not exist. ensure_dir(egg_info_dir) - if egg_info_dir: - base_cmd += ['--egg-base', egg_info_dir] + args = make_setuptools_egg_info_args( + install_req.setup_py_path, + egg_info_dir=egg_info_dir, + no_user_config=install_req.isolated, + ) with install_req.build_env: call_subprocess( - base_cmd, + args, cwd=install_req.unpacked_source_directory, command_desc='python setup.py egg_info', ) diff --git a/src/pip/_internal/utils/setuptools_build.py b/src/pip/_internal/utils/setuptools_build.py index 495a703e9a0..fc4f06c79e5 100644 --- a/src/pip/_internal/utils/setuptools_build.py +++ b/src/pip/_internal/utils/setuptools_build.py @@ -71,6 +71,24 @@ def make_setuptools_develop_args( return args +def make_setuptools_egg_info_args( + setup_py_path, # type: str + egg_info_dir, # type: Optional[str] + no_user_config, # type: bool +): + # type: (...) -> List[str] + base_cmd = make_setuptools_shim_args(setup_py_path) + if no_user_config: + base_cmd += ["--no-user-cfg"] + + base_cmd += ["egg_info"] + + if egg_info_dir: + base_cmd += ['--egg-base', egg_info_dir] + + return base_cmd + + def make_setuptools_install_args( setup_py_path, # type: str global_options, # type: Sequence[str] From 8af0dc2e02590895d359f45a6bbe83fee1012047 Mon Sep 17 00:00:00 2001 From: Chris Hunt Date: Fri, 11 Oct 2019 20:50:01 -0400 Subject: [PATCH 08/11] Normalize style --- src/pip/_internal/utils/setuptools_build.py | 52 ++++++++++----------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/src/pip/_internal/utils/setuptools_build.py b/src/pip/_internal/utils/setuptools_build.py index fc4f06c79e5..866d660a6f7 100644 --- a/src/pip/_internal/utils/setuptools_build.py +++ b/src/pip/_internal/utils/setuptools_build.py @@ -21,10 +21,10 @@ def make_setuptools_shim_args( - setup_py_path, # type: str - global_options=None, # type: Sequence[str] - no_user_config=False, # type: bool - unbuffered_output=False # type: bool + setup_py_path, # type: str + global_options=None, # type: Sequence[str] + no_user_config=False, # type: bool + unbuffered_output=False # type: bool ): # type: (...) -> List[str] """ @@ -38,12 +38,12 @@ def make_setuptools_shim_args( """ args = [sys.executable] if unbuffered_output: - args.append('-u') - args.extend(['-c', _SETUPTOOLS_SHIM.format(setup_py_path)]) + args += ["-u"] + args += ["-c", _SETUPTOOLS_SHIM.format(setup_py_path)] if global_options: - args.extend(global_options) + args += global_options if no_user_config: - args.append('--no-user-cfg') + args += ["--no-user-cfg"] return args @@ -61,12 +61,12 @@ def make_setuptools_develop_args( no_user_config=no_user_config, ) - args.extend(["develop", "--no-deps"]) + args += ["develop", "--no-deps"] - args.extend(install_options) + args += install_options if prefix: - args.extend(["--prefix", prefix]) + args += ["--prefix", prefix] return args @@ -77,16 +77,16 @@ def make_setuptools_egg_info_args( no_user_config, # type: bool ): # type: (...) -> List[str] - base_cmd = make_setuptools_shim_args(setup_py_path) + args = make_setuptools_shim_args(setup_py_path) if no_user_config: - base_cmd += ["--no-user-cfg"] + args += ["--no-user-cfg"] - base_cmd += ["egg_info"] + args += ["egg_info"] if egg_info_dir: - base_cmd += ['--egg-base', egg_info_dir] + args += ["--egg-base", egg_info_dir] - return base_cmd + return args def make_setuptools_install_args( @@ -101,28 +101,28 @@ def make_setuptools_install_args( pycompile # type: bool ): # type: (...) -> List[str] - install_args = make_setuptools_shim_args( + args = make_setuptools_shim_args( setup_py_path, global_options=global_options, no_user_config=no_user_config, unbuffered_output=True ) - install_args += ['install', '--record', record_filename] - install_args += ['--single-version-externally-managed'] + args += ["install", "--record", record_filename] + args += ["--single-version-externally-managed"] if root is not None: - install_args += ['--root', root] + args += ["--root", root] if prefix is not None: - install_args += ['--prefix', prefix] + args += ["--prefix", prefix] if pycompile: - install_args += ["--compile"] + args += ["--compile"] else: - install_args += ["--no-compile"] + args += ["--no-compile"] if header_dir: - install_args += ['--install-headers', header_dir] + args += ["--install-headers", header_dir] - install_args += install_options + args += install_options - return install_args + return args From c451bce2596ac6468d3ce5d1899cdeb0e4252cf7 Mon Sep 17 00:00:00 2001 From: Chris Hunt Date: Sat, 12 Oct 2019 21:00:38 -0400 Subject: [PATCH 09/11] Separate functions for constructing setuptools args To prepare for factoring these out into a separate module. --- src/pip/_internal/wheel.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/pip/_internal/wheel.py b/src/pip/_internal/wheel.py index 8f9778c7d29..029e486e223 100644 --- a/src/pip/_internal/wheel.py +++ b/src/pip/_internal/wheel.py @@ -957,7 +957,7 @@ def _build_one_inside_env(self, req, output_dir, python_tag=None): self._clean_one(req) return None - def _base_setup_args(self, req): + def _make_setuptools_bdist_wheel_args(self, req): # NOTE: Eventually, we'd want to also -S to the flags here, when we're # isolating. Currently, it breaks Python in virtualenvs, because it # relies on site.py to find parts of the standard library outside the @@ -968,6 +968,13 @@ def _base_setup_args(self, req): unbuffered_output=True ) + def _make_setuptools_clean_args(self, req): + return make_setuptools_shim_args( + req.setup_py_path, + global_options=self.global_options, + unbuffered_output=True + ) + def _build_one_pep517(self, req, tempd, python_tag=None): """Build one InstallRequirement using the PEP 517 build process. @@ -1012,16 +1019,15 @@ def _build_one_legacy(self, req, tempd, python_tag=None): Returns path to wheel if successfully built. Otherwise, returns None. """ - base_args = self._base_setup_args(req) + wheel_args = self._make_setuptools_bdist_wheel_args(req) + wheel_args += ['bdist_wheel', '-d', tempd] + wheel_args += self.build_options + if python_tag is not None: + wheel_args += ["--python-tag", python_tag] spin_message = 'Building wheel for %s (setup.py)' % (req.name,) with open_spinner(spin_message) as spinner: logger.debug('Destination directory: %s', tempd) - wheel_args = base_args + ['bdist_wheel', '-d', tempd] \ - + self.build_options - - if python_tag is not None: - wheel_args += ["--python-tag", python_tag] try: output = call_subprocess( @@ -1045,10 +1051,10 @@ def _build_one_legacy(self, req, tempd, python_tag=None): return wheel_path def _clean_one(self, req): - base_args = self._base_setup_args(req) + clean_args = self._make_setuptools_clean_args(req) + clean_args += ['clean', '--all'] logger.info('Running setup.py clean for %s', req.name) - clean_args = base_args + ['clean', '--all'] try: call_subprocess(clean_args, cwd=req.source_dir) return True From 3d931388dc4437e6e163db401f8d5cdfb93e2529 Mon Sep 17 00:00:00 2001 From: Chris Hunt Date: Sat, 12 Oct 2019 21:12:32 -0400 Subject: [PATCH 10/11] Parameterize bdist_wheel and clean args functions --- src/pip/_internal/wheel.py | 54 +++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/src/pip/_internal/wheel.py b/src/pip/_internal/wheel.py index 029e486e223..bd2b836f881 100644 --- a/src/pip/_internal/wheel.py +++ b/src/pip/_internal/wheel.py @@ -957,23 +957,43 @@ def _build_one_inside_env(self, req, output_dir, python_tag=None): self._clean_one(req) return None - def _make_setuptools_bdist_wheel_args(self, req): + def _make_setuptools_bdist_wheel_args( + self, + setup_py_path, # type: str + global_options, # type: Sequence[str] + build_options, # type: Sequence[str] + destination_dir, # type: str + python_tag, # type: Optional[str] + ): + # type: (...) -> List[str] # NOTE: Eventually, we'd want to also -S to the flags here, when we're # isolating. Currently, it breaks Python in virtualenvs, because it # relies on site.py to find parts of the standard library outside the # virtualenv. - return make_setuptools_shim_args( - req.setup_py_path, - global_options=self.global_options, + args = make_setuptools_shim_args( + setup_py_path, + global_options=global_options, unbuffered_output=True ) + args += ["bdist_wheel", "-d", destination_dir] + args += build_options + if python_tag is not None: + args += ["--python-tag", python_tag] + return args - def _make_setuptools_clean_args(self, req): - return make_setuptools_shim_args( - req.setup_py_path, - global_options=self.global_options, + def _make_setuptools_clean_args( + self, + setup_py_path, # type: str + global_options, # type: Sequence[str] + ): + # type: (...) -> List[str] + args = make_setuptools_shim_args( + setup_py_path, + global_options=global_options, unbuffered_output=True ) + args += ["clean", "--all"] + return args def _build_one_pep517(self, req, tempd, python_tag=None): """Build one InstallRequirement using the PEP 517 build process. @@ -1019,11 +1039,13 @@ def _build_one_legacy(self, req, tempd, python_tag=None): Returns path to wheel if successfully built. Otherwise, returns None. """ - wheel_args = self._make_setuptools_bdist_wheel_args(req) - wheel_args += ['bdist_wheel', '-d', tempd] - wheel_args += self.build_options - if python_tag is not None: - wheel_args += ["--python-tag", python_tag] + wheel_args = self._make_setuptools_bdist_wheel_args( + req.setup_py_path, + global_options=self.global_options, + build_options=self.build_options, + destination_dir=tempd, + python_tag=python_tag, + ) spin_message = 'Building wheel for %s (setup.py)' % (req.name,) with open_spinner(spin_message) as spinner: @@ -1051,8 +1073,10 @@ def _build_one_legacy(self, req, tempd, python_tag=None): return wheel_path def _clean_one(self, req): - clean_args = self._make_setuptools_clean_args(req) - clean_args += ['clean', '--all'] + clean_args = self._make_setuptools_clean_args( + req.setup_py_path, + global_options=self.global_options, + ) logger.info('Running setup.py clean for %s', req.name) try: From 66c3e6010d95bcabae8095a4176f4aa31bae2f3a Mon Sep 17 00:00:00 2001 From: Chris Hunt Date: Sat, 12 Oct 2019 21:20:10 -0400 Subject: [PATCH 11/11] Move arg builder functions to setuptools_build --- src/pip/_internal/utils/setuptools_build.py | 38 +++++++++++++++++ src/pip/_internal/wheel.py | 47 +++------------------ 2 files changed, 44 insertions(+), 41 deletions(-) diff --git a/src/pip/_internal/utils/setuptools_build.py b/src/pip/_internal/utils/setuptools_build.py index 866d660a6f7..1bf416eb34d 100644 --- a/src/pip/_internal/utils/setuptools_build.py +++ b/src/pip/_internal/utils/setuptools_build.py @@ -47,6 +47,44 @@ def make_setuptools_shim_args( return args +def make_setuptools_bdist_wheel_args( + setup_py_path, # type: str + global_options, # type: Sequence[str] + build_options, # type: Sequence[str] + destination_dir, # type: str + python_tag, # type: Optional[str] +): + # type: (...) -> List[str] + # NOTE: Eventually, we'd want to also -S to the flags here, when we're + # isolating. Currently, it breaks Python in virtualenvs, because it + # relies on site.py to find parts of the standard library outside the + # virtualenv. + args = make_setuptools_shim_args( + setup_py_path, + global_options=global_options, + unbuffered_output=True + ) + args += ["bdist_wheel", "-d", destination_dir] + args += build_options + if python_tag is not None: + args += ["--python-tag", python_tag] + return args + + +def make_setuptools_clean_args( + setup_py_path, # type: str + global_options, # type: Sequence[str] +): + # type: (...) -> List[str] + args = make_setuptools_shim_args( + setup_py_path, + global_options=global_options, + unbuffered_output=True + ) + args += ["clean", "--all"] + return args + + def make_setuptools_develop_args( setup_py_path, # type: str global_options, # type: Sequence[str] diff --git a/src/pip/_internal/wheel.py b/src/pip/_internal/wheel.py index bd2b836f881..d524701bdac 100644 --- a/src/pip/_internal/wheel.py +++ b/src/pip/_internal/wheel.py @@ -39,7 +39,10 @@ from pip._internal.utils.logging import indent_log from pip._internal.utils.marker_files import has_delete_marker_file from pip._internal.utils.misc import captured_stdout, ensure_dir, read_chunks -from pip._internal.utils.setuptools_build import make_setuptools_shim_args +from pip._internal.utils.setuptools_build import ( + make_setuptools_bdist_wheel_args, + make_setuptools_clean_args, +) from pip._internal.utils.subprocess import ( LOG_DIVIDER, call_subprocess, @@ -957,44 +960,6 @@ def _build_one_inside_env(self, req, output_dir, python_tag=None): self._clean_one(req) return None - def _make_setuptools_bdist_wheel_args( - self, - setup_py_path, # type: str - global_options, # type: Sequence[str] - build_options, # type: Sequence[str] - destination_dir, # type: str - python_tag, # type: Optional[str] - ): - # type: (...) -> List[str] - # NOTE: Eventually, we'd want to also -S to the flags here, when we're - # isolating. Currently, it breaks Python in virtualenvs, because it - # relies on site.py to find parts of the standard library outside the - # virtualenv. - args = make_setuptools_shim_args( - setup_py_path, - global_options=global_options, - unbuffered_output=True - ) - args += ["bdist_wheel", "-d", destination_dir] - args += build_options - if python_tag is not None: - args += ["--python-tag", python_tag] - return args - - def _make_setuptools_clean_args( - self, - setup_py_path, # type: str - global_options, # type: Sequence[str] - ): - # type: (...) -> List[str] - args = make_setuptools_shim_args( - setup_py_path, - global_options=global_options, - unbuffered_output=True - ) - args += ["clean", "--all"] - return args - def _build_one_pep517(self, req, tempd, python_tag=None): """Build one InstallRequirement using the PEP 517 build process. @@ -1039,7 +1004,7 @@ def _build_one_legacy(self, req, tempd, python_tag=None): Returns path to wheel if successfully built. Otherwise, returns None. """ - wheel_args = self._make_setuptools_bdist_wheel_args( + wheel_args = make_setuptools_bdist_wheel_args( req.setup_py_path, global_options=self.global_options, build_options=self.build_options, @@ -1073,7 +1038,7 @@ def _build_one_legacy(self, req, tempd, python_tag=None): return wheel_path def _clean_one(self, req): - clean_args = self._make_setuptools_clean_args( + clean_args = make_setuptools_clean_args( req.setup_py_path, global_options=self.global_options, )