-
Notifications
You must be signed in to change notification settings - Fork 3k
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
improve handling of PEP 518 build requirements #5286
Conversation
a55fd21
to
fbbac93
Compare
There was a problem hiding this 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.
tests/functional/test_install.py
Outdated
if sys.version_info[:2] == (3, 3): | ||
# Ignore Python 3.3 deprecation warning... | ||
kwargs['expect_stderr'] = True | ||
script.run( |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll simplify this.
tests/functional/test_wheel.py
Outdated
@@ -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') |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, Okay. :)
src/pip/_internal/build_env.py
Outdated
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: NotImplementedError()
There was a problem hiding this comment.
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.
This comment was marked as resolved.
Sorry, something went wrong.
@@ -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', |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice idea. :)
ddd6193
to
d91b60d
Compare
There was a problem hiding this 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.
tests/functional/test_install.py
Outdated
kwargs['expect_stderr'] = True | ||
script.run( | ||
"python", "-c", | ||
"import pip._internal; pip._internal.main(['wheel', '-f', %r, %r])" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, Okay. :)
d91b60d
to
ec68159
Compare
I further tweaked some tests to avoid hitting PyPI, and simplify some of them to use |
tests/functional/test_install.py
Outdated
) | ||
raise ValueError(variant) | ||
kwargs = {'use_module': True} | ||
if sys.version_info[:2] == (3, 3): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed! Amended.
tests/functional/test_install.py
Outdated
|
||
def test_pep518_with_extra_and_markers(script, data, common_wheels): | ||
kwargs = {} | ||
if sys.version_info[:2] == (3, 3): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No longer needed.
ec68159
to
09d840d
Compare
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('_', '-'), |
Yeps. Sounds like a good idea. :) |
@pradyunsg: I believe I have addressed all your change requests. |
02dcb9f
to
93a98ee
Compare
Fixed stupid typo: in |
93a98ee
to
b794939
Compare
Rebased on master to fix mypy job. |
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. :) |
I've just had a couple of minutes to look at the docs, and your doc changes look good to me. |
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. |
Agreed. |
docs/reference/pip.rst
Outdated
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, amended and squashed.
c3e8470
to
2f295ad
Compare
I'm happy with this PR as it stands. If someone has any concerns with this, please speak up now. |
I've only done a high level review, but this looks good to me. |
2f295ad
to
9ee13ad
Compare
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 |
- 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.
9ee13ad
to
92e6e19
Compare
Thanks for the rebase @benoit-pierre! I'm merging this now. |
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. |
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
.