From e1c00e0bea99c1e40afeac362a871dbc2693d6ee Mon Sep 17 00:00:00 2001 From: birdhackor Date: Sat, 2 Sep 2023 11:04:51 +0800 Subject: [PATCH 1/4] Add PIPENV_REQUESTS_TIMEOUT environment variable --- pipenv/environments.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pipenv/environments.py b/pipenv/environments.py index 325b63ac..8add6f86 100644 --- a/pipenv/environments.py +++ b/pipenv/environments.py @@ -289,6 +289,17 @@ class Setting: Default is 120 seconds, an arbitrary number that seems to work. """ + self.PIPENV_REQUESTS_TIMEOUT = int( + get_from_env("REQUESTS_TIMEOUT", check_for_negation=False, default=10) + ) + """Timeout setting for requests. + + Default is 10 seconds. + + For more information on the role of Timeout in Requests, see + [Requests docs](https://requests.readthedocs.io/en/latest/user/advanced/#timeouts). + """ + self.PIPENV_VENV_IN_PROJECT = get_from_env("VENV_IN_PROJECT") """ When set True, will create or use the ``.venv`` in your project directory. When Set False, will ignore the .venv in your project directory even if it exists. From 4dc5980927ce0cd0b1796d90ab927161093cc854 Mon Sep 17 00:00:00 2001 From: birdhackor Date: Sat, 2 Sep 2023 11:12:17 +0800 Subject: [PATCH 2/4] Use PIPENV_REQUESTS_TIMEOUT for timeout setting when use requests. --- pipenv/project.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pipenv/project.py b/pipenv/project.py index 7a8978f0..3ac7b123 100644 --- a/pipenv/project.py +++ b/pipenv/project.py @@ -270,7 +270,7 @@ class Project: try: collected_hashes = set() # Grab the hashes from the new warehouse API. - r = session.get(pkg_url, timeout=10) + r = session.get(pkg_url, timeout=self.s.PIPENV_REQUESTS_TIMEOUT) api_releases = r.json()["releases"] cleaned_releases = {} for api_version, api_info in api_releases.items(): @@ -299,7 +299,7 @@ class Project: try: collected_hashes = set() - response = session.get(pkg_url, timeout=10) + response = session.get(pkg_url, timeout=self.s.PIPENV_REQUESTS_TIMEOUT) parser = PackageIndexHTMLParser() parser.feed(response.text) hrefs = parser.urls @@ -316,7 +316,7 @@ class Project: if version in parsed_url.path and parsed_url.path.endswith("/"): # This might be a version-specific page. Fetch and parse it version_url = urljoin(pkg_url, package_url) - version_response = session.get(version_url, timeout=10) + version_response = session.get(version_url, timeout=self.s.PIPENV_REQUESTS_TIMEOUT) version_parser = PackageIndexHTMLParser() version_parser.feed(version_response.text) version_hrefs = version_parser.urls From 5882e8d0d878173355f27aeaaa5bf5007888472a Mon Sep 17 00:00:00 2001 From: birdhackor Date: Sat, 2 Sep 2023 12:20:22 +0800 Subject: [PATCH 3/4] Add corresponding documentation for PIPENV_REQUESTS_TIMEOUT --- docs/configuration.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/configuration.md b/docs/configuration.md index 0d44c8ad..bc42d243 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -32,3 +32,14 @@ This is useful in the same situations that you would change `PIP_CACHE_DIR` to a By default, pipenv will initialize a project using whatever version of python the system has as default. Besides starting a project with the `--python` flag, you can also use `PIPENV_DEFAULT_PYTHON_VERSION` to specify what version to use when starting a project when `--python` isn't used. + +## Environments with network issues + +If you are trying to use pipenv in an environment with network issues, you may be able to try modifying +the following settings when you encounter errors related to network connectivity. + +### REQUESTS_TIMEOUT + +Default is 10 seconds. You can increase it by setting `PIPENV_REQUESTS_TIMEOUT` environment variable. + +Please notice that this setting only affects pipenv itself, not additional packages such as [safety](advanced.rst). From 1a6d0e76b4a631e8ecc6db41845205fc7cb5974d Mon Sep 17 00:00:00 2001 From: birdhackor Date: Sat, 2 Sep 2023 18:28:51 +0800 Subject: [PATCH 4/4] Format. Fix CI lint issue. --- pipenv/project.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pipenv/project.py b/pipenv/project.py index 3ac7b123..e13a6747 100644 --- a/pipenv/project.py +++ b/pipenv/project.py @@ -316,7 +316,9 @@ class Project: if version in parsed_url.path and parsed_url.path.endswith("/"): # This might be a version-specific page. Fetch and parse it version_url = urljoin(pkg_url, package_url) - version_response = session.get(version_url, timeout=self.s.PIPENV_REQUESTS_TIMEOUT) + version_response = session.get( + version_url, timeout=self.s.PIPENV_REQUESTS_TIMEOUT + ) version_parser = PackageIndexHTMLParser() version_parser.feed(version_response.text) version_hrefs = version_parser.urls