bazel-contrib / bazel-contrib/rules_python

Add a new python comment annotation that adds targets to `data`

Open
#1,865 4 comments 0 reactions 0 assignees View on GitHub
gazelle help wanted type: feature request
Dominant language
Starlark
Stars
688
Forks
721
Avg merge
15h 7m
Merged PRs (30d)
76

Description

# 🚀 feature request

### Relevant Rules

+ gazelle

### Description

This is the same as #1862, but for the `data` attribute on generated targets.

### Describe the solution you'd like

```python
# foo/bar/baz_test.py
import pathlib

# gazelle:include_data //foo/bar:test_data
TEST_DATA_DIR = pathlib.Path(__file__).parent / "test_data"

def test_main():
assert TEST_DATA_DIR.exists()
```

Running Gazelle generates:

```starlark
py_test(
name = "baz_test",
srcs = ["baz_test.py"],
data = ["//foo/bar:test_data"],
)
```

Note that Gazelle does _**not**_ generate the `test_data` target - it's still on the user to do that themselves.

### Describe alternatives you've considered

The current method is to manually add `data` attributes.

Contributor guide

Open the contributing guide

Research direction

Start by reading the related issue #1862 and the Gazelle implementation for existing Python comment annotations. Trace how annotations affect generated targets, then add the corresponding handling for `# gazelle:include_data` so the `data` attribute contains the requested label without generating the target. Done means the example produces the shown `py_test` output and existing behavior remains intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
build-system, tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.