hack_pip.py 863 B

12345678910111213141516171819202122232425262728293031
  1. from __future__ import annotations
  2. import os.path
  3. import sys
  4. import sysconfig
  5. PTH = """\
  6. from pip._internal.network.download import Downloader
  7. from pip._vendor.tenacity import retry, stop_after_attempt
  8. Downloader.__call__ = retry(
  9. reraise=True,
  10. stop=stop_after_attempt(5),
  11. after=lambda state: print(f'!!! retry: attempt {state.attempt_number + 1} !!!')
  12. )(Downloader.__call__)
  13. """
  14. def main() -> int:
  15. assert not sys.flags.no_site, sys.flags.no_site
  16. target = os.path.join(sysconfig.get_path("purelib"), "sentry-pip-hack.pth")
  17. assert "/.venv/" in target, target
  18. print("working around https://github.com/pypa/pip/issues/12383#issuecomment-1808598097")
  19. print(f"writing: {target}")
  20. with open(target, "w") as f:
  21. f.write(f"import sys;exec({PTH!r})\n")
  22. return 0
  23. if __name__ == "__main__":
  24. raise SystemExit(main())