Skip to content

Commit 9f40536

Browse files
committed
Revert "wip"
This reverts commit 1de8269.
1 parent 1de8269 commit 9f40536

File tree

6 files changed

+26
-87
lines changed

6 files changed

+26
-87
lines changed

python/private/pypi/extension.bzl

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616

1717
load("@bazel_features//:features.bzl", "bazel_features")
1818
load("@pythons_hub//:interpreters.bzl", "INTERPRETER_LABELS")
19-
load("@pythons_hub//:versions.bzl", "MINOR_MAPPING")
2019
load("//python/private:auth.bzl", "AUTH_ATTRS")
21-
load("//python/private:full_version.bzl", "full_version")
2220
load("//python/private:normalize_name.bzl", "normalize_name")
2321
load("//python/private:repo_utils.bzl", "repo_utils")
2422
load("//python/private:semver.bzl", "semver")
@@ -175,7 +173,6 @@ def _create_whl_repos(
175173
logger = logger,
176174
)
177175

178-
platforms = {}
179176
for whl_name, requirements in requirements_by_platform.items():
180177
group_name = whl_group_mapping.get(whl_name)
181178
group_deps = requirement_cycles.get(group_name, [])
@@ -236,10 +233,6 @@ def _create_whl_repos(
236233
))
237234

238235
whl_libraries[repo_name] = args
239-
240-
# TODO @aignas 2025-03-23: make this more efficient
241-
for p in args.pop("experimental_target_platforms", []):
242-
platforms[p] = None
243236
whl_map.setdefault(whl_name, {})[config_setting] = repo_name
244237

245238
return struct(
@@ -251,7 +244,6 @@ def _create_whl_repos(
251244
},
252245
extra_aliases = extra_aliases,
253246
whl_libraries = whl_libraries,
254-
platforms = platforms,
255247
)
256248

257249
def _whl_repos(*, requirement, whl_library_args, download_only, netrc, auth_patterns, multiple_requirements_for_whl = False, python_version):
@@ -416,7 +408,6 @@ You cannot use both the additive_build_content and additive_build_content_file a
416408
exposed_packages = {}
417409
extra_aliases = {}
418410
whl_libraries = {}
419-
platforms = {}
420411

421412
is_reproducible = True
422413

@@ -494,7 +485,6 @@ You cannot use both the additive_build_content and additive_build_content_file a
494485
extra_aliases[hub_name].setdefault(whl_name, {}).update(aliases)
495486
exposed_packages.setdefault(hub_name, {}).update(out.exposed_packages)
496487
whl_libraries.update(out.whl_libraries)
497-
platforms.setdefault(hub_name, {}).update(out.platforms)
498488

499489
# TODO @aignas 2024-04-05: how do we support different requirement
500490
# cycles for different abis/oses? For now we will need the users to
@@ -531,17 +521,6 @@ You cannot use both the additive_build_content and additive_build_content_file a
531521
}
532522
for hub_name, extra_whl_aliases in extra_aliases.items()
533523
},
534-
platforms = {
535-
hub_name: sorted(p)
536-
for hub_name, p in platforms.items()
537-
},
538-
python_versions = {
539-
hub_name: sorted({
540-
full_version(version = v, minor_mapping = MINOR_MAPPING): None
541-
for v in m.python_versions
542-
})
543-
for hub_name, m in pip_hub_map.items()
544-
},
545524
whl_libraries = {
546525
k: dict(sorted(args.items()))
547526
for k, args in sorted(whl_libraries.items())
@@ -633,8 +612,6 @@ def _pip_impl(module_ctx):
633612
for key, values in whl_map.items()
634613
},
635614
packages = mods.exposed_packages.get(hub_name, []),
636-
python_versions = mods.python_versions[hub_name],
637-
platforms = mods.platforms.get(hub_name, ["host"]),
638615
groups = mods.hub_group_map.get(hub_name),
639616
)
640617

python/private/pypi/generate_whl_library_build_bazel.bzl

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
"""Generate the BUILD.bazel contents for a repo defined by a whl_library."""
1616

17-
load("//python/private:bzlmod_enabled.bzl", "BZLMOD_ENABLED")
1817
load("//python/private:text_util.bzl", "render")
1918

