Skip to content

Commit

Permalink
fix poetry init
Browse files Browse the repository at this point in the history
We can't access `self.poetry.config` when poetry has not been initialized yet.
  • Loading branch information
radoering committed Nov 12, 2023
1 parent 2b50120 commit 54f74be
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/poetry/console/commands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
14 changes: 14 additions & 0 deletions tests/console/commands/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 54f74be

Please sign in to comment.