Retry pypi.org requests on CI, or if an environment variable is set

Use PIPENV_MAX_RETRIES environment variable to determine how many times to retry
requests to pypi.org. Default to 0 retries, unless running on CI, in which case
default to 1 retry.
This commit is contained in:
Grey Baker
2018-05-05 19:12:52 +01:00
parent cbe15167c2
commit 1414243c01
2 changed files with 10 additions and 1 deletions
+3
View File
@@ -23,6 +23,9 @@ PIPENV_COLORBLIND = bool(os.environ.get('PIPENV_COLORBLIND'))
PIPENV_NOSPIN = bool(os.environ.get('PIPENV_NOSPIN'))
# Tells Pipenv how many rounds of resolving to do for Pip-Tools.
PIPENV_MAX_ROUNDS = int(os.environ.get('PIPENV_MAX_ROUNDS', '16'))
# Specify how many retries Pipenv should attempt for network requests.
default_retries = '1' if 'CI' in os.environ else '0'
PIPENV_MAX_RETRIES = int(os.environ.get('PIPENV_MAX_RETRIES', default_retries))
# Specify a custom Pipfile location.
PIPENV_PIPFILE = os.environ.get('PIPENV_PIPFILE')
# Tells Pipenv which Python to default to, when none is provided.
+7 -1
View File
@@ -45,7 +45,11 @@ except ImportError:
from distutils.spawn import find_executable
from contextlib import contextmanager
from .pep508checker import lookup
from .environments import PIPENV_MAX_ROUNDS, PIPENV_CACHE_DIR
from .environments import (
PIPENV_MAX_ROUNDS,
PIPENV_CACHE_DIR,
PIPENV_MAX_RETRIES
)
try:
from collections.abc import Mapping
@@ -72,6 +76,8 @@ def _get_requests_session():
return requests_session
import requests
requests_session = requests.Session()
adapter = requests.adapters.HTTPAdapter(max_retries=PIPENV_MAX_RETRIES)
requests_session.mount('https://pypi.org/pypi', adapter)
return requests_session