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
f57cdc31
Commit
f57cdc31
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: turn EnvManager method into staticmethod which detect active python
parent
98568d49
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
16 deletions
+26
-16
src/poetry/utils/env.py
+26
-16
No files found.
src/poetry/utils/env.py
View file @
f57cdc31
...
...
@@ -20,7 +20,6 @@ from pathlib import Path
from
subprocess
import
CalledProcessError
from
typing
import
TYPE_CHECKING
from
typing
import
Any
from
typing
import
cast
import
packaging.tags
import
tomlkit
...
...
@@ -521,7 +520,8 @@ class EnvManager:
self
.
_poetry
=
poetry
self
.
_io
=
io
or
NullIO
()
def
_full_python_path
(
self
,
python
:
str
)
->
str
:
@staticmethod
def
_full_python_path
(
python
:
str
)
->
str
:
try
:
executable
=
decode
(
subprocess
.
check_output
(
...
...
@@ -536,23 +536,23 @@ class EnvManager:
return
executable
def
_detect_active_python
(
self
)
->
str
|
None
:
@staticmethod
def
_detect_active_python
(
io
:
None
|
IO
=
None
)
->
str
|
None
:
io
=
io
or
NullIO
()
executable
=
None
try
:
self
.
_
io
.
write_error_line
(
io
.
write_error_line
(
(
"Trying to detect current active python executable as specified in"
" the config."
),
verbosity
=
Verbosity
.
VERBOSE
,
)
executable
=
self
.
_full_python_path
(
"python"
)
self
.
_io
.
write_error_line
(
f
"Found: {executable}"
,
verbosity
=
Verbosity
.
VERBOSE
)
executable
=
EnvManager
.
_full_python_path
(
"python"
)
io
.
write_error_line
(
f
"Found: {executable}"
,
verbosity
=
Verbosity
.
VERBOSE
)
except
EnvCommandError
:
self
.
_
io
.
write_error_line
(
io
.
write_error_line
(
(
"Unable to detect the current active python executable. Falling"
" back to default."
...
...
@@ -561,11 +561,16 @@ class EnvManager:
)
return
executable
def
_get_python_version
(
self
)
->
tuple
[
int
,
int
,
int
]:
version_info
=
tuple
(
sys
.
version_info
[:
3
])
@staticmethod
def
get_python_version
(
precious
:
int
=
3
,
prefer_active_python
:
bool
=
False
,
io
:
None
|
IO
=
None
,
)
->
Version
:
version
=
"."
.
join
(
str
(
v
)
for
v
in
sys
.
version_info
[:
precious
])
if
self
.
_poetry
.
config
.
get
(
"virtualenvs.prefer-active-python"
)
:
executable
=
self
.
_detect_active_python
(
)
if
prefer_active_python
:
executable
=
EnvManager
.
_detect_active_python
(
io
)
if
executable
:
python_patch
=
decode
(
...
...
@@ -577,9 +582,9 @@ class EnvManager:
)
.
strip
()
)
version
_info
=
tuple
(
int
(
v
)
for
v
in
python_patch
.
split
(
"."
)[:
3
])
version
=
"."
.
join
(
str
(
v
)
for
v
in
python_patch
.
split
(
"."
)[:
precious
])
return
cast
(
"tuple[int, int, int]"
,
version_info
)
return
Version
.
parse
(
version
)
def
activate
(
self
,
python
:
str
)
->
Env
:
venv_path
=
self
.
_poetry
.
config
.
virtualenvs_path
...
...
@@ -692,7 +697,12 @@ class EnvManager:
if
self
.
_env
is
not
None
and
not
reload
:
return
self
.
_env
python_minor
=
"."
.
join
([
str
(
v
)
for
v
in
self
.
_get_python_version
()[:
2
]])
prefer_active_python
=
self
.
_poetry
.
config
.
get
(
"virtualenvs.prefer-active-python"
)
python_minor
=
self
.
get_python_version
(
precious
=
2
,
prefer_active_python
=
prefer_active_python
,
io
=
self
.
_io
)
.
to_string
()
venv_path
=
self
.
_poetry
.
config
.
virtualenvs_path
...
...
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