39
39
from poetry .utils ._compat import encode
40
40
from poetry .utils ._compat import list_to_shell_command
41
41
from poetry .utils ._compat import subprocess
42
+ from poetry .utils .helpers import temporary_directory
42
43
from poetry .utils .toml_file import TomlFile
43
44
44
45
@@ -680,8 +681,13 @@ def create_venv(
680
681
681
682
@classmethod
682
683
def build_venv (
683
- cls , path , executable = None , with_pip = False
684
- ): # type: (Union[Path,str], Optional[Union[str, Path]], bool) -> virtualenv.run.session.Session
684
+ cls ,
685
+ path ,
686
+ executable = None ,
687
+ with_pip = False ,
688
+ with_wheel = None ,
689
+ with_setuptools = None ,
690
+ ): # type: (Union[Path,str], Optional[Union[str, Path]], bool, Optional[bool], Optional[bool]) -> virtualenv.run.session.Session
685
691
if isinstance (executable , Path ):
686
692
executable = executable .resolve ().as_posix ()
687
693
@@ -693,7 +699,16 @@ def build_venv(
693
699
]
694
700
695
701
if not with_pip :
696
- opts .extend (["--no-pip" , "--no-wheel" , "--no-setuptools" ])
702
+ opts .append ("--no-pip" )
703
+ else :
704
+ if with_wheel is None :
705
+ with_wheel = True
706
+
707
+ if with_wheel is None or not with_wheel :
708
+ opts .append ("--no-wheel" )
709
+
710
+ if with_setuptools is None or not with_setuptools :
711
+ opts .append ("--no-setuptools" )
697
712
698
713
opts .append (str (path ))
699
714
@@ -1250,6 +1265,21 @@ def _bin(self, bin):
1250
1265
return bin
1251
1266
1252
1267
1268
+ @contextmanager
1269
+ def ephemeral_environment (executable = None , pip = False , wheel = None , setuptools = None ):
1270
+ with temporary_directory () as tmp_dir :
1271
+ # TODO: cache PEP 517 build environment corresponding to each project venv
1272
+ venv_dir = Path (tmp_dir ) / ".venv"
1273
+ EnvManager .build_venv (
1274
+ path = venv_dir .as_posix (),
1275
+ executable = executable ,
1276
+ with_pip = pip ,
1277
+ with_wheel = wheel ,
1278
+ with_setuptools = setuptools ,
1279
+ )
1280
+ yield VirtualEnv (venv_dir , venv_dir )
1281
+
1282
+
1253
1283
class MockEnv (NullEnv ):
1254
1284
def __init__ (
1255
1285
self ,
0 commit comments