bazel-contrib / bazel-contrib/rules_python

`gazelle:python_manifest_file_name` not applied in subdirectories

Đang mở
#3,133 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
gazelle
Ngôn ngữ chính
Starlark
Star
688
Fork
721
Merge trung bình
15 giờ 7 phút
Pull request đã merge (30 ngày)
76

Mô tả

# 🐞 bug report

### Affected Rule

[`gazelle`](https://github.com/bazel-contrib/rules_python/blob/main/examples/bzlmod_build_file_generation/BUILD.bazel#L90-L93) with `gazelle = "@rules_python_gazelle_plugin//python:gazelle_binary"`.

### Is this a regression?

I don't think so.

### Description

[Gazelle documentation](https://github.com/bazel-contrib/bazel-gazelle?tab=readme-ov-file#directives) describes directives as:
> Directives apply in the directory where they are set and in subdirectories. This means, for example, if you set # gazelle:prefix in the build file in your project's root directory, it affects your whole project. If you set it in a subdirectory, it only affects rules in that subtree.

Thus, I expected [`gazelle:python_manifest_file_name`](https://github.com/bazel-contrib/rules_python/blob/main/gazelle/README.md#directives) directive to apply to targets within the subfolders. I don't think this is the case, however. It seems like gazelle only considers directives at the root BUILD file.

## 🔬 Minimal Reproduction

See https://github.com/bazel-contrib/rules_python/compare/main...hartikainen:gazelle-hub-change. Running this gives me:

Given the directives in [`jax/BUILD.bazel`](https://github.com/bazel-contrib/rules_python/compare/main...hartikainen:gazelle-hub-change#diff-f767eeff89c3e51bca27e7684abee92f362583542d781aac5a378c614e3bb7a0R3-R4) and [`numpy/BUILD.bazel`](https://github.com/bazel-contrib/rules_python/compare/main...hartikainen:gazelle-hub-change#diff-adcf17f9e663d83e26a6efe5842cdfd69bf37f1827d99fe4674f9d583c754258R3-R4), I would expect both `py_binary` targets to have the right `deps` (as I have manually written them) after running `bazel run //:gazelle`. Unfortunately, gazelle does not recognize the directives in the subdirectories and fails.

## 🔥 Exception or Error

Details

```console
$ bazel run //:gazelle
INFO: Analyzed target //:gazelle (0 packages loaded, 2 targets configured).
INFO: Found 1 target...
Target //:gazelle up-to-date:
bazel-bin/gazelle-runner.bash
bazel-bin/gazelle
INFO: Elapsed time: 0.162s, Critical Path: 0.00s
INFO: 1 process: 6 action cache hit, 1 internal.
INFO: Build completed successfully, 1 total action
INFO: Running command line: bazel-bin/gazelle
gazelle: ERROR: failed to validate dependencies for target "//jax:main":

"jax/main.py", line 5: "absl.app" is an invalid dependency: possible solutions:
1. Add it as a dependency in the requirements.txt file.
2. Use the '# gazelle:resolve py absl.app TARGET_LABEL' BUILD file directive to resolve to a known dependency.
3. Ignore it with a comment '# gazelle:ignore absl.app' in the Python file.

"jax/main.py", line 5: "absl" is an invalid dependency: possible solutions:
1. Add it as a dependency in the requirements.txt file.
2. Use the '# gazelle:resolve py absl TARGET_LABEL' BUILD file directive to resolve to a known dependency.
3. Ignore it with a comment '# gazelle:ignore absl' in the Python file.

gazelle: ERROR: failed to validate dependencies for target "//jax:main":

"jax/main.py", line 6: "absl.logging" is an invalid dependency: possible solutions:
1. Add it as a dependency in the requirements.txt file.
2. Use the '# gazelle:resolve py absl.logging TARGET_LABEL' BUILD file directive to resolve to a known dependency.
3. Ignore it with a comment '# gazelle:ignore absl.logging' in the Python file.

"jax/main.py", line 6: "absl" is an invalid dependency: possible solutions:
1. Add it as a dependency in the requirements.txt file.
2. Use the '# gazelle:resolve py absl TARGET_LABEL' BUILD file directive to resolve to a known dependency.
3. Ignore it with a comment '# gazelle:ignore absl' in the Python file.

gazelle: ERROR: failed to validate dependencies for target "//jax:main":

"jax/main.py", line 7: "etils.eapp" is an invalid dependency: possible solutions:
1. Add it as a dependency in the requirements.txt file.
2. Use the '# gazelle:resolve py etils.eapp TARGET_LABEL' BUILD file directive to resolve to a known dependency.
3. Ignore it with a comment '# gazelle:ignore etils.eapp' in the Python file.

"jax/main.py", line 7: "etils" is an invalid dependency: possible solutions:
1. Add it as a dependency in the requirements.txt file.
2. Use the '# gazelle:resolve py etils TARGET_LABEL' BUILD file directive to resolve to a known dependency.
3. Ignore it with a comment '# gazelle:ignore etils' in the Python file.

gazelle: ERROR: failed to validate dependencies for target "//jax:main":

"jax/main.py", line 8: "etils.epath" is an invalid dependency: possible solutions:
1. Add it as a dependency in the requirements.txt file.
2. Use the '# gazelle:resolve py etils.epath TARGET_LABEL' BUILD file directive to resolve to a known dependency.
3. Ignore it with a comment '# gazelle:ignore etils.epath' in the Python file.

"jax/main.py", line 8: "etils" is an invalid dependency: possible solutions:
1. Add it as a dependency in the requirements.txt file.
2. Use the '# gazelle:resolve py etils TARGET_LABEL' BUILD file directive to resolve to a known dependency.
3. Ignore it with a comment '# gazelle:ignore etils' in the Python file.

gazelle: ERROR: failed to validate dependencies for target "//jax:main":

"jax/main.py", line 9: "jax.numpy" is an invalid dependency: possible solutions:
1. Add it as a dependency in the requirements.txt file.
2. Use the '# gazelle:resolve py jax.numpy TARGET_LABEL' BUILD file directive to resolve to a known dependency.
3. Ignore it with a comment '# gazelle:ignore jax.numpy' in the Python file.

"jax/main.py", line 9: "jax" is an invalid dependency: possible solutions:
1. Add it as a dependency in the requirements.txt file.
2. Use the '# gazelle:resolve py jax TARGET_LABEL' BUILD file directive to resolve to a known dependency.
3. Ignore it with a comment '# gazelle:ignore jax' in the Python file.
```

## 🌍 Your Environment

**Operating System:**

  

macos Sequoia 15.5 (24F74)

**Output of `bazel version`:**

  

bazel version
Bazelisk version: 1.26.0
Build label: 8.3.1
Build target: @@//src/main/java/com/google/devtools/build/lib/bazel:BazelServer
Build time: Mon Jun 30 16:26:17 2025 (1751300777)
Build timestamp: 1751300777
Build timestamp as int: 1751300777

**Rules_python version:**

https://github.com/bazel-contrib/rules_python/commit/39703fa18135fae3bcc458490a0b8266ca85e513

**Anything else relevant?**

N/A

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Start with the linked minimal reproduction, especially the directives in jax/BUILD.bazel and numpy/BUILD.bazel, then run bazel run //:gazelle to reproduce the dependency errors. Done means python_manifest_file_name directives in subdirectories are applied to their targets and the generated dependencies validate without these errors.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
build-system
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
45/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.