Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve handling of PEP 518 build requirements #5286

Merged

Conversation

benoit-pierre
Copy link
Member

@benoit-pierre benoit-pierre commented Apr 18, 2018

Fixes #5230
Fixes #5265

Offload more work to the underlying pip command used to install the build requirements, so there's no need to duplicate code to handle environment markers/extras. This is done by setting the correct options from the finder passed in argument to _install_build_reqs.

Copy link
Member

@pradyunsg pradyunsg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! ^>^

LGTM, barring a question regarding options passed and some test style-related stuff.

if sys.version_info[:2] == (3, 3):
# Ignore Python 3.3 deprecation warning...
kwargs['expect_stderr'] = True
script.run(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there some reason you're not using script.pip_install_local here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can pass -f data.find_links4 to that too and it'd simplify the loop.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll simplify this.

@@ -215,7 +215,7 @@ def test_pip_wheel_with_pep518_build_reqs(script, data):

@pytest.mark.network
def test_pip_wheel_with_pep518_build_reqs_no_isolation(script, data):
script.pip('install', 'wheel')
script.pip('install', '-f', data.find_links, 'wheel', 'simplewheel==2.0')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be split into 2 -- use of common_wheels to install wheel and pip_install_local for installing simplewheel.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

@@ -100,6 +100,10 @@ def packages2(self):
def packages3(self):
return self.root.join("packages3")

@property
def packages4(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels unnecessary -- why has a simple package been added under a new, different directory; am I missing something?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some tests expect the source distribution of simple to be used. Once PEP 518 support using source distributions for the build requirements package4 can be removed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, Okay. :)

@@ -90,3 +113,6 @@ def __exit__(self, exc_type, exc_val, exc_tb):

def cleanup(self):
pass

def install_requirements(self, finder, requirements, message):
raise NotImplementedError
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: NotImplementedError()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will amend.

@@ -100,6 +100,10 @@ def packages2(self):
def packages3(self):
return self.root.join("packages3")

@property
def packages4(self):

This comment was marked as resolved.

@@ -74,12 +72,37 @@ def restore_var(varname, old_value):
def cleanup(self):
self._temp_dir.cleanup()

def install_requirements(self, finder, requirements, message):
args = [
sys.executable, '-m', 'pip', 'install', '--ignore-installed',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for adding --ignore-installed here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This call is not run with build isolation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha.

Isolating this run would make pip not visible -> python -m pip won't work, and a temporary prefix for the installation of packages makes this non env-breaking.

@@ -127,7 +127,7 @@ def __init__(self, req, comes_from, source_dir=None, editable=False,
self.is_direct = False

self.isolated = isolated
self.build_env = BuildEnvironment(no_clean=True)
self.build_env = NoOpBuildEnvironment()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice idea. :)

@benoit-pierre benoit-pierre force-pushed the improve_pep518_build_requirements_handling branch 2 times, most recently from ddd6193 to d91b60d Compare April 19, 2018 21:50
Copy link
Member

@pradyunsg pradyunsg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, barring one nit.

kwargs['expect_stderr'] = True
script.run(
"python", "-c",
"import pip._internal; pip._internal.main(['wheel', '-f', %r, %r])"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've removed a test-run for "install" command here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, as noted in the commit message the goal of this test is to check the command to install build dependencies can be run successfully, there's really no need to check with both install and wheel commands.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. :)

@@ -100,6 +100,10 @@ def packages2(self):
def packages3(self):
return self.root.join("packages3")

@property
def packages4(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, Okay. :)

@benoit-pierre
Copy link
Member Author

I further tweaked some tests to avoid hitting PyPI, and simplify some of them to use script.pip(..., use_module=True).

)
raise ValueError(variant)
kwargs = {'use_module': True}
if sys.version_info[:2] == (3, 3):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This conditional is no longer needed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed! Amended.


def test_pep518_with_extra_and_markers(script, data, common_wheels):
kwargs = {}
if sys.version_info[:2] == (3, 3):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer needed.

@benoit-pierre
Copy link
Member Author

Should the verbose flag be forwarded to the command used to install build dependencies? IMHO this would make debugging easier:

diff --git a/src/pip/_internal/build_env.py b/src/pip/_internal/build_env.py
index 37f8ab80..13bbb687 100644
--- a/src/pip/_internal/build_env.py
+++ b/src/pip/_internal/build_env.py
@@ -1,6 +1,7 @@
 """Build Environment used for isolation during sdist building
 """
 
+import logging
 import os
 import sys
 from distutils.sysconfig import get_python_lib
@@ -11,6 +12,9 @@ from pip._internal.utils.temp_dir import TempDirectory
 from pip._internal.utils.ui import open_spinner
 
 
+logger = logging.getLogger(__name__)
+
+
 class BuildEnvironment(object):
     """Creates and manages an isolated environment to install build deps
     """
@@ -77,6 +81,8 @@ class BuildEnvironment(object):
             sys.executable, '-m', 'pip', 'install', '--ignore-installed',
             '--no-user', '--prefix', self.path, '--no-warn-script-location',
         ]
