diff --git a/docs/configuration.md b/docs/configuration.md index 889957d07f3..ebbd085d149 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -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* diff --git a/src/poetry/config/config.py b/src/poetry/config/config.py index c10a0f8841f..f2a8129f231 100644 --- a/src/poetry/config/config.py +++ b/src/poetry/config/config.py @@ -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, }, @@ -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 diff --git a/src/poetry/console/commands/config.py b/src/poetry/console/commands/config.py index 8c41cc4cb2b..25fec8ce72f 100644 --- a/src/poetry/console/commands/config.py +++ b/src/poetry/console/commands/config.py @@ -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, diff --git a/src/poetry/installation/executor.py b/src/poetry/installation/executor.py index b95a45ce704..196cdd5acfd 100644 --- a/src/poetry/installation/executor.py +++ b/src/poetry/installation/executor.py @@ -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: diff --git a/src/poetry/packages/direct_origin.py b/src/poetry/packages/direct_origin.py index 78bae1ee764..561b7a4223e 100644 --- a/src/poetry/packages/direct_origin.py +++ b/src/poetry/packages/direct_origin.py @@ -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 @@ -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 @@ -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) diff --git a/src/poetry/repositories/http_repository.py b/src/poetry/repositories/http_repository.py index 54c7f0da1e9..7d0249b897d 100644 --- a/src/poetry/repositories/http_repository.py +++ b/src/poetry/repositories/http_repository.py @@ -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 @@ -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 diff --git a/tests/config/test_config.py b/tests/config/test_config.py index 9f5ef0c7bc6..8afcd0e6596 100644 --- a/tests/config/test_config.py +++ b/tests/config/test_config.py @@ -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: diff --git a/tests/console/commands/test_config.py b/tests/console/commands/test_config.py index cd62c572e7d..ec88be4510d 100644 --- a/tests/console/commands/test_config.py +++ b/tests/console/commands/test_config.py @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/tests/repositories/test_http_repository.py b/tests/repositories/test_http_repository.py index 6d7fd667b02..64a5ba6b176 100644 --- a/tests/repositories/test_http_repository.py +++ b/tests/repositories/test_http_repository.py @@ -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