aboutsummaryrefslogtreecommitdiff
path: root/gazelle
diff options
context:
space:
mode:
authorIgnas Anikevicius <ignas.anikevicius@woven-planet.global>2023-03-06 10:33:30 +0900
committerGitHub <noreply@github.com>2023-03-05 17:33:30 -0800
commit7d82f06e7ba1cf217c6d855cd5ffbb3b6598587c (patch)
treee5edaea4d02f1b8d25e9dbaeeff1fcb6683ee0f8 /gazelle
parent51458e88f7223d8d7db282018f085828e9a5a312 (diff)
downloadbazelbuild-rules_python-7d82f06e7ba1cf217c6d855cd5ffbb3b6598587c.tar.gz
feat: add bzlmod support for gazelle plugin (#1077)
* feat: add optional pkg alias generation to pip_repository * feat: support using aliases in gazelle * doc: migrate gazelle example to use user friendly aliases * feat: gazelle supports bzlmod * chore: update gazelle plugin deps * chore: bazel run //:gazelle * fix: remove deps that are imported as bazel deps See: bazelbuild/bazel-gazelle#1403 * ci: add build_file_generation to show that we support bzlmod
Diffstat (limited to 'gazelle')
-rw-r--r--gazelle/MODULE.bazel20
-rw-r--r--gazelle/deps.bzl57
-rw-r--r--gazelle/go.mod2
-rw-r--r--gazelle/manifest/defs.bzl11
-rw-r--r--gazelle/manifest/generate/generate.go23
-rw-r--r--gazelle/manifest/manifest.go3
-rw-r--r--gazelle/python/BUILD.bazel1
-rw-r--r--gazelle/pythonconfig/pythonconfig.go10
8 files changed, 70 insertions, 57 deletions
diff --git a/gazelle/MODULE.bazel b/gazelle/MODULE.bazel
new file mode 100644
index 0000000..bd63402
--- /dev/null
+++ b/gazelle/MODULE.bazel
@@ -0,0 +1,20 @@
+module(
+ name = "rules_python_gazelle_plugin",
+ version = "0.0.0",
+ compatibility_level = 1,
+)
+
+bazel_dep(name = "rules_python", version = "0.18.0")
+bazel_dep(name = "rules_go", version = "0.38.1", repo_name = "io_bazel_rules_go")
+bazel_dep(name = "gazelle", version = "0.29.0", repo_name = "bazel_gazelle")
+
+go_deps = use_extension("@bazel_gazelle//:extensions.bzl", "go_deps")
+go_deps.from_file(go_mod = "//:go.mod")
+use_repo(
+ go_deps,
+ "com_github_bazelbuild_buildtools",
+ "com_github_bmatcuk_doublestar",
+ "com_github_emirpasic_gods",
+ "com_github_ghodss_yaml",
+ "in_gopkg_yaml_v2",
+)
diff --git a/gazelle/deps.bzl b/gazelle/deps.bzl
index 3579443..26f8c66 100644
--- a/gazelle/deps.bzl
+++ b/gazelle/deps.bzl
@@ -28,12 +28,7 @@ def gazelle_deps():
sum = "h1:/hemPrYIhOhy8zYrNj+069zDB68us2sMGsfkFJO0iZs=",
version = "v0.0.0-20190523083050-ea95bdfd59fc",
)
- go_repository(
- name = "com_github_bazelbuild_bazel_gazelle",
- importpath = "github.com/bazelbuild/bazel-gazelle",
- sum = "h1:+/ZhUxlDy4XnyMIGeKkbRZoIGssy1eO51GijwIvvuwE=",
- version = "v0.27.0",
- )
+
go_repository(
name = "com_github_bazelbuild_buildtools",
build_naming_convention = "go_default_library",
@@ -41,24 +36,14 @@ def gazelle_deps():
sum = "h1:jhiMzJ+8unnLRtV8rpbWBFE9pFNzIqgUTyZU5aA++w8=",
version = "v0.0.0-20221004120235-7186f635531b",
)
- go_repository(
- name = "com_github_bazelbuild_rules_go",
- importpath = "github.com/bazelbuild/rules_go",
- sum = "h1:ViPR65vOrg74JKntAUFY6qZkheBKGB6to7wFd8gCRU4=",
- version = "v0.35.0",
- )
+
go_repository(
name = "com_github_bmatcuk_doublestar",
importpath = "github.com/bmatcuk/doublestar",
sum = "h1:gPypJ5xD31uhX6Tf54sDPUOBXTqKH4c9aPY66CyQrS0=",
version = "v1.3.4",
)
- go_repository(
- name = "com_github_bmatcuk_doublestar_v4",
- importpath = "github.com/bmatcuk/doublestar/v4",
- sum = "h1:Qu+u9wR3Vd89LnlLMHvnZ5coJMWKQamqdz9/p5GNthA=",
- version = "v4.2.0",
- )
+
go_repository(
name = "com_github_burntsushi_toml",
importpath = "github.com/BurntSushi/toml",
@@ -113,12 +98,7 @@ def gazelle_deps():
sum = "h1:EQciDnbrYxy13PgWoY8AqoxGiPrpgBZ1R8UNe3ddc+A=",
version = "v0.1.0",
)
- go_repository(
- name = "com_github_fsnotify_fsnotify",
- importpath = "github.com/fsnotify/fsnotify",
- sum = "h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI=",
- version = "v1.5.4",
- )
+
go_repository(
name = "com_github_ghodss_yaml",
importpath = "github.com/ghodss/yaml",
@@ -134,14 +114,14 @@ def gazelle_deps():
go_repository(
name = "com_github_golang_mock",
importpath = "github.com/golang/mock",
- sum = "h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=",
- version = "v1.6.0",
+ sum = "h1:G5FRp8JnTd7RQH5kemVNlMeyXQAztQ3mOWV95KxsXH8=",
+ version = "v1.1.1",
)
go_repository(
name = "com_github_golang_protobuf",
importpath = "github.com/golang/protobuf",
- sum = "h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=",
- version = "v1.5.2",
+ sum = "h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM=",
+ version = "v1.4.3",
)
go_repository(
name = "com_github_google_go_cmp",
@@ -149,18 +129,7 @@ def gazelle_deps():
sum = "h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=",
version = "v0.5.9",
)
- go_repository(
- name = "com_github_pelletier_go_toml",
- importpath = "github.com/pelletier/go-toml",
- sum = "h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8=",
- version = "v1.9.5",
- )
- go_repository(
- name = "com_github_pmezard_go_difflib",
- importpath = "github.com/pmezard/go-difflib",
- sum = "h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=",
- version = "v1.0.0",
- )
+
go_repository(
name = "com_github_prometheus_client_model",
importpath = "github.com/prometheus/client_model",
@@ -218,8 +187,8 @@ def gazelle_deps():
go_repository(
name = "org_golang_google_protobuf",
importpath = "google.golang.org/protobuf",
- sum = "h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=",
- version = "v1.28.0",
+ sum = "h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c=",
+ version = "v1.25.0",
)
go_repository(
name = "org_golang_x_crypto",
@@ -260,8 +229,8 @@ def gazelle_deps():
go_repository(
name = "org_golang_x_sync",
importpath = "golang.org/x/sync",
- sum = "h1:0SH2R3f1b1VmIMG7BXbEZCBUu2dKmHschSmjqGUrW8A=",
- version = "v0.0.0-20220907140024-f12130a52804",
+ sum = "h1:uVc8UZUe6tr40fFVnUP5Oj+veunVezqYl9z7DYw9xzw=",
+ version = "v0.0.0-20220722155255-886fb9371eb4",
)
go_repository(
name = "org_golang_x_sys",
diff --git a/gazelle/go.mod b/gazelle/go.mod
index 6d6f033..94f19e8 100644
--- a/gazelle/go.mod
+++ b/gazelle/go.mod
@@ -3,9 +3,7 @@ module github.com/bazelbuild/rules_python/gazelle
go 1.19
require (
- github.com/bazelbuild/bazel-gazelle v0.27.0
github.com/bazelbuild/buildtools v0.0.0-20221004120235-7186f635531b
- github.com/bazelbuild/rules_go v0.35.0
github.com/bmatcuk/doublestar v1.3.4
github.com/emirpasic/gods v1.18.1
github.com/ghodss/yaml v1.0.0
diff --git a/gazelle/manifest/defs.bzl b/gazelle/manifest/defs.bzl
index 78e0c27..05562a1 100644
--- a/gazelle/manifest/defs.bzl
+++ b/gazelle/manifest/defs.bzl
@@ -24,13 +24,16 @@ def gazelle_python_manifest(
modules_mapping,
pip_repository_name = "",
pip_deps_repository_name = "",
- manifest = ":gazelle_python.yaml"):
+ manifest = ":gazelle_python.yaml",
+ use_pip_repository_aliases = False):
"""A macro for defining the updating and testing targets for the Gazelle manifest file.
Args:
name: the name used as a base for the targets.
requirements: the target for the requirements.txt file.
pip_repository_name: the name of the pip_install or pip_repository target.
+ use_pip_repository_aliases: boolean flag to enable using user-friendly
+ python package aliases.
pip_deps_repository_name: deprecated - the old pip_install target name.
modules_mapping: the target for the generated modules_mapping.json file.
manifest: the target for the Gazelle manifest file.
@@ -67,6 +70,12 @@ def gazelle_python_manifest(
update_target_label,
]
+ if use_pip_repository_aliases:
+ update_args += [
+ "--use-pip-repository-aliases",
+ "true",
+ ]
+
go_binary(
name = update_target,
embed = [Label("//manifest/generate:generate_lib")],
diff --git a/gazelle/manifest/generate/generate.go b/gazelle/manifest/generate/generate.go
index 0f429f8..1f56e63 100644
--- a/gazelle/manifest/generate/generate.go
+++ b/gazelle/manifest/generate/generate.go
@@ -38,12 +38,15 @@ func init() {
}
func main() {
- var manifestGeneratorHashPath string
- var requirementsPath string
- var pipRepositoryName string
- var modulesMappingPath string
- var outputPath string
- var updateTarget string
+ var (
+ manifestGeneratorHashPath string
+ requirementsPath string
+ pipRepositoryName string
+ usePipRepositoryAliases bool
+ modulesMappingPath string
+ outputPath string
+ updateTarget string
+ )
flag.StringVar(
&manifestGeneratorHashPath,
"manifest-generator-hash",
@@ -60,6 +63,11 @@ func main() {
"pip-repository-name",
"",
"The name of the pip_install or pip_repository target.")
+ flag.BoolVar(
+ &usePipRepositoryAliases,
+ "use-pip-repository-aliases",
+ false,
+ "Whether to use the pip-repository aliases, which are generated when passing 'incompatible_generate_aliases = True'.")
flag.StringVar(
&modulesMappingPath,
"modules-mapping",
@@ -103,7 +111,8 @@ func main() {
manifestFile := manifest.NewFile(&manifest.Manifest{
ModulesMapping: modulesMapping,
PipRepository: &manifest.PipRepository{
- Name: pipRepositoryName,
+ Name: pipRepositoryName,
+ UsePipRepositoryAliases: usePipRepositoryAliases,
},
})
if err := writeOutput(
diff --git a/gazelle/manifest/manifest.go b/gazelle/manifest/manifest.go
index bb48264..c49951d 100644
--- a/gazelle/manifest/manifest.go
+++ b/gazelle/manifest/manifest.go
@@ -144,4 +144,7 @@ type Manifest struct {
type PipRepository struct {
// The name of the pip_install or pip_repository target.
Name string
+ // UsePipRepositoryAliases allows to use aliases generated pip_repository
+ // when passing incompatible_generate_aliases = True.
+ UsePipRepositoryAliases bool `yaml:"use_pip_repository_aliases,omitempty"`
}
diff --git a/gazelle/python/BUILD.bazel b/gazelle/python/BUILD.bazel
index 3b5ded2..ddcad27 100644
--- a/gazelle/python/BUILD.bazel
+++ b/gazelle/python/BUILD.bazel
@@ -61,7 +61,6 @@ go_test(
] + glob(["testdata/**"]),
deps = [
"@bazel_gazelle//testtools:go_default_library",
- "@com_github_emirpasic_gods//lists/singlylinkedlist",
"@com_github_ghodss_yaml//:yaml",
"@io_bazel_rules_go//go/tools/bazel:go_default_library",
],
diff --git a/gazelle/pythonconfig/pythonconfig.go b/gazelle/pythonconfig/pythonconfig.go
index a2fe7d5..ea2ae65 100644
--- a/gazelle/pythonconfig/pythonconfig.go
+++ b/gazelle/pythonconfig/pythonconfig.go
@@ -220,10 +220,16 @@ func (c *Config) FindThirdPartyDependency(modName string) (string, bool) {
}
sanitizedDistribution := strings.ToLower(distributionName)
sanitizedDistribution = strings.ReplaceAll(sanitizedDistribution, "-", "_")
- var lbl label.Label
+
+ if gazelleManifest.PipRepository != nil && gazelleManifest.PipRepository.UsePipRepositoryAliases {
+ // @<repository_name>//<distribution_name>
+ lbl := label.New(distributionRepositoryName, sanitizedDistribution, sanitizedDistribution)
+ return lbl.String(), true
+ }
+
// @<repository_name>_<distribution_name>//:pkg
distributionRepositoryName = distributionRepositoryName + "_" + sanitizedDistribution
- lbl = label.New(distributionRepositoryName, "", "pkg")
+ lbl := label.New(distributionRepositoryName, "", "pkg")
return lbl.String(), true
}
}