Skip to content

Commit

Permalink
change config to requests.max-retries
Browse files Browse the repository at this point in the history
  • Loading branch information
austinzh authored and radoering committed Aug 17, 2024
1 parent 8b1df4b commit f8db472
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 16 deletions.
4 changes: 2 additions & 2 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,13 +273,13 @@ values, usage instructions and warnings.

Use parallel execution when using the new (`>=1.1.0`) installer.

### `installer.max-retries`
### `requests.max-retries`

**Type**: `int`

**Default**: `0`

**Environment Variable**: `POETRY_INSTALLER_MAX_RETRIES`
**Environment Variable**: `POETRY_REQUESTS_MAX_RETRIES`

*Introduced in 1.9.0*

Expand Down
6 changes: 4 additions & 2 deletions src/poetry/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,12 @@ class Config:
"experimental": {
"system-git-client": False,
},
"requests": {
"max-retries": 0,
},
"installer": {
"parallel": True,
"max-workers": None,
"max-retries": 0,
"no-binary": None,
"only-binary": None,
},
Expand Down Expand Up @@ -319,7 +321,7 @@ def _get_normalizer(name: str) -> Callable[[str], Any]:

if name in {
"installer.max-workers",
"installer.max-retries",
"requests.max-retries",
}:
return int_normalizer

