GeezerVison is showing github.com — refactor: use gazelle for bzl_library management (#3852) · bookingcom/rules_python@de6ca1b
File treeExpand file treeCollapse file tree Open diff view settings tests/config_settings/transition build_defs/python/private
Some content is hiddenLarge Commits have some content hidden by default. Use the searchbox below for content that may be hidden. Dismiss bannerExpand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboard +8Lines changed: 8 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +--- | | 2 | +trigger: always_on | | 3 | +--- | | 4 | + | | 5 | +# When to Use Copyright | | 6 | + | | 7 | +Unless directed by the user otherwise, do not add Bazel copyright to new or | | 8 | +existing files. |
Collapse file Copy file name to clipboard +56Lines changed: 56 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +--- | | 2 | +name: rule-creator | | 3 | +description: Create and format agent rules with proper front matter in the workspace | | 4 | +--- | | 5 | + | | 6 | +Use this skill when you need to create a new rule for the agent in the | | 7 | +workspace. | | 8 | + | | 9 | +### Rule File Location | | 10 | + | | 11 | +All workspace-specific rules must be created as individual Markdown files under | | 12 | +the `.agents/rules/` directory: | | 13 | +``` | | 14 | +.agents/rules/<rule-name>.md | | 15 | +``` | | 16 | + | | 17 | +### Rule Format | | 18 | + | | 19 | +Every rule file must start with a YAML front matter block defining the trigger | | 20 | +condition, followed by the rule content in Markdown. | | 21 | + | | 22 | +```yaml | | 23 | +--- | | 24 | +trigger: <trigger-condition> | | 25 | +--- | | 26 | + | | 27 | +# <Rule Title> | | 28 | + | | 29 | +<Rule description and directives...> | | 30 | +``` | | 31 | + | | 32 | +#### Trigger Conditions | | 33 | +* `always_on`: The rule is always active and must be followed for all tasks. | | 34 | +* Custom triggers: You can specify other trigger conditions if the rule only | | 35 | + applies in certain contexts. | | 36 | + | | 37 | +### Formatting Guidelines | | 38 | +* **Line Wrapping:** Always wrap all text in the rule file (including the | | 39 | + title and description) to **80 columns** to ensure readability and | | 40 | + compatibility. | | 41 | +* **Clarity:** Write clear, actionable directives. | | 42 | + | | 43 | +### Example | | 44 | + | | 45 | +To create a rule that prevents adding copyrights: | | 46 | + | | 47 | +```markdown | | 48 | +--- | | 49 | +trigger: always_on | | 50 | +--- | | 51 | + | | 52 | +# No Copyrights Rule | | 53 | + | | 54 | +Unless directed by the user otherwise, do not add Bazel copyright to new or | | 55 | +existing files. | | 56 | +``` |
Collapse file Copy file name to clipboardExpand all lines: .pre-commit-config.yaml +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 65 | 65 | entry: ./tools/private/sync_downloader_configs.py | 66 | 66 | files: downloader_config\.cfg$ | 67 | 67 | pass_filenames: false | | 68 | + - id: gazelle | | 69 | + name: Run Gazelle | | 70 | + language: system | | 71 | + entry: bazel run //tools/private/gazelle | | 72 | + files: (\.bzl|\.bazel|BUILD|WORKSPACE(\.bzlmod)?)$ | | 73 | + pass_filenames: false |
Collapse file Copy file name to clipboardExpand all lines: BUILD.bazel +41-6Lines changed: 41 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 14 | 14 |
| 15 | 15 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") | 16 | 16 |
| | 17 | +# Resolve rules_cc Starlark libraries to their correct targets | | 18 | +# gazelle:resolve starlark @rules_cc//cc/common:cc_info.bzl @rules_cc//cc/common:common | | 19 | +# gazelle:resolve starlark @rules_cc//cc/common:cc_common.bzl @rules_cc//cc/common:common | | 20 | + | | 21 | +# Resolve protobuf Starlark libraries | | 22 | +# gazelle:resolve starlark @com_google_protobuf//bazel:py_proto_library.bzl @com_google_protobuf//bazel:py_proto_library_bzl | | 23 | + | | 24 | +# Resolve bazel_tools repo rules to our internal wrapper to avoid transitive dependencies | | 25 | +# gazelle:resolve starlark @bazel_tools//tools/build_defs/repo:http.bzl //python/private:bazel_tools | | 26 | +# gazelle:resolve starlark @bazel_tools//tools/build_defs/repo:utils.bzl //python/private:bazel_tools | | 27 | + | | 28 | +# Prevent Gazelle from incorrectly stripping the .bzl suffix from the toml.bzl repo name | | 29 | +# gazelle:resolve starlark @toml.bzl//:toml.bzl @toml.bzl//:toml | | 30 | + | | 31 | +# Override Gazelle's incorrect default resolution for platforms host constraints Starlark library | | 32 | +# gazelle:resolve starlark @platforms//host:constraints.bzl @platforms//host:constraints_lib | | 33 | + | | 34 | +# Override Gazelle's incorrect default resolution for rules_cc Starlark libraries | | 35 | +# gazelle:resolve starlark @rules_cc//cc:cc_import.bzl @rules_cc//cc:core_rules | | 36 | +# gazelle:resolve starlark @rules_cc//cc:cc_library.bzl @rules_cc//cc:core_rules | | 37 | + | | 38 | +# Exclude directories that are separate packages/workspaces or only for testing/examples | | 39 | +# gazelle:exclude tests | | 40 | +# gazelle:exclude examples | | 41 | + | | 42 | +# Exclude internal development tools and dependencies that users don't need | | 43 | +# gazelle:exclude internal_dev_setup.bzl | | 44 | +# gazelle:exclude internal_dev_deps.bzl | | 45 | +# gazelle:exclude python/private/internal_dev_deps.bzl | | 46 | +# gazelle:exclude workspace_bazel9.bzl | | 47 | + | | 48 | +# Exclude legacy paths that are only kept for backwards compatibility | | 49 | +# gazelle:exclude python/private/common | | 50 | + | 17 | 51 | package(default_visibility = ["//visibility:public"]) | 18 | 52 |
| 19 | 53 | licenses(["notice"]) | @@ -52,12 +86,6 @@ filegroup( | 52 | 86 | ], | 53 | 87 | ) | 54 | 88 |
| 55 | | -bzl_library( | 56 | | - name = "version_bzl", | 57 | | - srcs = ["version.bzl"], | 58 | | - visibility = ["//:__subpackages__"], | 59 | | -) | 60 | | - | 61 | 89 | # Reexport of all bzl files used to allow downstream rules to generate docs | 62 | 90 | # without shipping with a dependency on Skylib | 63 | 91 | filegroup( | @@ -73,3 +101,10 @@ filegroup( | 73 | 101 | ], | 74 | 102 | visibility = ["//visibility:public"], | 75 | 103 | ) | | 104 | + | | 105 | +# keep | | 106 | +bzl_library( | | 107 | + name = "version", | | 108 | + srcs = ["version.bzl"], | | 109 | + visibility = ["//:__subpackages__"], | | 110 | +) |
Collapse file Copy file name to clipboardExpand all lines: MODULE.bazel +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -96,6 +96,8 @@ bazel_dep(name = "another_module", version = "0", dev_dependency = True) | 96 | 96 | # Extra gazelle plugin deps so that WORKSPACE.bzlmod can continue including it for e2e tests. | 97 | 97 | # We use `WORKSPACE.bzlmod` because it is impossible to have dev-only local overrides. | 98 | 98 | bazel_dep(name = "rules_go", version = "0.60.0", dev_dependency = True, repo_name = "io_bazel_rules_go") | | 99 | +bazel_dep(name = "gazelle", version = "0.40.0", dev_dependency = True, repo_name = "bazel_gazelle") | | 100 | +bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.8.2", dev_dependency = True) | 99 | 101 |
| 100 | 102 | internal_dev_deps = use_extension( | 101 | 103 | "//python/private:internal_dev_deps.bzl", | |
Collapse file Copy file name to clipboardExpand all lines: WORKSPACE +4-7Lines changed: 4 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -17,13 +17,10 @@ workspace(name = "rules_python") | 17 | 17 | # Everything below this line is used only for developing rules_python. Users | 18 | 18 | # should not copy it to their WORKSPACE. | 19 | 19 |
| 20 | | -# Necessary so that Bazel 9 recognizes this as rules_python and doesn't try | 21 | | -# to load the version Bazel itself uses by default. | 22 | | -# buildifier: disable=duplicated-name | 23 | | -local_repository( | 24 | | - name = "rules_python", | 25 | | - path = ".", | 26 | | -) | | 20 | +# Workaround for Bazel 9 duplicate name issue in Gazelle. | | 21 | +load("//:workspace_bazel9.bzl", "bazel_9_workaround") | | 22 | + | | 23 | +bazel_9_workaround() | 27 | 24 |
| 28 | 25 | load("//:internal_dev_deps.bzl", "rules_python_internal_deps") | 29 | 26 |
| |
Collapse file Copy file name to clipboardExpand all lines: docs/BUILD.bazel +52-52Lines changed: 52 additions & 52 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -106,59 +106,59 @@ build_test( | 106 | 106 | sphinx_stardocs( | 107 | 107 | name = "bzl_api_docs", | 108 | 108 | srcs = [ | 109 | | - "//python:defs_bzl", | 110 | | - "//python:features_bzl", | 111 | | - "//python:packaging_bzl", | 112 | | - "//python:pip_bzl", | 113 | | - "//python:proto_bzl", | 114 | | - "//python:py_binary_bzl", | 115 | | - "//python:py_cc_link_params_info_bzl", | 116 | | - "//python:py_exec_tools_info_bzl", | 117 | | - "//python:py_exec_tools_toolchain_bzl", | 118 | | - "//python:py_executable_info_bzl", | 119 | | - "//python:py_info_bzl", | 120 | | - "//python:py_library_bzl", | 121 | | - "//python:py_runtime_bzl", | 122 | | - "//python:py_runtime_info_bzl", | 123 | | - "//python:py_test_bzl", | 124 | | - "//python:repositories_bzl", | 125 | | - "//python/api:api_bzl", | 126 | | - "//python/api:attr_builders_bzl", | 127 | | - "//python/api:executables_bzl", | 128 | | - "//python/api:libraries_bzl", | 129 | | - "//python/api:rule_builders_bzl", | 130 | | - "//python/cc:py_cc_toolchain_bzl", | 131 | | - "//python/cc:py_cc_toolchain_info_bzl", | 132 | | - "//python/entry_points:py_console_script_binary_bzl", | 133 | | - "//python/extensions:config_bzl", | 134 | | - "//python/extensions:python_bzl", | 135 | | - "//python/local_toolchains:repos_bzl", | 136 | | - "//python/private:attr_builders_bzl", | 137 | | - "//python/private:builders_bzl", | 138 | | - "//python/private:builders_util_bzl", | 139 | | - "//python/private:py_binary_rule_bzl", | 140 | | - "//python/private:py_cc_toolchain_rule_bzl", | 141 | | - "//python/private:py_info_bzl", | 142 | | - "//python/private:py_library_rule_bzl", | 143 | | - "//python/private:py_runtime_rule_bzl", | 144 | | - "//python/private:py_test_rule_bzl", | 145 | | - "//python/private:rule_builders_bzl", | 146 | | - "//python/private/api:py_common_api_bzl", | 147 | | - "//python/private/pypi:config_settings_bzl", | 148 | | - "//python/private/pypi:env_marker_info_bzl", | 149 | | - "//python/private/pypi:pkg_aliases_bzl", | 150 | | - "//python/private/pypi:whl_config_setting_bzl", | 151 | | - "//python/private/pypi:whl_library_bzl", | 152 | | - "//python/private/zipapp:py_zipapp_rule_bzl", | 153 | | - "//python/uv:lock_bzl", | 154 | | - "//python/uv:uv_bzl", | 155 | | - "//python/uv:uv_toolchain_bzl", | 156 | | - "//python/uv:uv_toolchain_info_bzl", | 157 | | - "//python/zipapp:py_zipapp_binary_bzl", | 158 | | - "//python/zipapp:py_zipapp_test_bzl", | | 109 | + "//python:defs", | | 110 | + "//python:features", | | 111 | + "//python:packaging", | | 112 | + "//python:pip", | | 113 | + "//python:proto", | | 114 | + "//python:py_binary", | | 115 | + "//python:py_cc_link_params_info", | | 116 | + "//python:py_exec_tools_info", | | 117 | + "//python:py_exec_tools_toolchain", | | 118 | + "//python:py_executable_info", | | 119 | + "//python:py_info", | | 120 | + "//python:py_library", | | 121 | + "//python:py_runtime", | | 122 | + "//python:py_runtime_info", | | 123 | + "//python:py_test", | | 124 | + "//python:repositories", | | 125 | + "//python/api", | | 126 | + "//python/api:attr_builders", | | 127 | + "//python/api:executables", | | 128 | + "//python/api:libraries", | | 129 | + "//python/api:rule_builders", | | 130 | + "//python/cc:py_cc_toolchain", | | 131 | + "//python/cc:py_cc_toolchain_info", | | 132 | + "//python/entry_points:py_console_script_binary", | | 133 | + "//python/extensions:config", | | 134 | + "//python/extensions:python", | | 135 | + "//python/local_toolchains:repos", | | 136 | + "//python/private:attr_builders", | | 137 | + "//python/private:builders", | | 138 | + "//python/private:builders_util", | | 139 | + "//python/private:py_binary_rule", | | 140 | + "//python/private:py_cc_toolchain_rule", | | 141 | + "//python/private:py_info", | | 142 | + "//python/private:py_library_rule", | | 143 | + "//python/private:py_runtime_rule", | | 144 | + "//python/private:py_test_rule", | | 145 | + "//python/private:rule_builders", | | 146 | + "//python/private/api:py_common_api", | | 147 | + "//python/private/pypi:config_settings", | | 148 | + "//python/private/pypi:env_marker_info", | | 149 | + "//python/private/pypi:pkg_aliases", | | 150 | + "//python/private/pypi:whl_config_setting", | | 151 | + "//python/private/pypi:whl_library", | | 152 | + "//python/private/zipapp:py_zipapp_rule", | | 153 | + "//python/uv", | | 154 | + "//python/uv:lock", | | 155 | + "//python/uv:uv_toolchain", | | 156 | + "//python/uv:uv_toolchain_info", | | 157 | + "//python/zipapp:py_zipapp_binary", | | 158 | + "//python/zipapp:py_zipapp_test", | 159 | 159 | ] + ([ | 160 | 160 | # This depends on @pythons_hub, which is only created under bzlmod, | 161 | | - "//python/extensions:pip_bzl", | | 161 | + "//python/extensions:pip", | 162 | 162 | ] if BZLMOD_ENABLED else []), | 163 | 163 | prefix = "api/rules_python/", | 164 | 164 | tags = ["docs"], | @@ -167,7 +167,7 @@ sphinx_stardocs( | 167 | 167 |
| 168 | 168 | sphinx_stardoc( | 169 | 169 | name = "py_runtime_pair", | 170 | | - src = "//python/private:py_runtime_pair_rule_bzl", | | 170 | + src = "//python/private:py_runtime_pair_rule", | 171 | 171 | prefix = "api/rules_python/", | 172 | 172 | tags = ["docs"], | 173 | 173 | target_compatible_with = _TARGET_COMPATIBLE_WITH, | |
Collapse file Copy file name to clipboardExpand all lines: gazelle/BUILD.bazel +9Lines changed: 9 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | load("@bazel_gazelle//:def.bzl", "gazelle") | | 2 | +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") | 2 | 3 |
| 3 | 4 | # Gazelle configuration options. | 4 | 5 | # See https://github.com/bazelbuild/bazel-gazelle#running-gazelle-with-bazel | 5 | 6 | # gazelle:prefix github.com/bazel-contrib/rules_python/gazelle | 6 | 7 | # gazelle:exclude bazel-out | | 8 | +# gazelle:exclude deps.bzl | | 9 | +# gazelle:exclude internal_dev_deps.bzl | 7 | 10 | gazelle( | 8 | 11 | name = "gazelle", | 9 | 12 | ) | @@ -36,3 +39,9 @@ filegroup( | 36 | 39 | ], | 37 | 40 | visibility = ["@rules_python//:__pkg__"], | 38 | 41 | ) | | 42 | + | | 43 | +bzl_library( | | 44 | + name = "def", | | 45 | + srcs = ["def.bzl"], | | 46 | + visibility = ["//visibility:public"], | | 47 | +) |
Collapse file Copy file name to clipboardExpand all lines: gazelle/manifest/BUILD.bazel +14-2Lines changed: 14 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") | 1 | 2 | load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") | 2 | 3 |
| 3 | 4 | exports_files([ | @@ -11,8 +12,8 @@ go_library( | 11 | 12 | importpath = "github.com/bazel-contrib/rules_python/gazelle/manifest", | 12 | 13 | visibility = ["//visibility:public"], | 13 | 14 | deps = [ | 14 | | - "@com_github_emirpasic_gods//sets/treeset", | 15 | | - "@in_gopkg_yaml_v2//:yaml_v2", | | 15 | + "@com_github_emirpasic_gods//sets/treeset:go_default_library", | | 16 | + "@in_gopkg_yaml_v2//:go_default_library", | 16 | 17 | ], | 17 | 18 | ) | 18 | 19 |
| @@ -32,3 +33,14 @@ filegroup( | 32 | 33 | ], | 33 | 34 | visibility = ["//:__pkg__"], | 34 | 35 | ) | | 36 | + | | 37 | +bzl_library( | | 38 | + name = "defs", | | 39 | + srcs = ["defs.bzl"], | | 40 | + visibility = ["//visibility:public"], | | 41 | + deps = [ | | 42 | + "@bazel_skylib//rules:diff_test", | | 43 | + "@io_bazel_rules_go//go:def", | | 44 | + "@rules_python//python:defs_bzl", | | 45 | + ], | | 46 | +) |
Collapse file Copy file name to clipboardExpand all lines: gazelle/modules_mapping/BUILD.bazel +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") | 1 | 2 | load("@bazel_skylib//rules:copy_file.bzl", "copy_file") | 2 | 3 | load("@rules_python//python:defs.bzl", "py_binary", "py_test") | 3 | 4 |
| @@ -56,3 +57,9 @@ filegroup( | 56 | 57 | srcs = glob(["**"]), | 57 | 58 | visibility = ["//:__pkg__"], | 58 | 59 | ) | | 60 | + | | 61 | +bzl_library( | | 62 | + name = "def", | | 63 | + srcs = ["def.bzl"], | | 64 | + visibility = ["//visibility:public"], | | 65 | +) |
|