@@ -552,12 +552,7 @@ def _detect_active_python(self, io: IO) -> str | None:
552
552
return executable
553
553
554
554
def activate (self , python : str , io : IO ) -> Env :
555
- venv_path = self ._poetry .config .get ("virtualenvs.path" )
556
- if venv_path is None :
557
- venv_path = self ._poetry .config .get ("cache-dir" ) / "virtualenvs"
558
- else :
559
- venv_path = Path (venv_path )
560
-
555
+ venv_path = self ._poetry .config .virtualenvs_path
561
556
cwd = self ._poetry .file .parent
562
557
563
558
envs_file = TOMLFile (venv_path / self .ENVS_FILE )
@@ -645,12 +640,7 @@ def activate(self, python: str, io: IO) -> Env:
645
640
return self .get (reload = True )
646
641
647
642
def deactivate (self , io : IO ) -> None :
648
- venv_path = self ._poetry .config .get ("virtualenvs.path" )
649
- if venv_path is None :
650
- venv_path = self ._poetry .config .get ("cache-dir" ) / "virtualenvs"
651
- else :
652
- venv_path = Path (venv_path )
653
-
643
+ venv_path = self ._poetry .config .virtualenvs_path
654
644
name = self ._poetry .package .name
655
645
name = self .generate_env_name (name , str (self ._poetry .file .parent ))
656
646
@@ -671,11 +661,7 @@ def get(self, reload: bool = False) -> Env:
671
661
672
662
python_minor = "." .join ([str (v ) for v in sys .version_info [:2 ]])
673
663
674
- venv_path = self ._poetry .config .get ("virtualenvs.path" )
675
- if venv_path is None :
676
- venv_path = self ._poetry .config .get ("cache-dir" ) / "virtualenvs"
677
- else :
678
- venv_path = Path (venv_path )
664
+ venv_path = self ._poetry .config .virtualenvs_path
679
665
680
666
cwd = self ._poetry .file .parent
681
667
envs_file = TOMLFile (venv_path / self .ENVS_FILE )
@@ -712,11 +698,7 @@ def get(self, reload: bool = False) -> Env:
712
698
if not create_venv :
713
699
return self .get_system_env ()
714
700
715
- venv_path = self ._poetry .config .get ("virtualenvs.path" )
716
- if venv_path is None :
717
- venv_path = self ._poetry .config .get ("cache-dir" ) / "virtualenvs"
718
- else :
719
- venv_path = Path (venv_path )
701
+ venv_path = self ._poetry .config .virtualenvs_path
720
702
721
703
name = f"{ base_env_name } -py{ python_minor .strip ()} "
722
704
@@ -741,13 +723,7 @@ def list(self, name: str | None = None) -> list[VirtualEnv]:
741
723
name = self ._poetry .package .name
742
724
743
725
venv_name = self .generate_env_name (name , str (self ._poetry .file .parent ))
744
-
745
- venv_path = self ._poetry .config .get ("virtualenvs.path" )
746
- if venv_path is None :
747
- venv_path = self ._poetry .config .get ("cache-dir" ) / "virtualenvs"
748
- else :
749
- venv_path = Path (venv_path )
750
-
726
+ venv_path = self ._poetry .config .virtualenvs_path
751
727
env_list = [
752
728
VirtualEnv (Path (p )) for p in sorted (venv_path .glob (f"{ venv_name } -py*" ))
753
729
]
@@ -762,11 +738,7 @@ def list(self, name: str | None = None) -> list[VirtualEnv]:
762
738
return env_list
763
739
764
740
def remove (self , python : str ) -> Env :
765
- venv_path = self ._poetry .config .get ("virtualenvs.path" )
766
- if venv_path is None :
767
- venv_path = self ._poetry .config .get ("cache-dir" ) / "virtualenvs"
768
- else :
769
- venv_path = Path (venv_path )
741
+ venv_path = self ._poetry .config .virtualenvs_path
770
742
771
743
cwd = self ._poetry .file .parent
772
744
envs_file = TOMLFile (venv_path / self .ENVS_FILE )
@@ -875,7 +847,6 @@ def create_venv(
875
847
876
848
create_venv = self ._poetry .config .get ("virtualenvs.create" )
877
849
root_venv = self ._poetry .config .get ("virtualenvs.in-project" )
878
- venv_path = self ._poetry .config .get ("virtualenvs.path" )
879
850
prefer_active_python = self ._poetry .config .get (
880
851
"virtualenvs.prefer-active-python"
881
852
)
@@ -884,13 +855,7 @@ def create_venv(
884
855
if not executable and prefer_active_python :
885
856
executable = self ._detect_active_python (io )
886
857
887
- if root_venv :
888
- venv_path = cwd / ".venv"
889
- elif venv_path is None :
890
- venv_path = self ._poetry .config .get ("cache-dir" ) / "virtualenvs"
891
- else :
892
- venv_path = Path (venv_path )
893
-
858
+ venv_path = cwd / ".venv" if root_venv else self ._poetry .config .virtualenvs_path
894
859
if not name :
895
860
name = self ._poetry .package .name
896
861
assert name is not None
0 commit comments