8000 feat(gazelle): support multiple requirements files in manifest genera… · cflewis/rules_python@9dd944e · GitHub
[go: up one dir, main page]

Skip to content

Commit 9dd944e

Browse files
authored
feat(gazelle): support multiple requirements files in manifest generation (bazel-contrib#1301)
For certain workflows it is useful to calculate the integrity hash of the manifest file based on a number of requirements files. The requirements locking is usually done by executing a script on each platform and having gazelle manifest generator be aware that more than one requirements file may affect the outcome (e.g. the wheels that get passed to modules map may come from multi_pip_parse rule) is generally useful. This change modifies the generation macro to concatenate the requirements files into one before passing it to the manifest generator.
1 parent 42b72db commit 9dd944e

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

examples/build_file_generation/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ gazelle_python_manifest(
4242
name = "gazelle_python_manifest",
4343
modules_mapping = ":modules_map",
4444
pip_repository_name = "pip",
45+
# NOTE: We can pass a list just like in `bzlmod_build_file_generation` example
46+
# but we keep a single target here for regression testing.
4547
requirements = "//:requirements_lock.txt",
4648
# NOTE: we can use this flag in order to make our setup compatible with
4749
# bzlmod.

examples/bzlmod_build_file_generation/BUILD.bazel

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ gazelle_python_manifest(
4949
name = "gazelle_python_manifest",
5050
modules_mapping = ":modules_map",
5151
pip_repository_name = "pip",
52-
requirements = "//:requirements_lock.txt",
52+
requirements = [
53+
"//:requirements_lock.txt",
54+
"//:requirements_windows.txt",
55+
],
5356
# NOTE: we can use this flag in order to make our setup compatible with
5457
# bzlmod.
5558
use_pip_repository_aliases = True,

examples/bzlmod_build_file_generation/gazelle_python.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ manifest:
232232
isort.wrap: isort
233233
isort.wrap_modes: isort
234234
lazy_object_proxy: lazy_object_proxy
235+
lazy_object_proxy.cext: lazy_object_proxy
235236
lazy_object_proxy.compat: lazy_object_proxy
236237
lazy_object_proxy.simple: lazy_object_proxy
237238
lazy_object_proxy.slots: lazy_object_proxy
@@ -587,4 +588,4 @@ manifest:
587588
pip_repository:
588589
name: pip
589590
use_pip_repository_aliases: true
590-
integrity: d979738b10adbbaff0884837e4414688990491c6c40f6a25d58b9bb564411477
591+
integrity: cee7684391c4a8a1ff219cd354deae61cdcdee70f2076789aabd5249f3c4eca9

gazelle/manifest/defs.bzl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ def gazelle_python_manifest(
3030
3131
Args:
3232
name: the name used as a base for the targets.
33-
requirements: the target for the requirements.txt file.
33+
requirements: the target for the requirements.txt file or a list of
34+
requirements files that will be concatenated before passing on to
35+
the manifest generator.
3436
pip_repository_name: the name of the pip_install or pip_repository target.
3537
use_pip_repository_aliases: boolean flag to enable using user-friendly
3638
python package aliases.
@@ -55,6 +57,16 @@ def gazelle_python_manifest(
5557

5658
manifest_generator_hash = Label("//manifest/generate:generate_lib_sources_hash")
5759

60+
if type(requirements) == "list":
61+
native.genrule(
62+
name = name + "_requirements_gen",
63+
srcs = sorted(requirements),
64+
outs = [name + "_requirements.txt"],
65+
cmd_bash = "cat $(SRCS) > $@",
66+
cmd_bat = "type $(SRCS) > $@",
67+
)
68+
requirements = name + "_requirements_gen"
69+
5870
update_args = [
5971
"--manifest-generator-hash",
6072
"$(rootpath {})".format(manifest_generator_hash),

0 commit comments

Comments
 (0)
0