From dc6328c4fe116e6b5b2e03651a87bc9ee72281f7 Mon Sep 17 00:00:00 2001 From: finswimmer Date: Sun, 3 Mar 2024 18:31:42 +0100 Subject: [PATCH] feat: make use of Python in init and new command --- src/poetry/console/commands/init.py | 8 ++------ tests/console/commands/test_init.py | 5 ++++- tests/console/commands/test_new.py | 4 ++++ 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/poetry/console/commands/init.py b/src/poetry/console/commands/init.py index 6725008daaf..bab51fe77a9 100644 --- a/src/poetry/console/commands/init.py +++ b/src/poetry/console/commands/init.py @@ -16,6 +16,7 @@ from poetry.console.commands.command import Command from poetry.console.commands.env_command import EnvCommand from poetry.utils.dependency_specification import RequirementsParser +from poetry.utils.env.python_manager import Python if TYPE_CHECKING: @@ -96,7 +97,6 @@ def _init_pyproject( from poetry.config.config import Config from poetry.layouts import layout from poetry.pyproject.toml import PyProjectTOML - from poetry.utils.env import EnvManager is_interactive = self.io.is_interactive() and allow_interactive @@ -174,11 +174,7 @@ def _init_pyproject( config = Config.create() python = ( ">=" - + EnvManager.get_python_version( - precision=2, - prefer_active_python=config.get("virtualenvs.prefer-active-python"), - io=self.io, - ).to_string() + + Python.get_preferred_python(config, self.io).minor_version.to_string() ) if is_interactive: diff --git a/tests/console/commands/test_init.py b/tests/console/commands/test_init.py index 80aee46e048..42219086048 100644 --- a/tests/console/commands/test_init.py +++ b/tests/console/commands/test_init.py @@ -1059,7 +1059,10 @@ def mock_check_output(cmd: str, *_: Any, **__: Any) -> str: return result mocker.patch("subprocess.check_output", side_effect=mock_check_output) - + mocker.patch( + "poetry.utils.env.python_manager.Python._full_python_path", + return_value=Path(f"/usr/bin/python{python}"), + ) config.config["virtualenvs"]["prefer-active-python"] = prefer_active pyproject_file = source_dir / "pyproject.toml" diff --git a/tests/console/commands/test_new.py b/tests/console/commands/test_new.py index dba738f4e8c..adfaa36237b 100644 --- a/tests/console/commands/test_new.py +++ b/tests/console/commands/test_new.py @@ -213,6 +213,10 @@ def mock_check_output(cmd: str, *_: Any, **__: Any) -> str: return output mocker.patch("subprocess.check_output", side_effect=mock_check_output) + mocker.patch( + "poetry.utils.env.python_manager.Python._full_python_path", + return_value=Path(f"/usr/bin/python{python}"), + ) config.config["virtualenvs"]["prefer-active-python"] = prefer_active