8
8
import shutil
9
9
import sys
10
10
import zipfile
11
+ from contextlib import nullcontext
11
12
from subprocess import CalledProcessError
13
+ from typing import TYPE_CHECKING
12
14
13
15
from variantlib import __package_name__
14
16
from variantlib .api import VariantDescription
@@ -46,6 +48,12 @@ def make_variant(args: list[str]) -> None:
46
48
help = "Output Directory to use to store the Wheel Variant" ,
47
49
)
48
50
51
+ parser .add_argument (
52
+ "--no-isolation" ,
53
+ action = "store_true" ,
54
+ help = "Use providers already installed in callignPython environment" ,
55
+ )
56
+
49
57
parser .add_argument (
50
58
"--installer" ,
51
59
choices = ("pip" , "uv" ),
@@ -107,6 +115,7 @@ def make_variant(args: list[str]) -> None:
107
115
validate_properties = not parsed_args .skip_plugin_validation ,
108
116
variant_info = pyproject_toml ,
109
117
installer = parsed_args .installer ,
118
+ use_isolation = not parsed_args .no_isolation ,
110
119
)
111
120
112
121
@@ -119,6 +128,7 @@ def _make_variant(
119
128
validate_properties : bool = True ,
120
129
variant_info : VariantPyProjectToml ,
121
130
installer : str | None = None ,
131
+ use_isolation : bool = True ,
122
132
) -> None :
123
133
# Input Validation
124
134
if not input_filepath .is_file ():
@@ -139,38 +149,47 @@ def _make_variant(
139
149
vdesc = VariantDescription (properties = properties )
140
150
141
151
if validate_properties :
142
- from build .env import DefaultIsolatedEnv
143
-
144
- # make it really verbose to make mypy happy
145
- if installer is None :
146
- env_factory = DefaultIsolatedEnv ()
147
- elif installer == "pip" :
148
- env_factory = DefaultIsolatedEnv (installer = "pip" )
149
- elif installer == "uv" :
150
- env_factory = DefaultIsolatedEnv (installer = "uv" )
152
+ if TYPE_CHECKING :
153
+ from build .env import DefaultIsolatedEnv
154
+
155
+ env_factory : DefaultIsolatedEnv | nullcontext [None ]
156
+
157
+ if use_isolation :
158
+ from build .env import DefaultIsolatedEnv
159
+
160
+ # make it really verbose to make mypy happy
161
+ if installer is None :
162
+ env_factory = DefaultIsolatedEnv ()
163
+ elif installer == "pip" :
164
+ env_factory = DefaultIsolatedEnv (installer = "pip" )
165
+ elif installer == "uv" :
166
+ env_factory = DefaultIsolatedEnv (installer = "uv" )
167
+ else :
168
+ raise ValueError (f"unexpected installer={ installer } " )
151
169
else :
152
- raise ValueError ( f"unexpected installer= { installer } " )
170
+ env_factory = nullcontext ( )
153
171
154
172
with env_factory as venv :
155
- try :
156
- venv .install (
157
- variant_info .get_provider_requires (
158
- {vprop .namespace for vprop in vdesc .properties }
173
+ if venv is not None :
174
+ try :
175
+ venv .install (
176
+ variant_info .get_provider_requires (
177
+ {vprop .namespace for vprop in vdesc .properties }
178
+ )
159
179
)
160
- )
161
- except CalledProcessError as err :
162
- sys .stderr .write (
163
- "Installing variant provider dependencies failed:\n "
164
- f"{ err .stderr .decode ()} "
165
- )
166
- raise
180
+ except CalledProcessError as err :
181
+ sys .stderr .write (
182
+ "Installing variant provider dependencies failed:\n "
183
+ f"{ err .stderr .decode ()} "
184
+ )
185
+ raise
167
186
168
187
# Verify whether the variant properties are valid
169
188
vdesc_valid = validate_variant (
170
189
vdesc ,
171
190
variant_info = variant_info ,
172
191
use_auto_install = False ,
173
- venv_path = venv .path ,
192
+ venv_path = venv .path if venv is not None else None ,
174
193
)
175
194
if vdesc_valid .invalid_properties :
176
195
invalid_str = ", " .join (
0 commit comments