-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ref: work around pip not having retries for streamed downloads (#60195)
pypa/pip#12383 (comment) this is a terrible hack -- essentially: - write a small `.pth` file to monkeypatch pip for any calls into the virtualenv site-packages - add a retrier to `Downloader.__call__` - instrument all of our virtualenv creation with it
- Loading branch information
1 parent
4a165ce
commit f4f9fa7
Showing
5 changed files
with
36 additions
and
5 deletions.
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
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
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,31 @@ | ||
from __future__ import annotations | ||
|
||
import os.path | ||
import sys | ||
import sysconfig | ||
|
||
PTH = """\ | ||
from pip._internal.network.download import Downloader | ||
from pip._vendor.tenacity import retry, stop_after_attempt | ||
Downloader.__call__ = retry( | ||
reraise=True, | ||
stop=stop_after_attempt(5), | ||
after=lambda state: print(f'!!! retry: attempt {state.attempt_number + 1} !!!') | ||
)(Downloader.__call__) | ||
""" | ||
|
||
|
||
def main() -> int: | ||
assert not sys.flags.no_site, sys.flags.no_site | ||
target = os.path.join(sysconfig.get_path("purelib"), "sentry-pip-hack.pth") | ||
assert "/.venv/" in target, target | ||
|
||
print("working around https://github.com/pypa/pip/issues/12383#issuecomment-1808598097") | ||
print(f"writing: {target}") | ||
with open(target, "w") as f: | ||
f.write(f"import sys;exec({PTH!r})\n") | ||
return 0 | ||
|
||
|
||
if __name__ == "__main__": | ||
raise SystemExit(main()) |