|
15 | 15 | "" |
16 | 16 |
|
17 | 17 | load("//python/private:auth.bzl", "AUTH_ATTRS", "get_auth") |
18 | | -load("//python/private:bzlmod_enabled.bzl", "BZLMOD_ENABLED") |
19 | 18 | load("//python/private:envsubst.bzl", "envsubst") |
20 | 19 | load("//python/private:is_standalone_interpreter.bzl", "is_standalone_interpreter") |
21 | 20 | load("//python/private:repo_utils.bzl", "REPO_DEBUG_ENV_VAR", "repo_utils") |
22 | 21 | load(":attrs.bzl", "ATTRS", "use_isolated") |
23 | 22 | load(":deps.bzl", "all_repo_names", "record_files") |
24 | 23 | load(":generate_whl_library_build_bazel.bzl", "generate_whl_library_build_bazel") |
25 | | -load(":parse_requirements.bzl", "host_platform") |
| 24 | +load(":parse_whl_name.bzl", "parse_whl_name") |
26 | 25 | load(":patch_whl.bzl", "patch_whl") |
27 | | -load(":pep508_requirement.bzl", "requirement") |
28 | 26 | load(":pypi_repo_utils.bzl", "pypi_repo_utils") |
29 | | -load(":whl_metadata.bzl", "whl_metadata") |
| 27 | +load(":whl_target_platforms.bzl", "whl_target_platforms") |
30 | 28 |
|
31 | 29 | _CPPFLAGS = "CPPFLAGS" |
32 | 30 | _COMMAND_LINE_TOOLS_PATH_SLUG = "commandlinetools" |
@@ -342,14 +340,29 @@ def _whl_library_impl(rctx): |
342 | 340 | timeout = rctx.attr.timeout, |
343 | 341 | ) |
344 | 342 |
|
| 343 | + target_platforms = rctx.attr.experimental_target_platforms or [] |
| 344 | + if target_platforms: |
| 345 | + parsed_whl = parse_whl_name(whl_path.basename) |
| 346 | + |
| 347 | + # NOTE @aignas 2023-12-04: if the wheel is a platform specific wheel, we |
| 348 | + # only include deps for that target platform |
| 349 | + if parsed_whl.platform_tag != "any": |
| 350 | + target_platforms = [ |
| 351 | + p.target_platform |
| 352 | + for p in whl_target_platforms( |
| 353 | + platform_tag = parsed_whl.platform_tag, |
| 354 | + abi_tag = parsed_whl.abi_tag.strip("tm"), |
| 355 | + ) |
| 356 | + ] |
| 357 | + |
345 | 358 | pypi_repo_utils.execute_checked( |
346 | 359 | rctx, |
347 | 360 | op = "whl_library.ExtractWheel({}, {})".format(rctx.attr.name, whl_path), |
348 | 361 | python = python_interpreter, |
349 | 362 | arguments = args + [ |
350 | 363 | "--whl-file", |
351 | 364 | whl_path, |
352 | | - ], |
| 365 | + ] + ["--platform={}".format(p) for p in target_platforms], |
353 | 366 | srcs = rctx.attr._python_srcs, |
354 | 367 | environment = environment, |
355 | 368 | quiet = rctx.attr.quiet, |
@@ -384,45 +397,21 @@ def _whl_library_impl(rctx): |
384 | 397 | ) |
385 | 398 | entry_points[entry_point_without_py] = entry_point_script_name |
386 | 399 |
|
387 | | - if BZLMOD_ENABLED: |
388 | | - # The following attributes are unset on bzlmod and we pass data through |
389 | | - # the hub via load statements. |
390 | | - default_python_version = None |
391 | | - target_platforms = [] |
392 | | - else: |
393 | | - # NOTE @aignas 2025-04-16: if BZLMOD_ENABLED, we should use |
394 | | - # DEFAULT_PYTHON_VERSION since platforms always come with the actual |
395 | | - # python version otherwise we should use the version of the interpreter |
396 | | - # here. In WORKSPACE `multi_pip_parse` is using an interpreter for each |
397 | | - # `pip_parse` invocation, so we will have the host target platform |
398 | | - # only. Even if somebody would change the code to support |
399 | | - # `experimental_target_platforms`, they would be for a single python |
400 | | - # version. Hence, using the `default_python_version` that we get from the |
401 | | - # interpreter is correct. Hence, we unset the argument if we are on bzlmod. |
402 | | - default_python_version = metadata["python_version"] |
403 | | - target_platforms = rctx.attr.experimental_target_platforms or [host_platform(rctx)] |
404 | | - |
405 | | - metadata = whl_metadata( |
406 | | - install_dir = rctx.path("site-packages"), |
407 | | - read_fn = rctx.read, |
408 | | - logger = logger, |
409 | | - ) |
410 | | - |
411 | 400 | build_file_contents = generate_whl_library_build_bazel( |
412 | 401 | name = whl_path.basename, |
413 | | - metadata_name = metadata.name, |
414 | | - metadata_version = metadata.version, |
415 | | - requires_dist = metadata.requires_dist, |
416 | 402 | dep_template = rctx.attr.dep_template or "@{}{{name}}//:{{target}}".format(rctx.attr.repo_prefix), |
417 | 403 | entry_points = entry_points, |
418 | | - target_platforms = target_platforms, |
419 | | - default_python_version = default_python_version, |
420 | 404 | # TODO @aignas 2025-04-14: load through the hub: |
| 405 | + dependencies = metadata["deps"], |
| 406 | + dependencies_by_platform = metadata["deps_by_platform"], |
421 | 407 | annotation = None if not rctx.attr.annotation else struct(**json.decode(rctx.read(rctx.attr.annotation))), |
422 | 408 | data_exclude = rctx.attr.pip_data_exclude, |
423 | | - extras = requirement(rctx.attr.requirement).extras, |
424 | 409 | group_deps = rctx.attr.group_deps, |
425 | 410 | group_name = rctx.attr.group_name, |
| 411 | + tags = [ |
| 412 | + "pypi_name={}".format(metadata["name"]), |
| 413 | + "pypi_version={}".format(metadata["version"]), |
| 414 | + ], |
426 | 415 | ) |
427 | 416 | rctx.file("BUILD.bazel", build_file_contents) |
428 | 417 |
|
|
0 commit comments