Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(whl_library): track sources in whl_library #2526

Merged
merged 5 commits into from
Jan 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ Unreleased changes template.
are now printing more details and include the currently active flag
values. Fixes [#2466](https://github.com/bazelbuild/rules_python/issues/2466).
* (py_proto_library) Fix import paths in Bazel 8.
* (whl_library) Now the changes to the dependencies are correctly tracked when
PyPI packages used in {bzl:obj}`whl_library` during the `repository_rule` phase
change. Fixes [#2468](https://github.com/bazelbuild/rules_python/issues/2468).
+ (gazelle) Gazelle no longer ignores `setup.py` files by default. To restore
this behavior, apply the `# gazelle:python_ignore_files setup.py` directive.

Expand Down
7 changes: 7 additions & 0 deletions python/private/pypi/deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ py_library(

# Collate all the repository names so they can be easily consumed
all_repo_names = [name for (name, _, _) in _RULE_DEPS]
record_files = {
name: Label("@{}//:{}.dist-info/RECORD".format(
name,
url.rpartition("/")[-1].partition("-py3-none")[0],
))
for (name, url, _) in _RULE_DEPS
}

def pypi_deps():
"""
Expand Down
3 changes: 2 additions & 1 deletion python/private/pypi/evaluate_markers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@

"""A simple function that evaluates markers using a python interpreter."""

load(":deps.bzl", "record_files")
load(":pypi_repo_utils.bzl", "pypi_repo_utils")

# Used as a default value in a rule to ensure we fetch the dependencies.
SRCS = [
# When the version, or any of the files in `packaging` package changes,
# this file will change as well.
Label("@pypi__packaging//:packaging-24.0.dist-info/RECORD"),
record_files["pypi__packaging"],
Label("//python/private/pypi/requirements_parser:resolve_target_platforms.py"),
Label("//python/private/pypi/whl_installer:platform.py"),
]
Expand Down
18 changes: 15 additions & 3 deletions python/private/pypi/whl_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ load("//python/private:envsubst.bzl", "envsubst")
load("//python/private:is_standalone_interpreter.bzl", "is_standalone_interpreter")
load("//python/private:repo_utils.bzl", "REPO_DEBUG_ENV_VAR", "repo_utils")
load(":attrs.bzl", "ATTRS", "use_isolated")
load(":deps.bzl", "all_repo_names")
load(":deps.bzl", "all_repo_names", "record_files")
load(":generate_whl_library_build_bazel.bzl", "generate_whl_library_build_bazel")
load(":parse_whl_name.bzl", "parse_whl_name")
load(":patch_whl.bzl", "patch_whl")
Expand Down Expand Up @@ -242,14 +242,15 @@ def _whl_library_impl(rctx):
else:
op_tmpl = "whl_library.ResolveRequirement({name}, {requirement})"

repo_utils.execute_checked(
pypi_repo_utils.execute_checked(
rctx,
# truncate the requirement value when logging it / reporting
# progress since it may contain several ' --hash=sha256:...
# --hash=sha256:...' substrings that fill up the console
op = op_tmpl.format(name = rctx.attr.name, requirement = rctx.attr.requirement.split(" ", 1)[0]),
arguments = args,
environment = environment,
srcs = rctx.attr._python_srcs,
quiet = rctx.attr.quiet,
timeout = rctx.attr.timeout,
logger = logger,
Expand Down Expand Up @@ -291,13 +292,14 @@ def _whl_library_impl(rctx):
)
]

repo_utils.execute_checked(
pypi_repo_utils.execute_checked(
rctx,
op = "whl_library.ExtractWheel({}, {})".format(rctx.attr.name, whl_path),
arguments = args + [
"--whl-file",
whl_path,
] + ["--platform={}".format(p) for p in target_platforms],
srcs = rctx.attr._python_srcs,
environment = environment,
quiet = rctx.attr.quiet,
timeout = rctx.attr.timeout,
Expand Down Expand Up @@ -450,6 +452,16 @@ attr makes `extra_pip_args` and `download_only` ignored.""",
for repo in all_repo_names
],
),
"_python_srcs": attr.label_list(
# Used as a default value in a rule to ensure we fetch the dependencies.
default = [
Label("//python/private/pypi/whl_installer:platform.py"),
Label("//python/private/pypi/whl_installer:wheel.py"),
Label("//python/private/pypi/whl_installer:wheel_installer.py"),
Label("//python/private/pypi/whl_installer:arguments.py"),
Label("//python/private/pypi/whl_installer:namespace_pkgs.py"),
] + record_files.values(),
),
"_rule_name": attr.string(default = "whl_library"),
}, **ATTRS)
whl_library_attrs.update(AUTH_ATTRS)
Expand Down