diff --git a/gazelle/python/BUILD.bazel b/gazelle/python/BUILD.bazel new file mode 100644 index 000000000..23fb87958 --- /dev/null +++ b/gazelle/python/BUILD.bazel @@ -0,0 +1,24 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +config_setting( + name = "windows", + constraint_values = ["@platforms//os:windows"], +) + +go_library( + name = "python", + srcs = [ + "unix.go", + "windows.go", + ], + importpath = "aspect.build/cli/gazelle/python", + visibility = ["//visibility:public"], + deps = [ + "@bazel_gazelle//language:go_default_library", + ] + select({ + ":windows": [], + "//conditions:default": [ + "@com_github_bazelbuild_rules_python_gazelle//python", + ], + }), +) diff --git a/gazelle/python/unix.go b/gazelle/python/unix.go new file mode 100644 index 000000000..a7b2e4616 --- /dev/null +++ b/gazelle/python/unix.go @@ -0,0 +1,13 @@ +//go:build linux || darwin +// +build linux darwin + +package python + +import ( + "github.com/bazelbuild/bazel-gazelle/language" + python "github.com/bazelbuild/rules_python/gazelle/python" +) + +func NewLanguage() language.Language { + return python.NewLanguage() +} diff --git a/gazelle/python/windows.go b/gazelle/python/windows.go new file mode 100644 index 000000000..b74894424 --- /dev/null +++ b/gazelle/python/windows.go @@ -0,0 +1,15 @@ +//go:build windows +// +build windows + +package python + +import ( + "log" + + "github.com/bazelbuild/bazel-gazelle/language" +) + +func NewLanguage() language.Language { + log.Fatalln("Python extension is not supported on Windows.\nSee: https://github.com/aspect-build/aspect-cli/issues/747") + return nil +} diff --git a/pkg/aspect/configure/BUILD.bazel b/pkg/aspect/configure/BUILD.bazel index 82dc6b65b..ed3dcbdee 100644 --- a/pkg/aspect/configure/BUILD.bazel +++ b/pkg/aspect/configure/BUILD.bazel @@ -18,6 +18,7 @@ go_library( "//gazelle/bzl", "//gazelle/js", "//gazelle/kotlin", + "//gazelle/python", "//pkg/aspect/configure/internal/wspace", "//pkg/aspecterrors", "//pkg/ioutils", @@ -33,7 +34,6 @@ go_library( "@bazel_gazelle//rule:go_default_library", "@bazel_gazelle//walk:go_default_library", "@com_github_bazelbuild_buildtools//build:go_default_library", - # "@com_github_bazelbuild_rules_python_gazelle//python", "@com_github_pmezard_go_difflib//difflib", "@com_github_spf13_cobra//:cobra", "@com_github_spf13_viper//:viper", diff --git a/pkg/aspect/configure/configure.go b/pkg/aspect/configure/configure.go index 93d73db99..e374698c8 100644 --- a/pkg/aspect/configure/configure.go +++ b/pkg/aspect/configure/configure.go @@ -26,12 +26,12 @@ import ( bzl "aspect.build/cli/gazelle/bzl" js "aspect.build/cli/gazelle/js" kotlin "aspect.build/cli/gazelle/kotlin" + python "aspect.build/cli/gazelle/python" "aspect.build/cli/pkg/aspecterrors" "aspect.build/cli/pkg/ioutils" "github.com/bazelbuild/bazel-gazelle/language" golang "github.com/bazelbuild/bazel-gazelle/language/go" "github.com/bazelbuild/bazel-gazelle/language/proto" - // python "github.com/bazelbuild/rules_python/gazelle/python" "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -93,10 +93,10 @@ func (c *Configure) addDefaultLanguages() { c.AddLanguage("bzl", bzl.NewLanguage) } - // viper.SetDefault("configure.languages.python", false) - // if viper.GetBool("configure.languages.python") { - // c.AddLanguage("python", python.NewLanguage) - // } + viper.SetDefault("configure.languages.python", false) + if viper.GetBool("configure.languages.python") { + c.AddLanguage("python", python.NewLanguage) + } } func (runner *Configure) Run(_ context.Context, cmd *cobra.Command, args []string) error {