Skip to content

Commit

Permalink
feat: make use of Python in init and new command
Browse files Browse the repository at this point in the history
  • Loading branch information
finswimmer committed Aug 24, 2024
1 parent 197a12e commit f1a44bc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
8 changes: 2 additions & 6 deletions src/poetry/console/commands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion tests/console/commands/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

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

Expand Down

0 comments on commit f1a44bc

Please sign in to comment.