Skip to content

Commit

Permalink
refactor(gazelle): Move plugin to a separate directory.
Browse files Browse the repository at this point in the history
This is in order to make bazelbuild#972 easier to review. This PR is only moving
files and addressing a few small review comments made in the initial
review of bazelbuild#972.

Work towards bazelbuild#965.
  • Loading branch information
aignas committed Jan 12, 2023
1 parent 9022291 commit 75f8f60
Show file tree
Hide file tree
Showing 408 changed files with 91 additions and 81 deletions.
69 changes: 5 additions & 64 deletions gazelle/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,72 +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",
],
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 @@ -75,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",
]
77 changes: 77 additions & 0 deletions gazelle/python/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
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",
],
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 = ["//:__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.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 75f8f60

Please sign in to comment.