Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
python-poetry
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
python-poetry
Commits
8949bfdc
Commit
8949bfdc
authored
Nov 26, 2022
by
finswimmer
Committed by
Randy Döring
Feb 04, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: take `virtualenvs.prefer-active-python` into account on `poetry init`
parent
f57cdc31
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
6 deletions
+57
-6
src/poetry/console/commands/init.py
+11
-6
tests/console/commands/test_init.py
+46
-0
No files found.
src/poetry/console/commands/init.py
View file @
8949bfdc
from
__future__
import
annotations
import
sys
from
pathlib
import
Path
from
typing
import
TYPE_CHECKING
from
typing
import
Any
...
...
@@ -78,8 +76,9 @@ The <c1>init</c1> command creates a basic <comment>pyproject.toml</> file in the
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
()
...
...
@@ -161,10 +160,16 @@ The <c1>init</c1> command creates a basic <comment>pyproject.toml</> file in the
python
=
self
.
option
(
"python"
)
if
not
python
:
current_env
=
SystemEnv
(
Path
(
sys
.
executable
))
default_python
=
"^"
+
"."
.
join
(
str
(
v
)
for
v
in
current_env
.
version_info
[:
2
]
config
=
Config
.
create
()
default_python
=
(
"^"
+
EnvManager
.
get_python_version
(
precious
=
2
,
prefer_active_python
=
config
.
get
(
"virtualenvs.prefer-active-python"
),
io
=
self
.
io
,
)
.
to_string
()
)
question
=
self
.
create_question
(
f
"Compatible Python versions [<comment>{default_python}</comment>]: "
,
default
=
default_python
,
...
...
tests/console/commands/test_init.py
View file @
8949bfdc
...
...
@@ -2,10 +2,12 @@ from __future__ import annotations
import
os
import
shutil
import
subprocess
import
sys
from
pathlib
import
Path
from
typing
import
TYPE_CHECKING
from
typing
import
Any
import
pytest
...
...
@@ -26,6 +28,7 @@ if TYPE_CHECKING:
from
poetry.core.packages.package
import
Package
from
pytest_mock
import
MockerFixture
from
poetry.config.config
import
Config
from
poetry.poetry
import
Poetry
from
tests.helpers
import
TestRepository
from
tests.types
import
FixtureDirGetter
...
...
@@ -1061,3 +1064,46 @@ def test_package_include(
f
'python = "^3.10"
\n
'
)
assert
expected
in
tester
.
io
.
fetch_output
()
@pytest.mark.parametrize
(
[
"prefer_active"
,
"python"
],
[
(
True
,
"1.1"
),
(
False
,
f
"{sys.version_info[0]}.{sys.version_info[1]}"
),
],
)
def
test_respect_prefer_active_on_init
(
prefer_active
:
bool
,
python
:
str
,
config
:
Config
,
mocker
:
MockerFixture
,
tester
:
CommandTester
,
source_dir
:
Path
,
):
from
poetry.utils.env
import
GET_PYTHON_VERSION_ONELINER
orig_check_output
=
subprocess
.
check_output
def
mock_check_output
(
cmd
:
str
,
*
_
:
Any
,
**
__
:
Any
)
->
str
:
if
GET_PYTHON_VERSION_ONELINER
in
cmd
:
return
"1.1.1"
return
orig_check_output
(
cmd
,
*
_
,
**
__
)
mocker
.
patch
(
"subprocess.check_output"
,
side_effect
=
mock_check_output
)
config
.
config
[
"virtualenvs"
][
"prefer-active-python"
]
=
prefer_active
pyproject_file
=
source_dir
/
"pyproject.toml"
tester
.
execute
(
"--author 'Your Name <you@example.com>' --name 'my-package'"
,
interactive
=
False
,
)
expected
=
f
"""
\
[tool.poetry.dependencies]
python = "^{python}"
"""
assert
expected
in
pyproject_file
.
read_text
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment