Merge pull request #5907 from birdhackor/dev/add_env

Add PIPENV_REQUESTS_TIMEOUT and use it for requests session.
This commit is contained in:
Matt Davis
2023-09-05 19:49:46 -04:00
committed by GitHub
3 changed files with 27 additions and 3 deletions
+11
View File
@@ -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).
+11
View File
@@ -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.
+5 -3
View File
@@ -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,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=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