File tree 1 file changed +22
-1
lines changed
1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change 20
20
from subprocess import CalledProcessError
21
21
from typing import TYPE_CHECKING
22
22
from typing import Any
23
+ from typing import cast
23
24
24
25
import packaging .tags
25
26
import tomlkit
@@ -556,6 +557,26 @@ def _detect_active_python(self) -> str | None:
556
557
)
557
558
return executable
558
559
560
+ def _get_python_version (self ) -> tuple [int , int , int ]:
561
+ version_info = tuple (sys .version_info [:3 ])
562
+
563
+ if self ._poetry .config .get ("virtualenvs.prefer-active-python" ):
564
+ executable = self ._detect_active_python ()
565
+
566
+ if executable :
567
+ python_patch = decode (
568
+ subprocess .check_output (
569
+ list_to_shell_command (
570
+ [executable , "-c" , GET_PYTHON_VERSION_ONELINER ]
571
+ ),
572
+ shell = True ,
573
+ ).strip ()
574
+ )
575
+
576
+ version_info = tuple (int (v ) for v in python_patch .split ("." )[:3 ])
577
+
578
+ return cast ("tuple[int, int, int]" , version_info )
579
+
559
580
def activate (self , python : str ) -> Env :
560
581
venv_path = self ._poetry .config .virtualenvs_path
561
582
cwd = self ._poetry .file .parent
@@ -667,7 +688,7 @@ def get(self, reload: bool = False) -> Env:
667
688
if self ._env is not None and not reload :
668
689
return self ._env
669
690
670
- python_minor = "." .join ([str (v ) for v in sys . version_info [:2 ]])
691
+ python_minor = "." .join ([str (v ) for v in self . _get_python_version () [:2 ]])
671
692
672
693
venv_path = self ._poetry .config .virtualenvs_path
673
694
You can’t perform that action at this time.
0 commit comments