34
34
from ..util .helpers import prepare_command
35
35
from ..util .packaging import find_compatible_wheel
36
36
from ..util .python_build_standalone import create_python_build_standalone_environment
37
- from ..venv import constraint_flags , virtualenv
37
+ from ..venv import constraint_flags , find_uv , virtualenv
38
38
39
39
40
40
def android_triplet (identifier : str ) -> str :
@@ -187,6 +187,13 @@ def setup_env(
187
187
* android_env, which uses the environment while simulating running on Android.
188
188
"""
189
189
log .step ("Setting up build environment..." )
190
+ build_frontend = build_options .build_frontend .name
191
+ use_uv = build_frontend == "build[uv]"
192
+ uv_path = find_uv ()
193
+ if use_uv and uv_path is None :
194
+ msg = "uv not found"
195
+ raise AssertionError (msg )
196
+ pip = ["pip" ] if not use_uv else [str (uv_path ), "pip" ]
190
197
191
198
# Create virtual environment
192
199
python_exe = create_python_build_standalone_environment (
@@ -197,14 +204,14 @@ def setup_env(
197
204
version = config .version , tmp_dir = build_path
198
205
)
199
206
build_env = virtualenv (
200
- config .version , python_exe , venv_dir , dependency_constraint , use_uv = False
207
+ config .version , python_exe , venv_dir , dependency_constraint , use_uv = use_uv
201
208
)
202
209
create_cmake_toolchain (config , build_path , python_dir , build_env )
203
210
204
211
# Apply custom environment variables, and check environment is still valid
205
212
build_env = build_options .environment .as_dictionary (build_env )
206
213
build_env ["PIP_DISABLE_PIP_VERSION_CHECK" ] = "1"
207
- for command in ["python" , "pip" ]:
214
+ for command in ["python" ] if use_uv else [ "python" , "pip" ]:
208
215
command_path = call ("which" , command , env = build_env , capture_stdout = True ).strip ()
209
216
if command_path != f"{ venv_dir } /bin/{ command } " :
210
217
msg = (
@@ -219,11 +226,10 @@ def setup_env(
219
226
android_env = setup_android_env (config , python_dir , venv_dir , build_env )
220
227
221
228
# Install build tools
222
- build_frontend = build_options .build_frontend
223
- if build_frontend .name != "build" :
229
+ if build_frontend not in {"build" , "build[uv]" }:
224
230
msg = "Android requires the build frontend to be 'build'"
225
231
raise errors .FatalError (msg )
226
- call (" pip" , "install" , "build" , * constraint_flags (dependency_constraint ), env = build_env )
232
+ call (* pip , "install" , "build" , * constraint_flags (dependency_constraint ), env = build_env )
227
233
228
234
# Build-time requirements must be queried within android_env, because
229
235
# `get_requires_for_build` can run arbitrary code in setup.py scripts, which may be
@@ -243,13 +249,13 @@ def make_extra_environ(self) -> dict[str, str]:
243
249
244
250
pb = ProjectBuilder .from_isolated_env (AndroidEnv (), build_options .package_dir )
245
251
if pb .build_system_requires :
246
- call (" pip" , "install" , * pb .build_system_requires , env = build_env )
252
+ call (* pip , "install" , * pb .build_system_requires , env = build_env )
247
253
248
254
requires_for_build = pb .get_requires_for_build (
249
255
"wheel" , parse_config_settings (build_options .config_settings )
250
256
)
251
257
if requires_for_build :
252
- call (" pip" , "install" , * requires_for_build , env = build_env )
258
+ call (* pip , "install" , * requires_for_build , env = build_env )
253
259
254
260
return build_env , android_env
255
261
0 commit comments