Skip to content

Commit

Permalink
feat: take virtualenvs.prefer-active-python into account on `poetry…
Browse files Browse the repository at this point in the history
… init`
  • Loading branch information
finswimmer committed Nov 26, 2022
1 parent b712f3c commit 9e5c59e
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/poetry/console/commands/init.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from __future__ import annotations

import sys

from pathlib import Path
from typing import TYPE_CHECKING
from typing import Any
Expand Down Expand Up @@ -74,8 +72,9 @@ def handle(self) -> int:
from poetry.core.pyproject.toml import PyProjectTOML
from poetry.core.vcs.git import GitConfig

from poetry.config.config import Config
from poetry.layouts import layout
from poetry.utils.env import SystemEnv
from poetry.utils.env import EnvManager

project_path = Path.cwd()

Expand Down Expand Up @@ -157,10 +156,15 @@ def handle(self) -> int:

python = self.option("python")
if not python:
current_env = SystemEnv(Path(sys.executable))
config = Config.create()
default_python = "^" + ".".join(
str(v) for v in current_env.version_info[:2]
str(v)
for v in EnvManager.get_python_version(
prefer_active_python=config.get("virtualenvs.prefer-active-python"),
io=self.io,
)[:2]
)

question = self.create_question(
f"Compatible Python versions [<comment>{default_python}</comment>]: ",
default=default_python,
Expand Down

0 comments on commit 9e5c59e

Please sign in to comment.