-
-
Notifications
You must be signed in to change notification settings - Fork 267
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
Add support for --extra-pip-requirement
.
#2461
Conversation
You can now inject extra requirements into the isolated Pip PEXes Pex uses to resolve distributions. The motivating use case for this is to use the feature Pip 23.1 introduced for forcing `--keyring-provider import`. Pex already supported using a combination of the following to force non-interactive use of the keyring: 1. A `keyring` script installation that was on the `PATH` 2. A `--pip-version` 23.1 or newer. 3. Specifying `--use-pip-config` to pass `--keyring-provider subprocess` to Pip. You could not force `--keyring-provider import` though since the Pips Pex uses are themselves hermetic PEXes without access to extra installed keyring requirements elsewhere on the system. With `--extra-pip-requirement` you can do this with the primary benefit over `--keyring-provider subprocess` being that you do not need to add the username to index URLs. This is ultimately because the keyring CLI requires username whereas the API does not; but see https://pip.pypa.io/en/stable/topics/authentication/#keyring-support for more information.
f003932
to
91b1ed6
Compare
@@ -119,61 +117,11 @@ def mitmdump_venv(shared_integration_test_tmpdir): | |||
|
|||
|
|||
@pytest.fixture | |||
def run_proxy( |
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 factored this out to testing/mitmproxy.py
to re-use mitmproxy in the new test in its reverse proxy mode to wrap PyPI / devpi with required auth.
if not resolver: | ||
raise ValueError( | ||
"A resolver is required to install extra {requirements} for vendored Pip: " | ||
"{extra_requirements}".format( | ||
requirements=pluralize(extra_requirements, "requirement"), | ||
extra_requirements=" ".join(map(str, extra_requirements)), | ||
) | ||
) | ||
|
||
# This indirection works around MyPy type inference failing to see that | ||
# `iter_distribution_locations` is only successfully defined when resolve is not None. | ||
extra_requirement_resolver = resolver | ||
|
||
def iter_distribution_locations(): | ||
# type: () -> Iterator[str] | ||
for location in expose_vendored(): | ||
yield location | ||
|
||
for resolved_distribution in extra_requirement_resolver.resolve_requirements( | ||
requirements=tuple(map(str, extra_requirements)), | ||
targets=Targets.from_target(LocalInterpreter.create(interpreter)), | ||
pip_version=PipVersion.VENDORED, | ||
extra_resolver_requirements=(), | ||
).distributions: | ||
yield resolved_distribution.distribution.location | ||
|
||
return _pip_installation( | ||
version=PipVersion.VENDORED, | ||
iter_distribution_locations=lambda: third_party.expose( | ||
("pip", "setuptools"), interpreter=interpreter | ||
), | ||
iter_distribution_locations=iter_distribution_locations, | ||
interpreter=interpreter, | ||
fingerprint=_fingerprint(extra_requirements), | ||
) |
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.
N.B.: The PR was motivated by Pip keyring but is more generic, allowing extra pip requirements for any reason under the sun that comes up. As such, even though keyring support does not work with vendored Pip, --extra-pip-requirement
should work with vendored Pip.
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!
You can now inject extra requirements into the isolated Pip PEXes Pex
uses to resolve distributions. The motivating use case for this is to
use the feature Pip 23.1 introduced for forcing
--keyring-provider import
.Pex already supported using a combination of the following to force
non-interactive use of the keyring:
keyring
script installation that was on thePATH
--pip-version
23.1 or newer.--use-pip-config
to pass--keyring-provider subprocess
to Pip.
You could not force
--keyring-provider import
though since the PipsPex uses are themselves hermetic PEXes without access to extra installed
keyring requirements elsewhere on the system. With
--extra-pip-requirement
you can do this with the primary benefit over--keyring-provider subprocess
being that you do not need to add theusername to index URLs. This is ultimately because the keyring CLI
requires username whereas the API does not; but see
https://pip.pypa.io/en/stable/topics/authentication/#keyring-support for
more information.