Expand Down
2 changes: 1 addition & 1 deletion src/poetry/console/commands/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ def unique_config_values(self) -> dict[str, tuple[Any, Any]]:
"virtualenvs.prefer-active-python": (boolean_validator, boolean_normalizer),
"virtualenvs.prompt": (str, str),
"experimental.system-git-client": (boolean_validator, boolean_normalizer),
"requests.max-retries": (lambda val: int(val) >= 0, int_normalizer),
"installer.parallel": (boolean_validator, boolean_normalizer),
"installer.max-workers": (lambda val: int(val) > 0, int_normalizer),
"installer.max-retries": (lambda val: int(val) >= 0, int_normalizer),
"installer.no-binary": (
PackageFilterPolicy.validator,
PackageFilterPolicy.normalize,
Expand Down
2 changes: 1 addition & 1 deletion src/poetry/installation/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def __init__(
# Cache whether decorated output is supported.
# https://github.com/python-poetry/cleo/issues/423
self._decorated_output: bool = self._io.output.is_decorated()
self._max_retries = config.get("installer.max-retries", 0)
self._max_retries = config.get("requests.max-retries", 0)

@property
def installations_count(self) -> int:
Expand Down
7 changes: 6 additions & 1 deletion src/poetry/packages/direct_origin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from poetry.core.packages.utils.link import Link

from poetry.config.config import Config
from poetry.inspection.info import PackageInfo
from poetry.inspection.info import PackageInfoError
from poetry.utils.authenticator import get_default_authenticator
Expand Down Expand Up @@ -57,6 +58,8 @@ def _get_package_from_git(
class DirectOrigin:
def __init__(self, artifact_cache: ArtifactCache) -> None:
self._artifact_cache = artifact_cache
config = Config.create()
self._max_retries = config.get("requests.max-retries", 0)
self._authenticator = get_default_authenticator()

@classmethod
Expand All @@ -77,7 +80,9 @@ def get_package_from_directory(cls, directory: Path) -> Package:
return PackageInfo.from_directory(path=directory).to_package(root_dir=directory)

def _download_file(self, url: str, dest: Path) -> None:
download_file(url, dest, session=self._authenticator)
download_file(
url, dest, session=self._authenticator, max_retries=self._max_retries
)

def get_package_from_url(self, url: str) -> Package:
link = Link(url)
Expand Down
7 changes: 6 additions & 1 deletion src/poetry/repositories/http_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def __init__(
self.get_page = functools.lru_cache(maxsize=None)(self._get_page)

self._lazy_wheel = config.get("solver.lazy-wheel", True)
self._max_retries = config.get("requests.max-retries", 0)
# We are tracking if a domain supports range requests or not to avoid
# unnecessary requests.
# ATTENTION: A domain might support range requests only for some files, so the
Expand Down Expand Up @@ -95,7 +96,11 @@ def _download(
self, url: str, dest: Path, *, raise_accepts_ranges: bool = False
) -> None:
return download_file(
url, dest, session=self.session, raise_accepts_ranges=raise_accepts_ranges
url,
dest,
session=self.session,
raise_accepts_ranges=raise_accepts_ranges,
max_retries=self._max_retries,
)

@contextmanager
Expand Down
2 changes: 1 addition & 1 deletion tests/config/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def get_options_based_on_normalizer(normalizer: Normalizer) -> Iterator[str]:
[
("installer.parallel", True),
("virtualenvs.create", True),
("installer.max-retries", 0),
("requests.max-retries", 0),
],
)
def test_config_get_default_value(config: Config, name: str, value: bool) -> None:
Expand Down
12 changes: 6 additions & 6 deletions tests/console/commands/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ def test_list_displays_default_value_if_not_set(
venv_path = json.dumps(os.path.join("{cache-dir}", "virtualenvs"))
expected = f"""cache-dir = {cache_dir}
experimental.system-git-client = false
installer.max-retries = 0
installer.max-workers = null
installer.no-binary = null
installer.only-binary = null
installer.parallel = true
keyring.enabled = true
requests.max-retries = 0
solver.lazy-wheel = true
virtualenvs.create = true
virtualenvs.in-project = null
Expand Down Expand Up @@ -88,12 +88,12 @@ def test_list_displays_set_get_setting(
venv_path = json.dumps(os.path.join("{cache-dir}", "virtualenvs"))
expected = f"""cache-dir = {cache_dir}
experimental.system-git-client = false
installer.max-retries = 0
installer.max-workers = null
installer.no-binary = null
installer.only-binary = null
installer.parallel = true
keyring.enabled = true
requests.max-retries = 0
solver.lazy-wheel = true
virtualenvs.create = false
virtualenvs.in-project = null
Expand Down Expand Up @@ -142,12 +142,12 @@ def test_unset_setting(
venv_path = json.dumps(os.path.join("{cache-dir}", "virtualenvs"))
expected = f"""cache-dir = {cache_dir}
experimental.system-git-client = false
installer.max-retries = 0
installer.max-workers = null
installer.no-binary = null
installer.only-binary = null
installer.parallel = true
keyring.enabled = true
requests.max-retries = 0
solver.lazy-wheel = true
virtualenvs.create = true
virtualenvs.in-project = null
Expand All @@ -174,12 +174,12 @@ def test_unset_repo_setting(
venv_path = json.dumps(os.path.join("{cache-dir}", "virtualenvs"))
expected = f"""cache-dir = {cache_dir}
experimental.system-git-client = false
installer.max-retries = 0
installer.max-workers = null
installer.no-binary = null
installer.only-binary = null
installer.parallel = true
keyring.enabled = true
requests.max-retries = 0
solver.lazy-wheel = true
virtualenvs.create = true
virtualenvs.in-project = null
Expand Down Expand Up @@ -304,12 +304,12 @@ def test_list_displays_set_get_local_setting(
venv_path = json.dumps(os.path.join("{cache-dir}", "virtualenvs"))
expected = f"""cache-dir = {cache_dir}
experimental.system-git-client = false
installer.max-retries = 0
installer.max-workers = null
installer.no-binary = null
installer.only-binary = null
installer.parallel = true
keyring.enabled = true
requests.max-retries = 0
solver.lazy-wheel = true
virtualenvs.create = false
virtualenvs.in-project = null
Expand Down Expand Up @@ -344,13 +344,13 @@ def test_list_must_not_display_sources_from_pyproject_toml(
venv_path = json.dumps(os.path.join("{cache-dir}", "virtualenvs"))
expected = f"""cache-dir = {cache_dir}
experimental.system-git-client = false
installer.max-retries = 0
installer.max-workers = null
installer.no-binary = null
installer.only-binary = null
installer.parallel = true
keyring.enabled = true
repositories.foo.url = "https://foo.bar/simple/"
requests.max-retries = 0
solver.lazy-wheel = true
virtualenvs.create = true
virtualenvs.in-project = null
Expand Down
6 changes: 5 additions & 1 deletion tests/repositories/test_http_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ def test_get_info_from_wheel(
else:
mock_metadata_from_wheel_url.assert_not_called()
mock_download.assert_called_once_with(
url, mocker.ANY, session=repo.session, raise_accepts_ranges=lazy_wheel
url,
mocker.ANY,
session=repo.session,
raise_accepts_ranges=lazy_wheel,
max_retries=0,
)
if lazy_wheel:
assert repo._supports_range_requests[domain] is False
Expand Down

0 comments on commit f8db472

Please sign in to comment.