+        if logger.getEffectiveLevel() <= logging.DEBUG:
+            args.append('-v')
         for format_control in ('no_binary', 'only_binary'):
             formats = getattr(finder.format_control, format_control)
             args.extend(('--' + format_control.replace('_', '-'),

@pradyunsg
Copy link
Member

Yeps. Sounds like a good idea. :)

@benoit-pierre
Copy link
Member Author

@pradyunsg: I believe I have addressed all your change requests.

@benoit-pierre benoit-pierre force-pushed the improve_pep518_build_requirements_handling branch from 02dcb9f to 93a98ee Compare May 7, 2018 11:11
@benoit-pierre
Copy link
Member Author

Fixed stupid typo: in tests/data/src/pep518_with_extra_and_markers-1.0, renamed pep548_with_extra_and_markers.py to pep518_with_extra_and_markers.py.

@benoit-pierre benoit-pierre force-pushed the improve_pep518_build_requirements_handling branch from 93a98ee to b794939 Compare May 7, 2018 12:51
@benoit-pierre
Copy link
Member Author

Rebased on master to fix mypy job.

@pradyunsg pradyunsg added the type: enhancement Improvements to functionality label May 7, 2018
@pradyunsg pradyunsg requested a review from a team May 7, 2018 19:13
@pradyunsg
Copy link
Member

I'm happy with this PR as is. If someone else has the time to look at this, please do. I'll merge in a few days otherwise. :)

@pfmoore
Copy link
Member

pfmoore commented May 11, 2018

I've just had a couple of minutes to look at the docs, and your doc changes look good to me.

@benoit-pierre
Copy link
Member Author

On the subject of documentation: I think the "future development" section should be dropped or changed: it mentions PEP 426, and build hooks, but this PEP has been withdrawn and this is part is superseded by PEP 517.

@pfmoore
Copy link
Member

pfmoore commented May 11, 2018

Agreed.

installation of build dependencies from source has been disabled until a safe
resolution of this issue is found.

* ``pip<18.7`` does not support the use of environment markers and extras, only
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be 18.0

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, amended and squashed.

@benoit-pierre benoit-pierre force-pushed the improve_pep518_build_requirements_handling branch from c3e8470 to 2f295ad Compare May 11, 2018 21:25
@pradyunsg
Copy link
Member

I'm happy with this PR as it stands. If someone has any concerns with this, please speak up now.

@pfmoore
Copy link
Member

pfmoore commented May 12, 2018

I've only done a high level review, but this looks good to me.

@benoit-pierre benoit-pierre force-pushed the improve_pep518_build_requirements_handling branch from 2f295ad to 9ee13ad Compare May 12, 2018 18:57
@BrownTruck
Copy link
Contributor

Hello!

I am an automated bot and I have noticed that this pull request is not currently able to be merged. If you are able to either merge the master branch into this pull request or rebase this pull request against master then it will eligible for code review and hopefully merging!

@BrownTruck BrownTruck added the needs rebase or merge PR has conflicts with current master label May 18, 2018
- change module name to prevent conflicts with other distributions
- add a `__version__` field for version checks
- avoid hitting the index: use `common_wheels`/`script.pip_install_local`
- use `script.pip(..., use_module=True)` to simplify some tests
- improve `test_pep518_uses_build_env` parametrization
- simplify `test_pep518_with_user_pip`: we only need to check build
  requirements can be installed, so no need for testing with both
  `install` and `wheel` command
- fix `test_pip_wheel_with_pep518_build_reqs_no_isolation`: building
  pep518-3.0 without isolation should fail if the build requirements
  are not installed.
Offload more work to the underlying pip command used to install the
build requirements, so there's no need to duplicate code to handle
environment markers/extras. This is done by setting the correct options
from the finder passed in argument to `_install_build_reqs`.
- remove unused `BuildEnvironment` parameter: `no_clean`
- move helper to install build requirement to the `BuildEnvironment` class
- simplify a little the 2 different code paths (with and without build isolation)
Suppress warnings about out-of-PATH script installs.
@benoit-pierre benoit-pierre force-pushed the improve_pep518_build_requirements_handling branch from 9ee13ad to 92e6e19 Compare May 18, 2018 21:47
@pypa-bot pypa-bot removed the needs rebase or merge PR has conflicts with current master label May 18, 2018
@pradyunsg
Copy link
Member

Thanks for the rebase @benoit-pierre! I'm merging this now.

@pradyunsg pradyunsg merged commit 6fdcf23 into pypa:master May 19, 2018
@pradyunsg pradyunsg added the PEP implementation Involves some PEP label May 19, 2018
@benoit-pierre benoit-pierre deleted the improve_pep518_build_requirements_handling branch May 30, 2018 17:18
@lock
Copy link

lock bot commented Jun 2, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot added the auto-locked Outdated issues that have been locked by automation label Jun 2, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jun 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
auto-locked Outdated issues that have been locked by automation PEP implementation Involves some PEP type: enhancement Improvements to functionality
Projects
None yet
5 participants