2019
_RENDER = {
@@ -27,8 +26,7 @@ _RENDER = {
2726
"entry_points": render.dict,
2827
"extras": render.list,
2928
"group_deps": render.list,
30-
"host_python_version": str,
31-
"platforms": str,
29+
"platforms": render.list,
3230
"requires_dist": render.list,
3331
"srcs_exclude": render.list,
3432
"tags": render.list,
@@ -38,7 +36,7 @@ _RENDER = {
3836
# this repository can be publicly visible without the need for
3937
# export_files
4038
_TEMPLATE = """\
41-
{loads}
39+
load("@rules_python//python/private/pypi:whl_library_targets.bzl", "whl_library_targets")
4240
4341
package(default_visibility = ["//visibility:public"])
4442
@@ -63,17 +61,6 @@ def generate_whl_library_build_bazel(
6361
"""
6462

6563
additional_content = []
66-
loads = {
67-
"@rules_python//python/private/pypi:whl_library_targets.bzl": ('"whl_library_targets"',),
68-
}
69-
if BZLMOD_ENABLED:
70-
dep_template = kwargs["dep_template"]
71-
loads[dep_template.format(
72-
name = "",
73-
target = "requirements.bzl",
74-
)] = ("hub_settings = \"private\"",)
75-
kwargs["platforms"] = "hub_settings.platforms"
76-
kwargs["host_python_version"] = "hub_settings.python_versions[0]"
7764
if annotation:
7865
kwargs["data"] = annotation.data
7966
kwargs["copy_files"] = annotation.copy_files
@@ -86,13 +73,6 @@ def generate_whl_library_build_bazel(
8673
contents = "\n".join(
8774
[
8875
_TEMPLATE.format(
89-
loads = "\n".join([
90-
"load({}, {})".format(
91-
repr(path),
92-
", ".join([s for s in symbols]),
93-
)
94-
for path, symbols in loads.items()
95-
]),
9676
kwargs = render.indent("\n".join([
9777
"{} = {},".format(k, _RENDER.get(k, repr)(v))
9878
for k, v in sorted(kwargs.items())

python/private/pypi/hub_repository.bzl

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
""
1616

1717
load("//python/private:text_util.bzl", "render")
18-
load(":parse_requirements.bzl", "host_platform")
1918
load(":render_pkg_aliases.bzl", "render_multiplatform_pkg_aliases")
2019
load(":whl_config_setting.bzl", "whl_config_setting")
2120

@@ -45,11 +44,6 @@ def _impl(rctx):
4544
# `requirement`, et al. macros.
4645
macro_tmpl = "@@{name}//{{}}:{{}}".format(name = rctx.attr.name)
4746

48-
platforms = [
49-
host_platform(rctx) if p == "host" else p
50-
for p in rctx.attr.platforms
51-
]
52-
5347
rctx.file("BUILD.bazel", _BUILD_FILE_CONTENTS)
5448
rctx.template("requirements.bzl", rctx.attr._template, substitutions = {
5549
"%%ALL_DATA_REQUIREMENTS%%": render.list([
@@ -65,8 +59,6 @@ def _impl(rctx):
6559
for p in bzl_packages
6660
}),
6761
"%%MACRO_TMPL%%": macro_tmpl,
68-
"%%PLATFORMS%%": render.indent(render.list(sorted(platforms))).lstrip(),
69-
"%%PYTHON_VERSIONS%%": render.indent(render.list(sorted(rctx.attr.python_versions))).lstrip(),
7062
})
7163

7264
hub_repository = repository_rule(
@@ -82,24 +74,6 @@ hub_repository = repository_rule(
8274
mandatory = False,
8375
doc = """\
8476
The list of packages that will be exposed via all_*requirements macros. Defaults to whl_map keys.
85-
""",
86-
),
87-
# TODO @aignas 2025-03-23: get the `platforms` and `python_versions`
88-
# from the aliases? This requires us to only create aliases for the
89-
# target platforms and python_versions we care about. Python versions
90-
# probably still need to be passed in.
91-
"platforms": attr.string_list(
92-
mandatory = True,
93-
doc = """\
94-
The list of target platforms that are supported in this hub repository. This
95-
can contain 'abi_os_arch' tuples or 'host' to keep the lock files os/arch
96-
agnostic.
97-
""",
98-
),
99-
"python_versions": attr.string_list(
100-
mandatory = True,
101-
doc = """\
102-
The list of python versions that are supported in this hub repository.
10377
""",
10478
),
10579
"repo_name": attr.string(

python/private/pypi/requirements.bzl.tmpl.bzlmod

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,6 @@ all_whl_requirements = all_whl_requirements_by_package.values()
1313

1414
all_data_requirements = %%ALL_DATA_REQUIREMENTS%%
1515

16-
# Internal constants used for passing information to `whl_library`
17-
# repositories without causing re-fetching. This is not intended to be
18-
# a stable API and may break. If you would like to depend on it, please raise
19-
# a ticket describing your use-case.
20-
private = struct(
21-
python_versions = %%PYTHON_VERSIONS%%,
22-
platforms = %%PLATFORMS%%,
23-
)
24-
2516
def requirement(name):
2617
return "%%MACRO_TMPL%%".format(pip_utils.normalize_name(name), "pkg")
2718

python/private/pypi/whl_library.bzl

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ load("//python/private:repo_utils.bzl", "REPO_DEBUG_ENV_VAR", "repo_utils")
2121
load(":attrs.bzl", "ATTRS", "use_isolated")
2222
load(":deps.bzl", "all_repo_names", "record_files")
2323
load(":generate_whl_library_build_bazel.bzl", "generate_whl_library_build_bazel")
24+
load(":parse_requirements.bzl", "host_platform")
2425
load(":parse_whl_name.bzl", "parse_whl_name")
2526
load(":patch_whl.bzl", "patch_whl")
2627
load(":pypi_repo_utils.bzl", "pypi_repo_utils")
@@ -353,7 +354,6 @@ def _whl_library_impl(rctx):
353354
entry_points[entry_point_without_py] = entry_point_script_name
354355

355356
build_file_contents = generate_whl_library_build_bazel(
356-
name = metadata["name"],
357357
whl_name = whl_path.basename,
358358
# TODO @aignas 2025-03-23: load the dep_template from the hub repository
359359
dep_template = rctx.attr.dep_template or "@{}{{name}}//:{{target}}".format(rctx.attr.repo_prefix),
@@ -369,12 +369,25 @@ def _whl_library_impl(rctx):
369369
entry_points = entry_points,
370370
# TODO @aignas 2025-03-23: store the annotation in the hub repo.
371371
annotation = None if not rctx.attr.annotation else struct(**json.decode(rctx.read(rctx.attr.annotation))),
372+
name = metadata["name"],
372373
requires_dist = metadata["requires_dist"],
373-
# TODO @aignas 2025-03-23: we should just generate targets for all of the
374-
# exposed extras and ask users to depend on this by `@pypi//foo:foo__extra`.
375-
# Since all of the dependencies go through the `hub` repository, the extras
376-
# that include packages that we don't
374+
# target the host platform if the target platform is not specified in the rule.
375+
# TODO @aignas 2025-03-23: we should materialize this inside the
376+
# hub_repository `requirements.bzl` file as `TARGET_PLATFORMS` with a
377+
# note, that this is internal and will be only for usage of the
378+
# `whl_library`
379+
platforms = target_platforms or [
380+
"{}_{}".format(metadata["abi"], host_platform(rctx)),
381+
],
382+
# TODO @aignas 2025-03-23: we should expose the requested extras via a
383+
# dict in `requirements.bzl` `EXTRAS` where the key is the package name
384+
# and the value is the list of requested extras. like the above, for
385+
# internal usage only.
377386
extras = metadata["extras"],
387+
# TODO @aignas 2025-03-23: we should expose full python version via the
388+
# TARGET_PYTHON_VERSIONS list so that we can correctly calculate the
389+
# deps. This would be again, internal only stuff.
390+
host_python_version = metadata["python_version"],
378391
)
379392
rctx.file("BUILD.bazel", build_file_contents)
380393

python/private/pypi/whl_library_targets.bzl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ def whl_library_targets(
5858
copy_file = copy_file,
5959
py_binary = py_binary,
6060
py_library = py_library,
61-
deps = deps,
6261
)):
6362
"""Create all of the whl_library targets.
6463
@@ -102,7 +101,7 @@ def whl_library_targets(
102101
# the analysis phase. This means that we need to get the target platform abi
103102
# from the python version/versions we are setting the package up for. We can
104103
# potentially get this from the python toolchain interpreter.
105-
package_deps = rules.deps(
104+
package_deps = deps(
106105
name = name,
107106
requires_dist = requires_dist,
108107
platforms = platforms,
@@ -113,6 +112,11 @@ def whl_library_targets(
113112
dependencies = package_deps.deps
114113
dependencies_by_platform = package_deps.deps_select
115114

115+
dependencies = sorted([normalize_name(d) for d in dependencies])
116+
dependencies_by_platform = {
117+
platform: sorted([normalize_name(d) for d in deps])
118+
for platform, deps in dependencies_by_platform.items()
119+
}
116120
tags = sorted(tags)
117121
data = [] + data
118122

0 commit comments

Comments
 (0)