Skip to content

Commit 81512d2

Browse files
committed
Revert "move the dep parsing to the analysis phase"
This reverts commit 7f99cb7.
1 parent 9f40536 commit 81512d2

File tree

3 files changed

+37
-48
lines changed

3 files changed

+37
-48
lines changed

python/private/pypi/generate_whl_library_build_bazel.bzl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ _RENDER = {
2424
"dependencies": render.list,
2525
"dependencies_by_platform": lambda x: render.dict(x, value_repr = render.list),
2626
"entry_points": render.dict,
27-
"extras": render.list,
2827
"group_deps": render.list,
29-
"platforms": render.list,
30-
"requires_dist": render.list,
3128
"srcs_exclude": render.list,
3229
"tags": render.list,
3330
}

python/private/pypi/whl_library.bzl

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ load(":generate_whl_library_build_bazel.bzl", "generate_whl_library_build_bazel"
2424
load(":parse_requirements.bzl", "host_platform")
2525
load(":parse_whl_name.bzl", "parse_whl_name")
2626
load(":patch_whl.bzl", "patch_whl")
27+
load(":pep508_env.bzl", "deps")
2728
load(":pypi_repo_utils.bzl", "pypi_repo_utils")
2829
load(":whl_target_platforms.bzl", "whl_target_platforms")
2930

@@ -353,22 +354,13 @@ def _whl_library_impl(rctx):
353354
)
354355
entry_points[entry_point_without_py] = entry_point_script_name
355356

