Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(gazelle): Move plugin to a separate directory. #983

Merged
merged 1 commit into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
73 changes: 5 additions & 68 deletions gazelle/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,76 +1,12 @@
load("@bazel_gazelle//:def.bzl", "gazelle_binary")
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("@rules_python//python:defs.bzl", "py_binary")

go_library(
alias(
name = "gazelle",
srcs = [
"configure.go",
"fix.go",
"generate.go",
"kinds.go",
"language.go",
"parser.go",
"resolve.go",
"std_modules.go",
"target.go",
],
data = [
":parse",
":std_modules",
],
importpath = "github.com/bazelbuild/rules_python/gazelle",
visibility = ["//visibility:public"],
deps = [
"//gazelle/manifest",
"//gazelle/pythonconfig",
"@bazel_gazelle//config:go_default_library",
"@bazel_gazelle//label:go_default_library",
"@bazel_gazelle//language:go_default_library",
"@bazel_gazelle//repo:go_default_library",
"@bazel_gazelle//resolve:go_default_library",
"@bazel_gazelle//rule:go_default_library",
"@com_github_bazelbuild_buildtools//build:go_default_library",
"@com_github_bmatcuk_doublestar//:doublestar",
"@com_github_emirpasic_gods//lists/singlylinkedlist",
"@com_github_emirpasic_gods//sets/treeset",
"@com_github_emirpasic_gods//utils",
"@com_github_google_uuid//:uuid",
"@io_bazel_rules_go//go/tools/bazel:go_default_library",
],
)

py_binary(
name = "parse",
srcs = ["parse.py"],
actual = "//gazelle/python",
visibility = ["//visibility:public"],
)

py_binary(
name = "std_modules",
srcs = ["std_modules.py"],
visibility = ["//visibility:public"],
)

go_test(
name = "gazelle_test",
srcs = ["python_test.go"],
data = [
":gazelle_python_binary",
":parse",
":std_modules",
] + 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",
],
)

gazelle_binary(
alias(
name = "gazelle_python_binary",
languages = ["//gazelle"],
actual = "//gazelle/python:gazelle_binary",
visibility = ["//visibility:public"],
)

Expand All @@ -79,6 +15,7 @@ filegroup(
srcs = glob(["**"]) + [
"//gazelle/manifest:distribution",
"//gazelle/modules_mapping:distribution",
"//gazelle/python:distribution",
"//gazelle/pythonconfig:distribution",
],
visibility = ["//:__pkg__"],
Expand Down
4 changes: 2 additions & 2 deletions gazelle/def.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"""

GAZELLE_PYTHON_RUNTIME_DEPS = [
"@rules_python//gazelle:parse",
"@rules_python//gazelle:std_modules",
"@rules_python//gazelle/python:parse",
"@rules_python//gazelle/python:std_modules",
]
81 changes: 81 additions & 0 deletions gazelle/python/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
load("@bazel_gazelle//:def.bzl", "gazelle_binary")
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("@rules_python//python:defs.bzl", "py_binary")

go_library(
name = "python",
srcs = [
"configure.go",
"fix.go",
"generate.go",
"kinds.go",
"language.go",
"parser.go",
"resolve.go",
"std_modules.go",
"target.go",
],
data = [
":parse",
":std_modules",
],
importpath = "github.com/bazelbuild/rules_python/gazelle/python",
visibility = ["//visibility:public"],
deps = [
"//gazelle/manifest",
"//gazelle/pythonconfig",
"@bazel_gazelle//config:go_default_library",
"@bazel_gazelle//label:go_default_library",
"@bazel_gazelle//language:go_default_library",
"@bazel_gazelle//repo:go_default_library",
"@bazel_gazelle//resolve:go_default_library",
"@bazel_gazelle//rule:go_default_library",
"@com_github_bazelbuild_buildtools//build:go_default_library",
"@com_github_bmatcuk_doublestar//:doublestar",
"@com_github_emirpasic_gods//lists/singlylinkedlist",
"@com_github_emirpasic_gods//sets/treeset",
"@com_github_emirpasic_gods//utils",
"@com_github_google_uuid//:uuid",
"@io_bazel_rules_go//go/tools/bazel:go_default_library",
],
)

py_binary(
name = "parse",
srcs = ["parse.py"],
visibility = ["//visibility:public"],
)

py_binary(
name = "std_modules",
srcs = ["std_modules.py"],
visibility = ["//visibility:public"],
)

go_test(
name = "python_test",
srcs = ["python_test.go"],
data = [
":gazelle_binary",
":parse",
":std_modules",
] + 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",
],
)

gazelle_binary(
name = "gazelle_binary",
languages = [":python"],
visibility = ["//visibility:public"],
)

filegroup(
name = "distribution",
srcs = glob(["**"]),
visibility = ["//gazelle:__pkg__"],
)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion gazelle/parser.go → gazelle/python/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var (
)

func init() {
parseScriptRunfile, err := bazel.Runfile("gazelle/parse")
parseScriptRunfile, err := bazel.Runfile("gazelle/python/parse")
if err != nil {
log.Printf("failed to initialize parser: %v\n", err)
os.Exit(1)
Expand Down
10 changes: 5 additions & 5 deletions gazelle/python_test.go → gazelle/python/python_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ import (
)

const (
extensionDir = "gazelle/"
testDataPath = extensionDir + "testdata/"
gazelleBinaryName = "gazelle_python_binary"
extensionDir = "gazelle" + string(os.PathSeparator) + "python" + string(os.PathSeparator)
testDataPath = extensionDir + "testdata" + string(os.PathSeparator)
gazelleBinaryName = "gazelle_binary"
)

var gazellePath = mustFindGazelle()
Expand All @@ -55,7 +55,7 @@ func TestGazelleBinary(t *testing.T) {
for _, f := range runfiles {
if strings.HasPrefix(f.ShortPath, testDataPath) {
relativePath := strings.TrimPrefix(f.ShortPath, testDataPath)
parts := strings.SplitN(relativePath, "/", 2)
parts := strings.SplitN(relativePath, string(os.PathSeparator), 2)
if len(parts) < 2 {
// This file is not a part of a testcase since it must be in a dir that
// is the test case and then have a path inside of that.
Expand All @@ -82,7 +82,7 @@ func testPath(t *testing.T, name string, files []bazel.RunfileEntry) {
var config *testYAML
for _, f := range files {
path := f.Path
trim := testDataPath + name + "/"
trim := filepath.Join(testDataPath, name) + string(os.PathSeparator)
shortPath := strings.TrimPrefix(f.ShortPath, trim)
info, err := os.Stat(path)
if err != nil {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion gazelle/std_modules.go → gazelle/python/std_modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var (
func init() {
stdModulesSeen = make(map[string]struct{})

stdModulesScriptRunfile, err := bazel.Runfile("gazelle/std_modules")
stdModulesScriptRunfile, err := bazel.Runfile("gazelle/python/std_modules")
if err != nil {
log.Printf("failed to initialize std_modules: %v\n", err)
os.Exit(1)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading