-
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
Run pip in isolated env by building zip #9689
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4ec34b9
Run pip in isolated env by building zip
uranusjr 638b562
Pass parent certificate location to isolated pip
uranusjr e8e5153
Better name temp directory
uranusjr 7067359
Less diff
uranusjr 4bf083c
Monkey-patch .pem path into standalone pip instead
uranusjr 0d183d3
Better docstring
uranusjr 40d0529
Patch __init__.py instead of __main__.py
uranusjr 2eb7e88
Patch certifi to use environ for passing cert
uranusjr 9cab77e
Pass in cert path with private environ
uranusjr bba1226
Handle zipapp inception
uranusjr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Prevent packages already-installed alongside with pip to be injected into an | ||
isolated build environment during build-time dependency population. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,41 @@ | ||
diff --git a/src/pip/_vendor/certifi/core.py b/src/pip/_vendor/certifi/core.py | ||
index 5d2b8cd32..8987449f6 100644 | ||
index 5d2b8cd32..b8140cf1a 100644 | ||
--- a/src/pip/_vendor/certifi/core.py | ||
+++ b/src/pip/_vendor/certifi/core.py | ||
@@ -33,7 +33,7 @@ try: | ||
@@ -8,7 +8,21 @@ This module returns the installation location of cacert.pem or its contents. | ||
""" | ||
import os | ||
|
||
+ | ||
+class _PipPatchedCertificate(Exception): | ||
+ pass | ||
+ | ||
+ | ||
try: | ||
+ # Return a certificate file on disk for a standalone pip zipapp running in | ||
+ # an isolated build environment to use. Passing --cert to the standalone | ||
+ # pip does not work since requests calls where() unconditionally on import. | ||
+ _PIP_STANDALONE_CERT = os.environ.get("_PIP_STANDALONE_CERT") | ||
+ if _PIP_STANDALONE_CERT: | ||
+ def where(): | ||
+ return _PIP_STANDALONE_CERT | ||
+ raise _PipPatchedCertificate() | ||
+ | ||
from importlib.resources import path as get_path, read_text | ||
|
||
_CACERT_CTX = None | ||
@@ -33,11 +47,13 @@ try: | ||
# We also have to hold onto the actual context manager, because | ||
# it will do the cleanup whenever it gets garbage collected, so | ||
# we will also store that at the global level as well. | ||
- _CACERT_CTX = get_path("certifi", "cacert.pem") | ||
+ _CACERT_CTX = get_path("pip._vendor.certifi", "cacert.pem") | ||
_CACERT_PATH = str(_CACERT_CTX.__enter__()) | ||
|
||
return _CACERT_PATH | ||
|
||
+except _PipPatchedCertificate: | ||
+ pass | ||
|
||
except ImportError: | ||
# This fallback will work for Python versions prior to 3.7 that lack the |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 works, and I'm not suggesting that you try updating this PR, but I do wonder: can we use the --cert option that we have on the CLI to achieve this?
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 works in practice, but some tests will fail because
requests
always triggers temp file creation even when the default cert is never used. The environ + certifi patch solution is the only way I can think of to prevent that temp file from being created entirely.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.
From #9689 (comment) in this thread
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'm assuming that there's a reason we can't just mark these as "expected temp files" in the test suite, or a reason why the temp files are bad in real usage - and we're not introducing a complicated hack just to cover over a test issue?
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.
There are tests on temp files being correctly cleaned up after build, and allowing temp files would defeat their purpose. Another way to do this is to ensure the copied cert file is also cleaned up by the PEP 517 process, but that would require even more patching in certifi.