356-
build_file_contents = generate_whl_library_build_bazel(
357-
whl_name = whl_path.basename,
358-
# TODO @aignas 2025-03-23: load the dep_template from the hub repository
359-
dep_template = rctx.attr.dep_template or "@{}{{name}}//:{{target}}".format(rctx.attr.repo_prefix),
360-
# TODO @aignas 2025-03-23: store the `group_name` per package in the hub repo
361-
group_name = rctx.attr.group_name,
362-
group_deps = rctx.attr.group_deps,
363-
# TODO @aignas 2025-03-23: store the pip_data_exclude in the hub repo.
364-
data_exclude = rctx.attr.pip_data_exclude,
365-
tags = [
366-
"pypi_name=" + metadata["name"],
367-
"pypi_version=" + metadata["version"],
368-
],
369-
entry_points = entry_points,
370-
# TODO @aignas 2025-03-23: store the annotation in the hub repo.
371-
annotation = None if not rctx.attr.annotation else struct(**json.decode(rctx.read(rctx.attr.annotation))),
357+
# TODO @aignas 2025-02-24: move this to pkg_aliases layer to have this in
358+
# the analysis phase. This means that we need to get the target platform abi
359+
# from the python version/versions we are setting the package up for. We can
360+
# potentially get this from the python toolchain interpreter.
361+
package_deps = deps(
362+
# TODO @aignas 2025-02-24: get the data here by parsing the METADATA
363+
# file manually without involving python interpreter at all.
372364
name = metadata["name"],
373365
requires_dist = metadata["requires_dist"],
374366
# target the host platform if the target platform is not specified in the rule.
@@ -389,6 +381,28 @@ def _whl_library_impl(rctx):
389381
# deps. This would be again, internal only stuff.
390382
host_python_version = metadata["python_version"],
391383
)
384+
385+
build_file_contents = generate_whl_library_build_bazel(
386+
name = whl_path.basename,
387+
# TODO @aignas 2025-03-23: load the dep_template from the hub repository
388+
dep_template = rctx.attr.dep_template or "@{}{{name}}//:{{target}}".format(rctx.attr.repo_prefix),
389+
# TODO @aignas 2025-03-23: replace `dependencies` and
390+
# `dependencies_by_platform` with `requires_dist`.
391+
dependencies = package_deps.deps,
392+
dependencies_by_platform = package_deps.deps_select,
393+
# TODO @aignas 2025-03-23: store the `group_name` per package in the hub repo
394+
group_name = rctx.attr.group_name,
395+
group_deps = rctx.attr.group_deps,
396+
# TODO @aignas 2025-03-23: store the pip_data_exclude in the hub repo.
397+
data_exclude = rctx.attr.pip_data_exclude,
398+
tags = [
399+
"pypi_name=" + metadata["name"],
400+
"pypi_version=" + metadata["version"],
401+
],
402+
entry_points = entry_points,
403+
# TODO @aignas 2025-03-23: store the annotation in the hub repo.
404+
annotation = None if not rctx.attr.annotation else struct(**json.decode(rctx.read(rctx.attr.annotation))),
405+
)
392406
rctx.file("BUILD.bazel", build_file_contents)
393407

394408
return

python/private/pypi/whl_library_targets.bzl

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,10 @@ load(
2929
"WHEEL_FILE_IMPL_LABEL",
3030
"WHEEL_FILE_PUBLIC_LABEL",
3131
)
32-
load(":pep508_env.bzl", "deps")
3332

3433
def whl_library_targets(
3534
*,
3635
name,
37-
whl_name,
3836
dep_template,
3937
data_exclude = [],
4038
srcs_exclude = [],
@@ -43,16 +41,14 @@ def whl_library_targets(
4341
DIST_INFO_LABEL: ["site-packages/*.dist-info/**"],
4442
DATA_LABEL: ["data/**"],
4543
},
44+
dependencies = [],
45+
dependencies_by_platform = {},
4646
group_deps = [],
4747
group_name = "",
4848
data = [],
4949
copy_files = {},
5050
copy_executables = {},
5151
entry_points = {},
52-
requires_dist = [],
53-
platforms,
54-
extras = [],
55-
host_python_version,
5652
native = native,
5753
rules = struct(
5854
copy_file = copy_file,
@@ -62,12 +58,14 @@ def whl_library_targets(
6258
"""Create all of the whl_library targets.
6359
6460
Args:
65-
name: {type}`str` the name of the distribution.
66-
whl_name: {type}`str` The file to match for including it into the `whl`
61+
name: {type}`str` The file to match for including it into the `whl`
6762
filegroup. This may be also parsed to generate extra metadata.
6863
dep_template: {type}`str` The dep_template to use for dependency
6964
interpolation.
7065
tags: {type}`list[str]` The tags set on the `py_library`.
66+
dependencies: {type}`list[str]` A list of dependencies.
67+
dependencies_by_platform: {type}`dict[str, list[str]]` A list of
68+
dependencies by platform key.
7169
filegroups: {type}`dict[str, list[str]]` A dictionary of the target
7270
names and the glob matches.
7371
group_name: {type}`str` name of the dependency group (if any) which
@@ -89,29 +87,9 @@ def whl_library_targets(
8987
data: {type}`list[str]` A list of labels to include as part of the `data` attribute in `py_library`.
9088
entry_points: {type}`dict[str, str]` The mapping between the script
9189
name and the python file to use. DEPRECATED.
92-
requires_dist: TODO
93-
platforms: TODO
94-
extras: TODO
95-
host_python_version: TODO
9690
native: {type}`native` The native struct for overriding in tests.
9791
rules: {type}`struct` A struct with references to rules for creating targets.
9892
"""
99-
100-
# TODO @aignas 2025-02-24: move this to pkg_aliases layer to have this in
101-
# the analysis phase. This means that we need to get the target platform abi
102-
# from the python version/versions we are setting the package up for. We can
103-
# potentially get this from the python toolchain interpreter.
104-
package_deps = deps(
105-
name = name,
106-
requires_dist = requires_dist,
107-
platforms = platforms,
108-
extras = extras,
109-
host_python_version = host_python_version,
110-
)
111-
112-
dependencies = package_deps.deps
113-
dependencies_by_platform = package_deps.deps_select
114-
11593
dependencies = sorted([normalize_name(d) for d in dependencies])
11694
dependencies_by_platform = {
11795
platform: sorted([normalize_name(d) for d in deps])
@@ -225,7 +203,7 @@ def whl_library_targets(
225203
if hasattr(native, "filegroup"):
226204
native.filegroup(
227205
name = whl_file_label,
228-
srcs = [whl_name],
206+
srcs = [name],
229207
data = _deps(
230208
deps = dependencies,
231209
deps_by_platform = dependencies_by_platform,

0 commit comments

Comments
 (0)