From 2447ac12ed3409a165d9f22da8884307c69ffbe1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Randy=20D=C3=B6ring?= <30527984+radoering@users.noreply.github.com> Date: Mon, 13 Nov 2023 16:47:24 +0100 Subject: [PATCH] fix `poetry init` (#8655) (cherry picked from commit 3900d81933dfba2cf4e2d072ef7fd95c8b6190a0) --- src/poetry/console/commands/init.py | 3 ++- tests/console/commands/test_init.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/poetry/console/commands/init.py b/src/poetry/console/commands/init.py index cf59517b3a6..658b7a4a504 100644 --- a/src/poetry/console/commands/init.py +++ b/src/poetry/console/commands/init.py @@ -481,6 +481,7 @@ def _validate_package(package: str | None) -> str | None: return package def _get_pool(self) -> RepositoryPool: + from poetry.config.config import Config from poetry.repositories import RepositoryPool from poetry.repositories.pypi_repository import PyPiRepository @@ -489,7 +490,7 @@ def _get_pool(self) -> RepositoryPool: if self._pool is None: self._pool = RepositoryPool() - pool_size = self.poetry.config.installer_max_workers + pool_size = Config.create().installer_max_workers self._pool.add_repository(PyPiRepository(pool_size=pool_size)) return self._pool diff --git a/tests/console/commands/test_init.py b/tests/console/commands/test_init.py index 2a0a9bcaa25..44e472fbd70 100644 --- a/tests/console/commands/test_init.py +++ b/tests/console/commands/test_init.py @@ -1087,3 +1087,17 @@ def mock_check_output(cmd: str, *_: Any, **__: Any) -> str: """ assert expected in pyproject_file.read_text() + + +def test_get_pool(mocker: MockerFixture, source_dir: Path) -> None: + """ + Since we are mocking _get_pool() in the other tests, we at least should make + sure it works in general. See https://github.com/python-poetry/poetry/issues/8634. + """ + mocker.patch("pathlib.Path.cwd", return_value=source_dir) + + app = Application() + command = app.find("init") + assert isinstance(command, InitCommand) + pool = command._get_pool() + assert pool.repositories