Skip to content

Commit

Permalink
Implement requirement installation for PEP 517 conform packages witho…
Browse files Browse the repository at this point in the history
…ut setup.py

The idea of this patch is that we build a wheel and install that whell when we install a requirement from
source that does not support setup.py.
Fixes pypa#6222.
  • Loading branch information
seppeljordan committed Jun 14, 2019
1 parent a240a98 commit 9b2c765
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
1 change: 1 addition & 0 deletions news/6222.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixes a bug that prevented installation of packages from source only if those packages depended on PEP 517 conform packages without a ``setup.py``
42 changes: 41 additions & 1 deletion src/pip/_internal/req/req_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from pip._internal.utils.misc import (
_make_build_dir, ask_path_exists, backup_dir, call_subprocess,
display_path, dist_in_site_packages, dist_in_usersite, ensure_dir,
get_installed_version, redact_password_from_url, rmtree,
get_installed_version, redact_password_from_url, rmtree, unpack_file,
)
from pip._internal.utils.packaging import get_metadata
from pip._internal.utils.setuptools_build import SETUPTOOLS_SHIM
Expand Down Expand Up @@ -922,6 +922,18 @@ def install(
self.install_succeeded = True
return

if self.use_pep517:
self.install_use_pep517(
warn_script_location=warn_script_location,
use_user_site=use_user_site,
pycompile=pycompile,
prefix=prefix,
root=root,
home=home,
)
self.install_succeed = True
return

# Extend the list of global and install options passed on to
# the setup.py call with the ones from the requirements file.
# Options specified in requirements file override those
Expand Down Expand Up @@ -993,6 +1005,34 @@ def prepend_root(path):
with open(inst_files_path, 'w') as f:
f.write('\n'.join(new_lines) + '\n')

def install_use_pep517(
self, warn_script_location, use_user_site, pycompile, prefix, root, home
):
with TempDirectory(kind='wheel') as wheel_dir, TempDirectory(kind='wheel') as build_dir:
wheel_name = self.build_wheel_use_pep517(build_dir.path)
unpack_file(
os.path.join(build_dir.path, wheel_name),
wheel_dir.path,
'application/zip',
None
)
version = wheel.wheel_version(wheel_dir.path)
wheel.check_compatibility(version, self.name)
self.move_wheel_files(
wheel_dir.path, root=root, prefix=prefix, home=home,
warn_script_location=warn_script_location,
use_user_site=use_user_site, pycompile=pycompile,
)
return

def build_wheel_use_pep517(self, output_directory):
self.spin_message = 'Building wheel for %s (PEP 517)' % (self.name,)
with self.build_env, indent_log():
return self.pep517_backend.build_wheel(
output_directory,
metadata_directory=self.metadata_directory,
)

def get_install_args(
self,
global_options, # type: Sequence[str]
Expand Down

0 comments on commit 9b2c765

Please sign in to comment.