Skip to content

Commit

Permalink
Update README with a Gazelle how-to
Browse files Browse the repository at this point in the history
  • Loading branch information
wingsofovnia committed Nov 11, 2024
1 parent cb3f627 commit 600703e
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,71 @@ A `pip install` operation can be roughly broken down into these parts:
provides it as a `py_library`.

See the [generated docs](docs).

### Gazelle Plugin
`rules_pycross` is compatible with `rules_python_gazelle_plugin`, a plugin for [Gazelle](https://github.com/bazelbuild/bazel-gazelle)
that generates BUILD files content for `rules_python` rules, but requires additional configuration.

`rules_python_gazelle_plugin` is originally designed for `rules_python` rules that uses custom name normalization, whereas
`rules_pycross` uses the Python [name normalization](https://packaging.python.org/en/latest/specifications/name-normalization/).

To switch name normalization, use the following Gazelle [directives](https://github.com/bazelbuild/rules_python/blob/main/gazelle/README.md#directives):
```
# gazelle:python_label_convention :$distribution_name$
# gazelle:python_label_normalization pep503
```

Other than these options, the configuration is identical to a setup with `rules_python`.
Read more [here](https://github.com/bazelbuild/rules_python/blob/main/gazelle/README.md#directives).

<details>
<summary>Example BUILD.bazel</summary>

```
load("@gazelle//:def.bzl", "DEFAULT_LANGUAGES", "gazelle", "gazelle_binary")
load("@pip//:requirements.bzl", "all_whl_requirements")
load("@rules_python_gazelle_plugin//manifest:defs.bzl", "gazelle_python_manifest")
load("@rules_python_gazelle_plugin//modules_mapping:def.bzl", "modules_mapping")
# gazelle:python_root
# gazelle:python_label_convention :$distribution_name$
# gazelle:python_label_normalization pep503
gazelle_binary(
name = "gazelle_bin",
languages = DEFAULT_LANGUAGES + [
"@rules_python_gazelle_plugin//python",
],
)
gazelle(
name = "gazelle.update",
gazelle = ":gazelle_bin",
)
gazelle(
name = "gazelle.check",
args = ["-mode=diff"],
gazelle = ":gazelle_bin",
)
modules_mapping(
name = "gazelle.metadata",
tags = ["manual"],
wheels = all_whl_requirements,
)
gazelle_python_manifest(
name = "gazelle.mapping",
modules_mapping = ":gazelle.metadata",
pip_repository_name = "pip",
tags = ["manual"],
)
```

###### Useful Commands
```
> bazel run //:gazelle.update # Update gazelle_python.yaml used by Gazelle
> bazel run //:gazelle.check # Show changes needed to build scripts per Gazelle
> bazel run //:gazelle.update # Apply changes needed to build scripts per Gazelle
```
</details>

0 comments on commit 600703e

Please sign in to comment.