Skip to content

Commit

Permalink
make python conditional
Browse files Browse the repository at this point in the history
  • Loading branch information
thesayyn committed Sep 24, 2024
1 parent 24a56c6 commit f362963
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 6 deletions.
24 changes: 24 additions & 0 deletions gazelle/python/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
],
}),
)
13 changes: 13 additions & 0 deletions gazelle/python/unix.go
Original file line number Diff line number Diff line change
@@ -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()
}
15 changes: 15 additions & 0 deletions gazelle/python/windows.go
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion pkg/aspect/configure/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ go_library(
"//gazelle/bzl",
"//gazelle/js",
"//gazelle/kotlin",
"//gazelle/python",
"//pkg/aspect/configure/internal/wspace",
"//pkg/aspecterrors",
"//pkg/ioutils",
Expand All @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions pkg/aspect/configure/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit f362963

Please sign in to comment.