diff --git a/gazelle/.bazelrc b/gazelle/.bazelrc new file mode 100644 index 0000000000..f48d0a97ee --- /dev/null +++ b/gazelle/.bazelrc @@ -0,0 +1,13 @@ +test --test_output=errors + +# Do NOT implicitly create empty __init__.py files in the runfiles tree. +# By default, these are created in every directory containing Python source code +# or shared libraries, and every parent directory of those directories, +# excluding the repo root directory. With this flag set, we are responsible for +# creating (possibly empty) __init__.py files and adding them to the srcs of +# Python targets as required. +build --incompatible_default_to_explicit_init_py + +# Windows makes use of runfiles for some rules +build --enable_runfiles +startup --windows_enable_symlinks diff --git a/gazelle/.gitignore b/gazelle/.gitignore new file mode 100644 index 0000000000..8481c9668c --- /dev/null +++ b/gazelle/.gitignore @@ -0,0 +1,12 @@ +# Bazel directories +/bazel-* +/bazel-bin +/bazel-genfiles +/bazel-out +/bazel-testlogs +user.bazelrc + +# Go/Gazelle files +# These otherwise match patterns above +!go.mod +!BUILD.out diff --git a/gazelle/BUILD.bazel b/gazelle/BUILD.bazel index c24a086a50..6016145516 100644 --- a/gazelle/BUILD.bazel +++ b/gazelle/BUILD.bazel @@ -1,71 +1,35 @@ -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") +load("@bazel_gazelle//:def.bzl", "gazelle") -go_library( - 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"], - visibility = ["//visibility:public"], -) - -py_binary( - name = "std_modules", - srcs = ["std_modules.py"], - visibility = ["//visibility:public"], -) +# Gazelle configuration options. +# See https://github.com/bazelbuild/bazel-gazelle#running-gazelle-with-bazel +# gazelle:prefix github.com/bazelbuild/rules_python/gazelle +# gazelle:exclude bazel-out +gazelle(name = "gazelle") -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( + name = "gazelle_update_repos", + args = [ + "-from_file=go.mod", + "-to_macro=deps.bzl%gazelle_deps", + "-prune", ], + command = "update-repos", ) -gazelle_binary( - name = "gazelle_python_binary", - languages = ["//gazelle"], - visibility = ["//visibility:public"], +filegroup( + name = "distribution", + srcs = [ + ":BUILD.bazel", + ":README.md", + ":WORKSPACE", + ":def.bzl", + ":deps.bzl", + ":go.mod", + ":go.sum", + "//manifest:distribution", + "//modules_mapping:distribution", + "//python:distribution", + "//pythonconfig:distribution", + ], + visibility = ["@rules_python//:__pkg__"], ) diff --git a/gazelle/MODULE.bazel b/gazelle/MODULE.bazel new file mode 100644 index 0000000000..bd634020f3 --- /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/README.md b/gazelle/README.md index e622db991a..e36f3a303a 100644 --- a/gazelle/README.md +++ b/gazelle/README.md @@ -1,29 +1,79 @@ # Python Gazelle plugin +[Gazelle](https://github.com/bazelbuild/bazel-gazelle) +is a build file generator for Bazel projects. It can create new BUILD.bazel files for a project that follows language conventions, and it can update existing build files to include new sources, dependencies, and options. + +Gazelle may be run by Bazel using the gazelle rule, or it may be installed and run as a command line tool. + This directory contains a plugin for [Gazelle](https://github.com/bazelbuild/bazel-gazelle) -that generates BUILD file content for Python code. +that generates BUILD files content for Python code. + +The following instructions are for when you use [bzlmod](https://docs.bazel.build/versions/5.0.0/bzlmod.html). +Please refer to older documentation that includes instructions on how to use Gazelle +without using bzlmod as your dependency manager. + +## Example + +We have an example of using Gazelle with Python located [here](https://github.com/bazelbuild/rules_python/tree/main/examples/bzlmod). +A fully-working example without using bzlmod is in [`examples/build_file_generation`](../examples/build_file_generation). -It requires Go 1.16+ to compile. +The following documentation covers using bzlmod. -## Installation +## Adding Gazelle to your project -First, you'll need to add Gazelle to your `WORKSPACE` file. -Follow the instructions at https://github.com/bazelbuild/bazel-gazelle#running-gazelle-with-bazel +First, you'll need to add Gazelle to your `MODULES.bazel` file. +Get the current version of Gazelle from there releases here: https://github.com/bazelbuild/bazel-gazelle/releases/. -Next, we need to fetch the third-party Go libraries that the python extension -depends on. -Add this to your `WORKSPACE`: +See the installation `MODULE.bazel` snippet on the Releases page: +https://github.com/bazelbuild/rules_python/releases in order to configure rules_python. + +You will also need to add the `bazel_dep` for configuration for `rules_python_gazelle_plugin`. + +Here is a snippet of a `MODULE.bazel` file. ```starlark -# To compile the rules_python gazelle extension from source, -# we must fetch some third-party go dependencies that it uses. -load("@rules_python//gazelle:deps.bzl", _py_gazelle_deps = "gazelle_deps") +# The following stanza defines the dependency rules_python. +bazel_dep(name = "rules_python", version = "0.20.0") -_py_gazelle_deps() -``` +# The following stanza defines the dependency rules_python. +# For typical setups you set the version. +bazel_dep(name = "rules_python_gazelle_plugin", version = "0.20.0") + +# The following stanza defines the dependency rules_python. +bazel_dep(name = "gazelle", version = "0.30.0", repo_name = "bazel_gazelle") + +# Import the python repositories generated by the given module extension into the scope of the current module. +use_repo(python, "python3_9") +use_repo(python, "python3_9_toolchains") + +# Register an already-defined toolchain so that Bazel can use it during toolchain resolution. +register_toolchains( + "@python3_9_toolchains//:all", +) + +# Use the pip extension +pip = use_extension("@rules_python//python:extensions.bzl", "pip") + +# Use the extension to call the `pip_repository` rule that invokes `pip`, with `incremental` set. +# Accepts a locked/compiled requirements file and installs the dependencies listed within. +# Those dependencies become available in a generated `requirements.bzl` file. +# You can instead check this `requirements.bzl` file into your repo. +# Because this project has different requirements for windows vs other +# operating systems, we have requirements for each. +pip.parse( + name = "pip", + # When using gazelle you must use set the following flag + # in order for the generation of gazelle dependency resolution. + incompatible_generate_aliases = True, + requirements_lock = "//:requirements_lock.txt", + requirements_windows = "//:requirements_windows.txt", +) +# Imports the pip toolchain generated by the given module extension into the scope of the current module. +use_repo(pip, "pip") +``` Next, we'll fetch metadata about your Python dependencies, so that gazelle can determine which package a given import statement comes from. This is provided by the `modules_mapping` rule. We'll make a target for consuming this @@ -40,8 +90,8 @@ To keep the metadata updated, put this in your `BUILD.bazel` file next to `gazel ```starlark load("@pip//:requirements.bzl", "all_whl_requirements") -load("@rules_python//gazelle/manifest:defs.bzl", "gazelle_python_manifest") -load("@rules_python//gazelle/modules_mapping:def.bzl", "modules_mapping") +load("@rules_python_gazelle_plugin//manifest:defs.bzl", "gazelle_python_manifest") +load("@rules_python_gazelle_plugin//modules_mapping:def.bzl", "modules_mapping") # This rule fetches the metadata for python packages we depend on. That data is # required for the gazelle_python_manifest rule to update our manifest file. @@ -63,11 +113,12 @@ gazelle_python_manifest( # This is what we called our `pip_install` rule, where third-party # python libraries are loaded in BUILD files. pip_repository_name = "pip", - # When using pip_parse instead of pip_install, set the following. - # pip_repository_incremental = True, # This should point to wherever we declare our python dependencies # (the same as what we passed to the modules_mapping rule in WORKSPACE) requirements = "//:requirements_lock.txt", + # NOTE: we can use this flag in order to make our setup compatible with + # bzlmod. + use_pip_repository_aliases = True, ) ``` @@ -75,9 +126,9 @@ Finally, you create a target that you'll invoke to run the Gazelle tool with the rules_python extension included. This typically goes in your root `/BUILD.bazel` file: -``` +```starlark load("@bazel_gazelle//:def.bzl", "gazelle") -load("@rules_python//gazelle:def.bzl", "GAZELLE_PYTHON_RUNTIME_DEPS") +load("@rules_python_gazelle_plugin//:def.bzl", "GAZELLE_PYTHON_RUNTIME_DEPS") # Our gazelle target points to the python gazelle binary. # This is the simple case where we only need one language supported. @@ -87,15 +138,13 @@ load("@rules_python//gazelle:def.bzl", "GAZELLE_PYTHON_RUNTIME_DEPS") gazelle( name = "gazelle", data = GAZELLE_PYTHON_RUNTIME_DEPS, - gazelle = "@rules_python//gazelle:gazelle_python_binary", + gazelle = "@rules_python_gazelle_plugin//python:gazelle_binary", ) ``` That's it, now you can finally run `bazel run //:gazelle` anytime you edit Python code, and it should update your `BUILD` files correctly. -A fully-working example is in [`examples/build_file_generation`](../examples/build_file_generation). - ## Usage Gazelle is non-destructive. @@ -166,11 +215,29 @@ Next, all source files are collected into the `srcs` of the `py_library`. Finally, the `import` statements in the source files are parsed, and dependencies are added to the `deps` attribute. -### Tests +### Unit Tests + +A `py_test` target is added to the BUILD file when gazelle encounters +a file named `__test__.py`. +Often, Python unit test files are named with the suffix `_test`. +For example, if we had a folder that is a package named "foo" we could have a Python file named `foo_test.py` +and gazelle would create a `py_test` block for the file. + +The following is an example of a `py_test` target that gazelle would add when +it encounters a file named `__test__.py`. -Python test files are those ending in `_test.py`. +```starlark +py_test( + name = "build_file_generation_test", + srcs = ["__test__.py"], + main = "__test__.py", + deps = [":build_file_generation"], +) +``` -A `py_test` target is added containing all test files as `srcs`. +You can control the naming convention for test targets by adding a gazelle directive named +`# gazelle:python_test_naming_convention`. See the instructions in the section above that +covers directives. ### Binaries @@ -179,16 +246,18 @@ of a Python program. A `py_binary` target will be created, named `[package]_bin`. -## Developing on the extension +## Developer Notes -Gazelle extensions are written in Go. Ours is a hybrid, which also spawns -a Python interpreter as a subprocess to parse python files. +Gazelle extensions are written in Go. This gazelle plugin is a hybrid, as it uses Go to execute a +Python interpreter as a subprocess to parse Python source files. +See the gazelle documentation https://github.com/bazelbuild/bazel-gazelle/blob/master/extend.md +for more information on extending Gazelle. -The Go dependencies are managed by the go.mod file. -After changing that file, run `go mod tidy` to get a `go.sum` file, -then run `bazel run //:update_go_deps` to convert that to the `gazelle/deps.bzl` file. -The latter is loaded in our `/WORKSPACE` to define the external repos -that we can load Go dependencies from. +If you add new Go dependencies to the plugin source code, you need to "tidy" the go.mod file. +After changing that file, run `go mod tidy` or `bazel run @go_sdk//:bin/go -- mod tidy` +to update the go.mod and go.sum files. Then run `bazel run //:update_go_deps` to have gazelle +add the new dependenies to the deps.bzl file. The deps.bzl file is used as defined in our /WORKSPACE +to include the external repos Bazel loads Go dependencies from. -Then after editing Go code, run `bazel run //:gazelle` to generate/update -go_* rules in the BUILD.bazel files in our repo. +Then after editing Go code, run `bazel run //:gazelle` to generate/update the rules in the +BUILD.bazel files in our repo. diff --git a/gazelle/WORKSPACE b/gazelle/WORKSPACE new file mode 100644 index 0000000000..55cf1b0d40 --- /dev/null +++ b/gazelle/WORKSPACE @@ -0,0 +1,47 @@ +workspace(name = "rules_python_gazelle_plugin") + +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +http_archive( + name = "io_bazel_rules_go", + sha256 = "099a9fb96a376ccbbb7d291ed4ecbdfd42f6bc822ab77ae6f1b5cb9e914e94fa", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.35.0/rules_go-v0.35.0.zip", + "https://github.com/bazelbuild/rules_go/releases/download/v0.35.0/rules_go-v0.35.0.zip", + ], +) + +http_archive( + name = "bazel_gazelle", + sha256 = "448e37e0dbf61d6fa8f00aaa12d191745e14f07c31cabfa731f0c8e8a4f41b97", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.28.0/bazel-gazelle-v0.28.0.tar.gz", + "https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.28.0/bazel-gazelle-v0.28.0.tar.gz", + ], +) + +load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") +load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") + +go_rules_dependencies() + +go_register_toolchains(version = "1.19.4") + +gazelle_dependencies() + +local_repository( + name = "rules_python", + path = "..", +) + +load("@rules_python//python:repositories.bzl", "python_register_toolchains") + +python_register_toolchains( + name = "python39", + python_version = "3.9", +) + +load("//:deps.bzl", _py_gazelle_deps = "gazelle_deps") + +# gazelle:repository_macro deps.bzl%gazelle_deps +_py_gazelle_deps() diff --git a/gazelle/fix.go b/gazelle/fix.go deleted file mode 100644 index c669f21d27..0000000000 --- a/gazelle/fix.go +++ /dev/null @@ -1,13 +0,0 @@ -package python - -import ( - "github.com/bazelbuild/bazel-gazelle/config" - "github.com/bazelbuild/bazel-gazelle/rule" -) - -// Fix repairs deprecated usage of language-specific rules in f. This is -// called before the file is indexed. Unless c.ShouldFix is true, fixes -// that delete or rename rules should not be performed. -func (py *Python) Fix(c *config.Config, f *rule.File) { - // TODO(f0rmiga): implement. -} diff --git a/gazelle/go.mod b/gazelle/go.mod new file mode 100644 index 0000000000..94f19e801f --- /dev/null +++ b/gazelle/go.mod @@ -0,0 +1,17 @@ +module github.com/bazelbuild/rules_python/gazelle + +go 1.19 + +require ( + github.com/bazelbuild/buildtools v0.0.0-20221004120235-7186f635531b + github.com/bmatcuk/doublestar v1.3.4 + github.com/emirpasic/gods v1.18.1 + github.com/ghodss/yaml v1.0.0 + gopkg.in/yaml.v2 v2.4.0 +) + +require ( + github.com/google/go-cmp v0.5.9 // indirect + golang.org/x/sys v0.0.0-20221010170243-090e33056c14 // indirect + golang.org/x/tools v0.1.12 // indirect +) diff --git a/gazelle/go.sum b/gazelle/go.sum new file mode 100644 index 0000000000..ed8ceae5ec --- /dev/null +++ b/gazelle/go.sum @@ -0,0 +1,92 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/bazelbuild/bazel-gazelle v0.27.0 h1:+/ZhUxlDy4XnyMIGeKkbRZoIGssy1eO51GijwIvvuwE= +github.com/bazelbuild/bazel-gazelle v0.27.0/go.mod h1:2K6B42/loq8ext4JObmam4gTYx4En1MUSzHFKQF8hPM= +github.com/bazelbuild/buildtools v0.0.0-20221004120235-7186f635531b h1:jhiMzJ+8unnLRtV8rpbWBFE9pFNzIqgUTyZU5aA++w8= +github.com/bazelbuild/buildtools v0.0.0-20221004120235-7186f635531b/go.mod h1:689QdV3hBP7Vo9dJMmzhoYIyo/9iMhEmHkJcnaPRCbo= +github.com/bazelbuild/rules_go v0.35.0 h1:ViPR65vOrg74JKntAUFY6qZkheBKGB6to7wFd8gCRU4= +github.com/bazelbuild/rules_go v0.35.0/go.mod h1:ahciH68Viyxtm/gvCQplaAiu8buhf/b+gWswcPjFixI= +github.com/bmatcuk/doublestar v1.3.4 h1:gPypJ5xD31uhX6Tf54sDPUOBXTqKH4c9aPY66CyQrS0= +github.com/bmatcuk/doublestar v1.3.4/go.mod h1:wiQtGV+rzVYxB7WIlirSN++5HPtPlXEo9MEoZQC/PmE= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= +github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= +github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= +github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= +github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= +github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +go.starlark.net v0.0.0-20210223155950-e043a3d3c984/go.mod h1:t3mmBBPzAVvK0L0n1drDmrQsJ8FoIx4INCqVMTr/Zo0= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20221010170243-090e33056c14 h1:k5II8e6QD8mITdi+okbbmR/cIyEbeXLBhy5Ha4nevyc= +golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/gazelle/language.go b/gazelle/language.go deleted file mode 100644 index 877ac6d065..0000000000 --- a/gazelle/language.go +++ /dev/null @@ -1,18 +0,0 @@ -package python - -import ( - "github.com/bazelbuild/bazel-gazelle/language" -) - -// Python satisfies the language.Language interface. It is the Gazelle extension -// for Python rules. -type Python struct { - Configurer - Resolver -} - -// NewLanguage initializes a new Python that satisfies the language.Language -// interface. This is the entrypoint for the extension initialization. -func NewLanguage() language.Language { - return &Python{} -} diff --git a/gazelle/manifest/hasher/BUILD.bazel b/gazelle/manifest/hasher/BUILD.bazel new file mode 100644 index 0000000000..2e7b125cc0 --- /dev/null +++ b/gazelle/manifest/hasher/BUILD.bazel @@ -0,0 +1,20 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") + +go_library( + name = "hasher_lib", + srcs = ["main.go"], + importpath = "github.com/bazelbuild/rules_python/gazelle/manifest/hasher", + visibility = ["//visibility:private"], +) + +go_binary( + name = "hasher", + embed = [":hasher_lib"], + visibility = ["//visibility:public"], +) + +filegroup( + name = "distribution", + srcs = glob(["**"]), + visibility = ["//manifest:__pkg__"], +) diff --git a/gazelle/manifest/hasher/main.go b/gazelle/manifest/hasher/main.go new file mode 100644 index 0000000000..61f8952904 --- /dev/null +++ b/gazelle/manifest/hasher/main.go @@ -0,0 +1,44 @@ +// Copyright 2023 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package main + +import ( + "crypto/sha256" + "io" + "log" + "os" +) + +func main() { + h := sha256.New() + out, err := os.Create(os.Args[1]) + if err != nil { + log.Fatal(err) + } + defer out.Close() + for _, filename := range os.Args[2:] { + f, err := os.Open(filename) + if err != nil { + log.Fatal(err) + } + defer f.Close() + if _, err := io.Copy(h, f); err != nil { + log.Fatal(err) + } + } + if _, err := out.Write(h.Sum(nil)); err != nil { + log.Fatal(err) + } +} diff --git a/gazelle/python/BUILD.bazel b/gazelle/python/BUILD.bazel new file mode 100644 index 0000000000..ddcad2785d --- /dev/null +++ b/gazelle/python/BUILD.bazel @@ -0,0 +1,79 @@ +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 = [ + "//manifest", + "//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", + "@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_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__"], +) diff --git a/gazelle/configure.go b/gazelle/python/configure.go similarity index 89% rename from gazelle/configure.go rename to gazelle/python/configure.go index 8e71110d0a..32f9ab0a11 100644 --- a/gazelle/configure.go +++ b/gazelle/python/configure.go @@ -1,3 +1,17 @@ +// Copyright 2023 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package python import ( @@ -89,7 +103,7 @@ func (py *Configurer) Configure(c *config.Config, rel string, f *rule.File) { case "exclude": // We record the exclude directive for coarse-grained packages // since we do manual tree traversal in this mode. - config.AddExcludedPattern(strings.TrimSpace(d.Value)) + config.AddExcludedPattern(filepath.Join(rel, strings.TrimSpace(d.Value))) case pythonconfig.PythonExtensionDirective: switch d.Value { case "enabled": diff --git a/gazelle/python/fix.go b/gazelle/python/fix.go new file mode 100644 index 0000000000..1ca42571ab --- /dev/null +++ b/gazelle/python/fix.go @@ -0,0 +1,27 @@ +// Copyright 2023 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package python + +import ( + "github.com/bazelbuild/bazel-gazelle/config" + "github.com/bazelbuild/bazel-gazelle/rule" +) + +// Fix repairs deprecated usage of language-specific rules in f. This is +// called before the file is indexed. Unless c.ShouldFix is true, fixes +// that delete or rename rules should not be performed. +func (py *Python) Fix(c *config.Config, f *rule.File) { + // TODO(f0rmiga): implement. +} diff --git a/gazelle/generate.go b/gazelle/python/generate.go similarity index 63% rename from gazelle/generate.go rename to gazelle/python/generate.go index 077acb821a..fb41324fd6 100644 --- a/gazelle/generate.go +++ b/gazelle/python/generate.go @@ -1,3 +1,17 @@ +// Copyright 2023 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package python import ( @@ -12,13 +26,11 @@ import ( "github.com/bazelbuild/bazel-gazelle/label" "github.com/bazelbuild/bazel-gazelle/language" "github.com/bazelbuild/bazel-gazelle/rule" + "github.com/bazelbuild/rules_python/gazelle/pythonconfig" "github.com/bmatcuk/doublestar" "github.com/emirpasic/gods/lists/singlylinkedlist" "github.com/emirpasic/gods/sets/treeset" godsutils "github.com/emirpasic/gods/utils" - "github.com/google/uuid" - - "github.com/bazelbuild/rules_python/gazelle/pythonconfig" ) const ( @@ -26,12 +38,21 @@ const ( pyBinaryEntrypointFilename = "__main__.py" pyTestEntrypointFilename = "__test__.py" pyTestEntrypointTargetname = "__test__" + conftestFilename = "conftest.py" + conftestTargetname = "conftest" ) var ( buildFilenames = []string{"BUILD", "BUILD.bazel"} ) +func GetActualKindName(kind string, args language.GenerateArgs) string { + if kindOverride, ok := args.Config.KindMap[kind]; ok { + return kindOverride.KindName + } + return kind +} + // GenerateRules extracts build metadata from source files in a directory. // GenerateRules is called in each directory where an update is requested // in depth-first post-order. @@ -56,44 +77,55 @@ func (py *Python) GenerateRules(args language.GenerateArgs) language.GenerateRes } } + actualPyBinaryKind := GetActualKindName(pyBinaryKind, args) + actualPyLibraryKind := GetActualKindName(pyLibraryKind, args) + actualPyTestKind := GetActualKindName(pyTestKind, args) + pythonProjectRoot := cfg.PythonProjectRoot() packageName := filepath.Base(args.Dir) pyLibraryFilenames := treeset.NewWith(godsutils.StringComparator) pyTestFilenames := treeset.NewWith(godsutils.StringComparator) + pyFileNames := treeset.NewWith(godsutils.StringComparator) // hasPyBinary controls whether a py_binary target should be generated for // this package or not. hasPyBinary := false - // hasPyTestFile and hasPyTestTarget control whether a py_test target should + // hasPyTestEntryPointFile and hasPyTestEntryPointTarget control whether a py_test target should // be generated for this package or not. - hasPyTestFile := false - hasPyTestTarget := false + hasPyTestEntryPointFile := false + hasPyTestEntryPointTarget := false + hasConftestFile := false for _, f := range args.RegularFiles { if cfg.IgnoresFile(filepath.Base(f)) { continue } ext := filepath.Ext(f) - if !hasPyBinary && f == pyBinaryEntrypointFilename { - hasPyBinary = true - } else if !hasPyTestFile && f == pyTestEntrypointFilename { - hasPyTestFile = true - } else if strings.HasSuffix(f, "_test.py") || (strings.HasPrefix(f, "test_") && ext == ".py") { - pyTestFilenames.Add(f) - } else if ext == ".py" { - pyLibraryFilenames.Add(f) + if ext == ".py" { + pyFileNames.Add(f) + if !hasPyBinary && f == pyBinaryEntrypointFilename { + hasPyBinary = true + } else if !hasPyTestEntryPointFile && f == pyTestEntrypointFilename { + hasPyTestEntryPointFile = true + } else if f == conftestFilename { + hasConftestFile = true + } else if strings.HasSuffix(f, "_test.py") || strings.HasPrefix(f, "test_") { + pyTestFilenames.Add(f) + } else { + pyLibraryFilenames.Add(f) + } } } // If a __test__.py file was not found on disk, search for targets that are // named __test__. - if !hasPyTestFile && args.File != nil { + if !hasPyTestEntryPointFile && args.File != nil { for _, rule := range args.File.Rules { if rule.Name() == pyTestEntrypointTargetname { - hasPyTestTarget = true + hasPyTestEntryPointTarget = true break } } @@ -140,13 +172,14 @@ func (py *Python) GenerateRules(args language.GenerateArgs) language.GenerateRes } if filepath.Ext(path) == ".py" { if cfg.CoarseGrainedGeneration() || !isEntrypointFile(path) { - f, _ := filepath.Rel(args.Dir, path) + srcPath, _ := filepath.Rel(args.Dir, path) + repoPath := filepath.Join(args.Rel, srcPath) excludedPatterns := cfg.ExcludedPatterns() if excludedPatterns != nil { it := excludedPatterns.Iterator() for it.Next() { excludedPattern := it.Value().(string) - isExcluded, err := doublestar.Match(excludedPattern, f) + isExcluded, err := doublestar.Match(excludedPattern, repoPath) if err != nil { return err } @@ -157,9 +190,9 @@ func (py *Python) GenerateRules(args language.GenerateArgs) language.GenerateRes } baseName := filepath.Base(path) if strings.HasSuffix(baseName, "_test.py") || strings.HasPrefix(baseName, "test_") { - pyTestFilenames.Add(f) + pyTestFilenames.Add(srcPath) } else { - pyLibraryFilenames.Add(f) + pyLibraryFilenames.Add(srcPath) } } } @@ -180,13 +213,6 @@ func (py *Python) GenerateRules(args language.GenerateArgs) language.GenerateRes collisionErrors := singlylinkedlist.New() - if !hasPyTestFile && !hasPyTestTarget { - it := pyTestFilenames.Iterator() - for it.Next() { - pyLibraryFilenames.Add(it.Value()) - } - } - var pyLibrary *rule.Rule if !pyLibraryFilenames.Empty() { deps, err := parser.parse(pyLibraryFilenames) @@ -196,25 +222,24 @@ func (py *Python) GenerateRules(args language.GenerateArgs) language.GenerateRes pyLibraryTargetName := cfg.RenderLibraryName(packageName) - // Check if a target with the same name we are generating alredy exists, - // and if it is of a different kind from the one we are generating. If - // so, we have to throw an error since Gazelle won't generate it - // correctly. + // Check if a target with the same name we are generating already + // exists, and if it is of a different kind from the one we are + // generating. If so, we have to throw an error since Gazelle won't + // generate it correctly. if args.File != nil { for _, t := range args.File.Rules { - if t.Name() == pyLibraryTargetName && t.Kind() != pyLibraryKind { + if t.Name() == pyLibraryTargetName && t.Kind() != actualPyLibraryKind { fqTarget := label.New("", args.Rel, pyLibraryTargetName) err := fmt.Errorf("failed to generate target %q of kind %q: "+ "a target of kind %q with the same name already exists. "+ "Use the '# gazelle:%s' directive to change the naming convention.", - fqTarget.String(), pyLibraryKind, t.Kind(), pythonconfig.LibraryNamingConvention) + fqTarget.String(), actualPyLibraryKind, t.Kind(), pythonconfig.LibraryNamingConvention) collisionErrors.Add(err) } } } - pyLibrary = newTargetBuilder(pyLibraryKind, pyLibraryTargetName, pythonProjectRoot, args.Rel). - setUUID(uuid.Must(uuid.NewUUID()).String()). + pyLibrary = newTargetBuilder(pyLibraryKind, pyLibraryTargetName, pythonProjectRoot, args.Rel, pyFileNames). addVisibility(visibility). addSrcs(pyLibraryFilenames). addModuleDependencies(deps). @@ -233,76 +258,109 @@ func (py *Python) GenerateRules(args language.GenerateArgs) language.GenerateRes pyBinaryTargetName := cfg.RenderBinaryName(packageName) - // Check if a target with the same name we are generating alredy exists, - // and if it is of a different kind from the one we are generating. If - // so, we have to throw an error since Gazelle won't generate it - // correctly. + // Check if a target with the same name we are generating already + // exists, and if it is of a different kind from the one we are + // generating. If so, we have to throw an error since Gazelle won't + // generate it correctly. if args.File != nil { for _, t := range args.File.Rules { - if t.Name() == pyBinaryTargetName && t.Kind() != pyBinaryKind { + if t.Name() == pyBinaryTargetName && t.Kind() != actualPyBinaryKind { fqTarget := label.New("", args.Rel, pyBinaryTargetName) err := fmt.Errorf("failed to generate target %q of kind %q: "+ "a target of kind %q with the same name already exists. "+ "Use the '# gazelle:%s' directive to change the naming convention.", - fqTarget.String(), pyBinaryKind, t.Kind(), pythonconfig.BinaryNamingConvention) + fqTarget.String(), actualPyBinaryKind, t.Kind(), pythonconfig.BinaryNamingConvention) collisionErrors.Add(err) } } } - pyBinaryTarget := newTargetBuilder(pyBinaryKind, pyBinaryTargetName, pythonProjectRoot, args.Rel). + pyBinaryTarget := newTargetBuilder(pyBinaryKind, pyBinaryTargetName, pythonProjectRoot, args.Rel, pyFileNames). setMain(pyBinaryEntrypointFilename). addVisibility(visibility). addSrc(pyBinaryEntrypointFilename). addModuleDependencies(deps). generateImportsAttribute() - if pyLibrary != nil { - pyBinaryTarget.addModuleDependency(module{Name: pyLibrary.PrivateAttr(uuidKey).(string)}) - } - pyBinary := pyBinaryTarget.build() result.Gen = append(result.Gen, pyBinary) result.Imports = append(result.Imports, pyBinary.PrivateAttr(config.GazelleImportsKey)) } - if hasPyTestFile || hasPyTestTarget { - if hasPyTestFile { - // Only add the pyTestEntrypointFilename to the pyTestFilenames if - // the file exists on disk. - pyTestFilenames.Add(pyTestEntrypointFilename) - } - deps, err := parser.parse(pyTestFilenames) + var conftest *rule.Rule + if hasConftestFile { + deps, err := parser.parseSingle(conftestFilename) if err != nil { log.Fatalf("ERROR: %v\n", err) } - pyTestTargetName := cfg.RenderTestName(packageName) + // Check if a target with the same name we are generating already + // exists, and if it is of a different kind from the one we are + // generating. If so, we have to throw an error since Gazelle won't + // generate it correctly. + if args.File != nil { + for _, t := range args.File.Rules { + if t.Name() == conftestTargetname && t.Kind() != actualPyLibraryKind { + fqTarget := label.New("", args.Rel, conftestTargetname) + err := fmt.Errorf("failed to generate target %q of kind %q: "+ + "a target of kind %q with the same name already exists.", + fqTarget.String(), actualPyLibraryKind, t.Kind()) + collisionErrors.Add(err) + } + } + } + + conftestTarget := newTargetBuilder(pyLibraryKind, conftestTargetname, pythonProjectRoot, args.Rel, pyFileNames). + addSrc(conftestFilename). + addModuleDependencies(deps). + addVisibility(visibility). + setTestonly(). + generateImportsAttribute() + + conftest = conftestTarget.build() - // Check if a target with the same name we are generating alredy exists, - // and if it is of a different kind from the one we are generating. If - // so, we have to throw an error since Gazelle won't generate it - // correctly. + result.Gen = append(result.Gen, conftest) + result.Imports = append(result.Imports, conftest.PrivateAttr(config.GazelleImportsKey)) + } + + var pyTestTargets []*targetBuilder + newPyTestTargetBuilder := func(srcs *treeset.Set, pyTestTargetName string) *targetBuilder { + deps, err := parser.parse(srcs) + if err != nil { + log.Fatalf("ERROR: %v\n", err) + } + // Check if a target with the same name we are generating already + // exists, and if it is of a different kind from the one we are + // generating. If so, we have to throw an error since Gazelle won't + // generate it correctly. if args.File != nil { for _, t := range args.File.Rules { - if t.Name() == pyTestTargetName && t.Kind() != pyTestKind { + if t.Name() == pyTestTargetName && t.Kind() != actualPyTestKind { fqTarget := label.New("", args.Rel, pyTestTargetName) err := fmt.Errorf("failed to generate target %q of kind %q: "+ "a target of kind %q with the same name already exists. "+ "Use the '# gazelle:%s' directive to change the naming convention.", - fqTarget.String(), pyTestKind, t.Kind(), pythonconfig.TestNamingConvention) + fqTarget.String(), actualPyTestKind, t.Kind(), pythonconfig.TestNamingConvention) collisionErrors.Add(err) } } } - - pyTestTarget := newTargetBuilder(pyTestKind, pyTestTargetName, pythonProjectRoot, args.Rel). - addSrcs(pyTestFilenames). + return newTargetBuilder(pyTestKind, pyTestTargetName, pythonProjectRoot, args.Rel, pyFileNames). + addSrcs(srcs). addModuleDependencies(deps). generateImportsAttribute() + } + if hasPyTestEntryPointFile || hasPyTestEntryPointTarget { + if hasPyTestEntryPointFile { + // Only add the pyTestEntrypointFilename to the pyTestFilenames if + // the file exists on disk. + pyTestFilenames.Add(pyTestEntrypointFilename) + } + pyTestTargetName := cfg.RenderTestName(packageName) + pyTestTarget := newPyTestTargetBuilder(pyTestFilenames, pyTestTargetName) - if hasPyTestTarget { + if hasPyTestEntryPointTarget { entrypointTarget := fmt.Sprintf(":%s", pyTestEntrypointTargetname) main := fmt.Sprintf(":%s", pyTestEntrypointFilename) pyTestTarget. @@ -312,11 +370,20 @@ func (py *Python) GenerateRules(args language.GenerateArgs) language.GenerateRes } else { pyTestTarget.setMain(pyTestEntrypointFilename) } + pyTestTargets = append(pyTestTargets, pyTestTarget) + } else { + // Create one py_test target per file + pyTestFilenames.Each(func(index int, testFile interface{}) { + srcs := treeset.NewWith(godsutils.StringComparator, testFile) + pyTestTargetName := strings.TrimSuffix(filepath.Base(testFile.(string)), ".py") + pyTestTargets = append(pyTestTargets, newPyTestTargetBuilder(srcs, pyTestTargetName)) + }) + } - if pyLibrary != nil { - pyTestTarget.addModuleDependency(module{Name: pyLibrary.PrivateAttr(uuidKey).(string)}) + for _, pyTestTarget := range pyTestTargets { + if conftest != nil { + pyTestTarget.addModuleDependency(module{Name: strings.TrimSuffix(conftestFilename, ".py")}) } - pyTest := pyTestTarget.build() result.Gen = append(result.Gen, pyTest) diff --git a/gazelle/kinds.go b/gazelle/python/kinds.go similarity index 73% rename from gazelle/kinds.go rename to gazelle/python/kinds.go index fa0f4ed98a..ab1afb7d55 100644 --- a/gazelle/kinds.go +++ b/gazelle/python/kinds.go @@ -1,3 +1,17 @@ +// Copyright 2023 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package python import ( @@ -51,7 +65,7 @@ var pyKinds = map[string]rule.KindInfo{ }, }, pyTestKind: { - MatchAny: true, + MatchAny: false, NonEmptyAttrs: map[string]bool{ "deps": true, "main": true, diff --git a/gazelle/python/language.go b/gazelle/python/language.go new file mode 100644 index 0000000000..56eb97b043 --- /dev/null +++ b/gazelle/python/language.go @@ -0,0 +1,32 @@ +// Copyright 2023 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package python + +import ( + "github.com/bazelbuild/bazel-gazelle/language" +) + +// Python satisfies the language.Language interface. It is the Gazelle extension +// for Python rules. +type Python struct { + Configurer + Resolver +} + +// NewLanguage initializes a new Python that satisfies the language.Language +// interface. This is the entrypoint for the extension initialization. +func NewLanguage() language.Language { + return &Python{} +} diff --git a/gazelle/parse.py b/gazelle/python/parse.py similarity index 83% rename from gazelle/parse.py rename to gazelle/python/parse.py index b892229386..6c0ef69598 100644 --- a/gazelle/parse.py +++ b/gazelle/python/parse.py @@ -1,3 +1,17 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + # parse.py is a long-living program that communicates over STDIN and STDOUT. # STDIN receives parse requests, one per line. It outputs the parsed modules and # comments from all the files from each request. @@ -13,7 +27,7 @@ def parse_import_statements(content, filepath): modules = list() - tree = ast.parse(content) + tree = ast.parse(content, filename=filepath) for node in ast.walk(tree): if isinstance(node, ast.Import): for subnode in node.names: diff --git a/gazelle/parser.go b/gazelle/python/parser.go similarity index 84% rename from gazelle/parser.go rename to gazelle/python/parser.go index d287caf233..33eb6f4b33 100644 --- a/gazelle/parser.go +++ b/gazelle/python/parser.go @@ -1,3 +1,17 @@ +// Copyright 2023 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package python import ( @@ -25,14 +39,14 @@ var ( ) func init() { - parseScriptRunfile, err := bazel.Runfile("gazelle/parse") + parseScriptRunfile, err := bazel.Runfile("python/parse") if err != nil { log.Printf("failed to initialize parser: %v\n", err) os.Exit(1) } ctx := context.Background() - ctx, parserCancel := context.WithTimeout(ctx, time.Minute*5) + ctx, parserCancel := context.WithTimeout(ctx, time.Minute*10) cmd := exec.CommandContext(ctx, parseScriptRunfile) cmd.Stderr = os.Stderr @@ -128,7 +142,10 @@ func (p *python3Parser) parse(pyFilenames *treeset.Set) (*treeset.Set, error) { } for _, res := range allRes { - annotations := annotationsFromComments(res.Comments) + annotations, err := annotationsFromComments(res.Comments) + if err != nil { + return nil, fmt.Errorf("failed to parse annotations: %w", err) + } for _, m := range res.Modules { // Check for ignored dependencies set via an annotation to the Python @@ -195,17 +212,20 @@ type comment string // asAnnotation returns an annotation object if the comment has the // annotationPrefix. -func (c *comment) asAnnotation() *annotation { +func (c *comment) asAnnotation() (*annotation, error) { uncomment := strings.TrimLeft(string(*c), "# ") if !strings.HasPrefix(uncomment, annotationPrefix) { - return nil + return nil, nil } withoutPrefix := strings.TrimPrefix(uncomment, annotationPrefix) annotationParts := strings.SplitN(withoutPrefix, " ", 2) + if len(annotationParts) < 2 { + return nil, fmt.Errorf("`%s` requires a value", *c) + } return &annotation{ kind: annotationKind(annotationParts[0]), value: annotationParts[1], - } + }, nil } // annotation represents a single Gazelle annotation parsed from a Python @@ -224,10 +244,13 @@ type annotations struct { // annotationsFromComments returns all the annotations parsed out of the // comments of a Python module. -func annotationsFromComments(comments []comment) *annotations { +func annotationsFromComments(comments []comment) (*annotations, error) { ignore := make(map[string]struct{}) for _, comment := range comments { - annotation := comment.asAnnotation() + annotation, err := comment.asAnnotation() + if err != nil { + return nil, err + } if annotation != nil { if annotation.kind == annotationKindIgnore { modules := strings.Split(annotation.value, ",") @@ -243,7 +266,7 @@ func annotationsFromComments(comments []comment) *annotations { } return &annotations{ ignore: ignore, - } + }, nil } // ignored returns true if the given module was ignored via the ignore diff --git a/gazelle/python_test.go b/gazelle/python/python_test.go similarity index 72% rename from gazelle/python_test.go rename to gazelle/python/python_test.go index 99656552dd..79450ad584 100644 --- a/gazelle/python_test.go +++ b/gazelle/python/python_test.go @@ -23,8 +23,6 @@ import ( "bytes" "context" "errors" - "fmt" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -34,14 +32,13 @@ import ( "github.com/bazelbuild/bazel-gazelle/testtools" "github.com/bazelbuild/rules_go/go/tools/bazel" - "github.com/emirpasic/gods/lists/singlylinkedlist" "github.com/ghodss/yaml" ) const ( - extensionDir = "gazelle/" - testDataPath = extensionDir + "testdata/" - gazelleBinaryName = "gazelle_python_binary" + extensionDir = "python" + string(os.PathSeparator) + testDataPath = extensionDir + "testdata" + string(os.PathSeparator) + gazelleBinaryName = "gazelle_binary" ) var gazellePath = mustFindGazelle() @@ -56,7 +53,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. @@ -77,13 +74,13 @@ func TestGazelleBinary(t *testing.T) { func testPath(t *testing.T, name string, files []bazel.RunfileEntry) { t.Run(name, func(t *testing.T) { - var inputs []testtools.FileSpec - var goldens []testtools.FileSpec + t.Parallel() + var inputs, goldens []testtools.FileSpec 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 { @@ -94,9 +91,9 @@ func testPath(t *testing.T, name string, files []bazel.RunfileEntry) { continue } - content, err := ioutil.ReadFile(path) + content, err := os.ReadFile(path) if err != nil { - t.Errorf("ioutil.ReadFile(%q) error: %v", path, err) + t.Errorf("os.ReadFile(%q) error: %v", path, err) } if filepath.Base(shortPath) == "test.yaml" { @@ -114,43 +111,49 @@ func testPath(t *testing.T, name string, files []bazel.RunfileEntry) { Path: filepath.Join(name, strings.TrimSuffix(shortPath, ".in")), Content: string(content), }) - } else if strings.HasSuffix(shortPath, ".out") { + continue + } + + if strings.HasSuffix(shortPath, ".out") { goldens = append(goldens, testtools.FileSpec{ Path: filepath.Join(name, strings.TrimSuffix(shortPath, ".out")), Content: string(content), }) - } else { - inputs = append(inputs, testtools.FileSpec{ - Path: filepath.Join(name, shortPath), - Content: string(content), - }) - goldens = append(goldens, testtools.FileSpec{ - Path: filepath.Join(name, shortPath), - Content: string(content), - }) + continue } + + inputs = append(inputs, testtools.FileSpec{ + Path: filepath.Join(name, shortPath), + Content: string(content), + }) + goldens = append(goldens, testtools.FileSpec{ + Path: filepath.Join(name, shortPath), + Content: string(content), + }) } testdataDir, cleanup := testtools.CreateFiles(t, inputs) - defer cleanup() - defer func() { - if t.Failed() { - filepath.Walk(testdataDir, func(path string, info os.FileInfo, err error) error { - if err != nil { - return err - } - t.Logf("%q exists", strings.TrimPrefix(path, testdataDir)) - return nil - }) + t.Cleanup(cleanup) + t.Cleanup(func() { + if !t.Failed() { + return } - }() + + filepath.Walk(testdataDir, func(path string, info os.FileInfo, err error) error { + if err != nil { + return err + } + t.Logf("%q exists", strings.TrimPrefix(path, testdataDir)) + return nil + }) + }) workspaceRoot := filepath.Join(testdataDir, name) args := []string{"-build_file_name=BUILD,BUILD.bazel"} ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) - defer cancel() + t.Cleanup(cancel) cmd := exec.CommandContext(ctx, gazellePath, args...) var stdout, stderr bytes.Buffer cmd.Stdout = &stdout @@ -162,31 +165,23 @@ func testPath(t *testing.T, name string, files []bazel.RunfileEntry) { t.Fatal(err) } } - errs := singlylinkedlist.New() + actualExitCode := cmd.ProcessState.ExitCode() if config.Expect.ExitCode != actualExitCode { - errs.Add(fmt.Errorf("expected gazelle exit code: %d\ngot: %d", - config.Expect.ExitCode, actualExitCode, - )) + t.Errorf("expected gazelle exit code: %d\ngot: %d", + config.Expect.ExitCode, actualExitCode) } actualStdout := stdout.String() if strings.TrimSpace(config.Expect.Stdout) != strings.TrimSpace(actualStdout) { - errs.Add(fmt.Errorf("expected gazelle stdout: %s\ngot: %s", - config.Expect.Stdout, actualStdout, - )) + t.Errorf("expected gazelle stdout: %s\ngot: %s", + config.Expect.Stdout, actualStdout) } actualStderr := stderr.String() if strings.TrimSpace(config.Expect.Stderr) != strings.TrimSpace(actualStderr) { - errs.Add(fmt.Errorf("expected gazelle stderr: %s\ngot: %s", - config.Expect.Stderr, actualStderr, - )) + t.Errorf("expected gazelle stderr: %s\ngot: %s", + config.Expect.Stderr, actualStderr) } - if !errs.Empty() { - errsIt := errs.Iterator() - for errsIt.Next() { - err := errsIt.Value().(error) - t.Log(err) - } + if t.Failed() { t.FailNow() } diff --git a/gazelle/resolve.go b/gazelle/python/resolve.go similarity index 94% rename from gazelle/resolve.go rename to gazelle/python/resolve.go index 220876da60..46014e50ec 100644 --- a/gazelle/resolve.go +++ b/gazelle/python/resolve.go @@ -1,3 +1,17 @@ +// Copyright 2023 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package python import ( @@ -25,10 +39,6 @@ const ( // resolvedDepsKey is the attribute key used to pass dependencies that don't // need to be resolved by the dependency resolver in the Resolver step. resolvedDepsKey = "_gazelle_python_resolved_deps" - // uuidKey is the attribute key used to uniquely identify a py_library - // target that should be imported by a py_test or py_binary in the same - // Bazel package. - uuidKey = "_gazelle_python_library_uuid" ) // Resolver satisfies the resolve.Resolver interface. It resolves dependencies @@ -57,13 +67,6 @@ func (py *Resolver) Imports(c *config.Config, r *rule.Rule, f *rule.File) []reso provides = append(provides, provide) } } - if r.PrivateAttr(uuidKey) != nil { - provide := resolve.ImportSpec{ - Lang: languageName, - Imp: r.PrivateAttr(uuidKey).(string), - } - provides = append(provides, provide) - } if len(provides) == 0 { return nil } diff --git a/gazelle/std_modules.go b/gazelle/python/std_modules.go similarity index 67% rename from gazelle/std_modules.go rename to gazelle/python/std_modules.go index f7d0c243d5..94ef45666e 100644 --- a/gazelle/std_modules.go +++ b/gazelle/python/std_modules.go @@ -1,3 +1,17 @@ +// Copyright 2023 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package python import ( @@ -26,19 +40,19 @@ var ( func init() { stdModulesSeen = make(map[string]struct{}) - stdModulesScriptRunfile, err := bazel.Runfile("gazelle/std_modules") + stdModulesScriptRunfile, err := bazel.Runfile("python/std_modules") if err != nil { log.Printf("failed to initialize std_modules: %v\n", err) os.Exit(1) } ctx := context.Background() - ctx, stdModulesCancel := context.WithTimeout(ctx, time.Minute*5) + ctx, stdModulesCancel := context.WithTimeout(ctx, time.Minute*10) cmd := exec.CommandContext(ctx, stdModulesScriptRunfile) cmd.Stderr = os.Stderr - cmd.Env = []string{} - + // All userland site-packages should be ignored. + cmd.Env = []string{"PYTHONNOUSERSITE=1"} stdin, err := cmd.StdinPipe() if err != nil { log.Printf("failed to initialize std_modules: %v\n", err) diff --git a/gazelle/python/std_modules.py b/gazelle/python/std_modules.py new file mode 100644 index 0000000000..779a325508 --- /dev/null +++ b/gazelle/python/std_modules.py @@ -0,0 +1,51 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# std_modules.py is a long-living program that communicates over STDIN and +# STDOUT. STDIN receives module names, one per line. For each module statement +# it evaluates, it outputs true/false for whether the module is part of the +# standard library or not. + +import os +import sys +from contextlib import redirect_stdout + + +def is_std_modules(module): + # If for some reason a module (such as pygame, see https://github.com/pygame/pygame/issues/542) + # prints to stdout upon import, + # the output of this script should still be parseable by golang. + # Therefore, redirect stdout while running the import. + with redirect_stdout(os.devnull): + try: + __import__(module, globals(), locals(), [], 0) + return True + except Exception: + return False + + +def main(stdin, stdout): + for module in stdin: + module = module.strip() + # Don't print the boolean directly as it is capitalized in Python. + print( + "true" if is_std_modules(module) else "false", + end="\n", + file=stdout, + ) + stdout.flush() + + +if __name__ == "__main__": + exit(main(sys.stdin, sys.stdout)) diff --git a/gazelle/target.go b/gazelle/python/target.go similarity index 71% rename from gazelle/target.go rename to gazelle/python/target.go index 2b260679b6..fdc99fc68c 100644 --- a/gazelle/target.go +++ b/gazelle/python/target.go @@ -1,12 +1,25 @@ +// Copyright 2023 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package python import ( - "path/filepath" - "github.com/bazelbuild/bazel-gazelle/config" "github.com/bazelbuild/bazel-gazelle/rule" "github.com/emirpasic/gods/sets/treeset" godsutils "github.com/emirpasic/gods/utils" + "path/filepath" ) // targetBuilder builds targets to be generated by Gazelle. @@ -15,38 +28,31 @@ type targetBuilder struct { name string pythonProjectRoot string bzlPackage string - uuid string srcs *treeset.Set + siblingSrcs *treeset.Set deps *treeset.Set resolvedDeps *treeset.Set visibility *treeset.Set main *string imports []string + testonly bool } // newTargetBuilder constructs a new targetBuilder. -func newTargetBuilder(kind, name, pythonProjectRoot, bzlPackage string) *targetBuilder { +func newTargetBuilder(kind, name, pythonProjectRoot, bzlPackage string, siblingSrcs *treeset.Set) *targetBuilder { return &targetBuilder{ kind: kind, name: name, pythonProjectRoot: pythonProjectRoot, bzlPackage: bzlPackage, srcs: treeset.NewWith(godsutils.StringComparator), + siblingSrcs: siblingSrcs, deps: treeset.NewWith(moduleComparator), resolvedDeps: treeset.NewWith(godsutils.StringComparator), visibility: treeset.NewWith(godsutils.StringComparator), } } -// setUUID sets the given UUID for the target. It's used to index the generated -// target based on this value in addition to the other ways the targets can be -// imported. py_{binary,test} targets in the same Bazel package can add a -// virtual dependency to this UUID that gets resolved in the Resolver interface. -func (t *targetBuilder) setUUID(uuid string) *targetBuilder { - t.uuid = uuid - return t -} - // addSrc adds a single src to the target. func (t *targetBuilder) addSrc(src string) *targetBuilder { t.srcs.Add(src) @@ -64,6 +70,15 @@ func (t *targetBuilder) addSrcs(srcs *treeset.Set) *targetBuilder { // addModuleDependency adds a single module dep to the target. func (t *targetBuilder) addModuleDependency(dep module) *targetBuilder { + fileName := dep.Name + ".py" + if dep.From != "" { + fileName = dep.From + ".py" + } + if t.siblingSrcs.Contains(fileName) && fileName != filepath.Base(dep.Filepath) { + // importing another module from the same package, converting to absolute imports to make + // dependency resolution easier + dep.Name = importSpecFromSrc(t.pythonProjectRoot, t.bzlPackage, fileName).Imp + } t.deps.Add(dep) return t } @@ -72,7 +87,7 @@ func (t *targetBuilder) addModuleDependency(dep module) *targetBuilder { func (t *targetBuilder) addModuleDependencies(deps *treeset.Set) *targetBuilder { it := deps.Iterator() for it.Next() { - t.deps.Add(it.Value().(module)) + t.addModuleDependency(it.Value().(module)) } return t } @@ -96,6 +111,12 @@ func (t *targetBuilder) setMain(main string) *targetBuilder { return t } +// setTestonly sets the testonly attribute to true. +func (t *targetBuilder) setTestonly() *targetBuilder { + t.testonly = true + return t +} + // generateImportsAttribute generates the imports attribute. // These are a list of import directories to be added to the PYTHONPATH. In our // case, the value we add is on Bazel sub-packages to be able to perform imports @@ -113,9 +134,6 @@ func (t *targetBuilder) generateImportsAttribute() *targetBuilder { // build returns the assembled *rule.Rule for the target. func (t *targetBuilder) build() *rule.Rule { r := rule.NewRule(t.kind, t.name) - if t.uuid != "" { - r.SetPrivateAttr(uuidKey, t.uuid) - } if !t.srcs.Empty() { r.SetAttr("srcs", t.srcs.Values()) } @@ -131,6 +149,9 @@ func (t *targetBuilder) build() *rule.Rule { if !t.deps.Empty() { r.SetPrivateAttr(config.GazelleImportsKey, t.deps) } + if t.testonly { + r.SetAttr("testonly", true) + } r.SetPrivateAttr(resolvedDepsKey, t.resolvedDeps) return r } diff --git a/gazelle/testdata/README.md b/gazelle/python/testdata/README.md similarity index 100% rename from gazelle/testdata/README.md rename to gazelle/python/testdata/README.md diff --git a/gazelle/testdata/dependency_resolution_order/BUILD.in b/gazelle/python/testdata/dependency_resolution_order/BUILD.in similarity index 100% rename from gazelle/testdata/dependency_resolution_order/BUILD.in rename to gazelle/python/testdata/dependency_resolution_order/BUILD.in diff --git a/gazelle/testdata/dependency_resolution_order/BUILD.out b/gazelle/python/testdata/dependency_resolution_order/BUILD.out similarity index 85% rename from gazelle/testdata/dependency_resolution_order/BUILD.out rename to gazelle/python/testdata/dependency_resolution_order/BUILD.out index 2ba2c84c9a..3ea83eb5f1 100644 --- a/gazelle/testdata/dependency_resolution_order/BUILD.out +++ b/gazelle/python/testdata/dependency_resolution_order/BUILD.out @@ -9,6 +9,6 @@ py_library( deps = [ "//baz", "//somewhere/bar", - "@gazelle_python_test//pypi__some_foo", + "@gazelle_python_test_some_foo//:pkg", ], ) diff --git a/gazelle/testdata/dependency_resolution_order/README.md b/gazelle/python/testdata/dependency_resolution_order/README.md similarity index 100% rename from gazelle/testdata/dependency_resolution_order/README.md rename to gazelle/python/testdata/dependency_resolution_order/README.md diff --git a/gazelle/testdata/dependency_resolution_order/WORKSPACE b/gazelle/python/testdata/dependency_resolution_order/WORKSPACE similarity index 100% rename from gazelle/testdata/dependency_resolution_order/WORKSPACE rename to gazelle/python/testdata/dependency_resolution_order/WORKSPACE diff --git a/gazelle/python/testdata/dependency_resolution_order/__init__.py b/gazelle/python/testdata/dependency_resolution_order/__init__.py new file mode 100644 index 0000000000..d9c6504deb --- /dev/null +++ b/gazelle/python/testdata/dependency_resolution_order/__init__.py @@ -0,0 +1,24 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys + +import bar +import baz +import foo + +_ = sys +_ = bar +_ = baz +_ = foo diff --git a/gazelle/testdata/dependency_resolution_order/bar/BUILD.in b/gazelle/python/testdata/dependency_resolution_order/bar/BUILD.in similarity index 100% rename from gazelle/testdata/dependency_resolution_order/bar/BUILD.in rename to gazelle/python/testdata/dependency_resolution_order/bar/BUILD.in diff --git a/gazelle/testdata/dependency_resolution_order/bar/BUILD.out b/gazelle/python/testdata/dependency_resolution_order/bar/BUILD.out similarity index 100% rename from gazelle/testdata/dependency_resolution_order/bar/BUILD.out rename to gazelle/python/testdata/dependency_resolution_order/bar/BUILD.out diff --git a/gazelle/python/testdata/dependency_resolution_order/bar/__init__.py b/gazelle/python/testdata/dependency_resolution_order/bar/__init__.py new file mode 100644 index 0000000000..1c0275c070 --- /dev/null +++ b/gazelle/python/testdata/dependency_resolution_order/bar/__init__.py @@ -0,0 +1,17 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +_ = os diff --git a/gazelle/testdata/dependency_resolution_order/baz/BUILD.in b/gazelle/python/testdata/dependency_resolution_order/baz/BUILD.in similarity index 100% rename from gazelle/testdata/dependency_resolution_order/baz/BUILD.in rename to gazelle/python/testdata/dependency_resolution_order/baz/BUILD.in diff --git a/gazelle/testdata/dependency_resolution_order/baz/BUILD.out b/gazelle/python/testdata/dependency_resolution_order/baz/BUILD.out similarity index 100% rename from gazelle/testdata/dependency_resolution_order/baz/BUILD.out rename to gazelle/python/testdata/dependency_resolution_order/baz/BUILD.out diff --git a/gazelle/python/testdata/dependency_resolution_order/baz/__init__.py b/gazelle/python/testdata/dependency_resolution_order/baz/__init__.py new file mode 100644 index 0000000000..1c0275c070 --- /dev/null +++ b/gazelle/python/testdata/dependency_resolution_order/baz/__init__.py @@ -0,0 +1,17 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +_ = os diff --git a/gazelle/testdata/dependency_resolution_order/foo/BUILD.in b/gazelle/python/testdata/dependency_resolution_order/foo/BUILD.in similarity index 100% rename from gazelle/testdata/dependency_resolution_order/foo/BUILD.in rename to gazelle/python/testdata/dependency_resolution_order/foo/BUILD.in diff --git a/gazelle/testdata/dependency_resolution_order/foo/BUILD.out b/gazelle/python/testdata/dependency_resolution_order/foo/BUILD.out similarity index 100% rename from gazelle/testdata/dependency_resolution_order/foo/BUILD.out rename to gazelle/python/testdata/dependency_resolution_order/foo/BUILD.out diff --git a/gazelle/python/testdata/dependency_resolution_order/foo/__init__.py b/gazelle/python/testdata/dependency_resolution_order/foo/__init__.py new file mode 100644 index 0000000000..1c0275c070 --- /dev/null +++ b/gazelle/python/testdata/dependency_resolution_order/foo/__init__.py @@ -0,0 +1,17 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +_ = os diff --git a/gazelle/python/testdata/dependency_resolution_order/gazelle_python.yaml b/gazelle/python/testdata/dependency_resolution_order/gazelle_python.yaml new file mode 100644 index 0000000000..8615181c91 --- /dev/null +++ b/gazelle/python/testdata/dependency_resolution_order/gazelle_python.yaml @@ -0,0 +1,18 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +manifest: + modules_mapping: + foo: some_foo + pip_deps_repository_name: gazelle_python_test diff --git a/gazelle/testdata/dependency_resolution_order/somewhere/bar/BUILD.in b/gazelle/python/testdata/dependency_resolution_order/somewhere/bar/BUILD.in similarity index 100% rename from gazelle/testdata/dependency_resolution_order/somewhere/bar/BUILD.in rename to gazelle/python/testdata/dependency_resolution_order/somewhere/bar/BUILD.in diff --git a/gazelle/testdata/dependency_resolution_order/somewhere/bar/BUILD.out b/gazelle/python/testdata/dependency_resolution_order/somewhere/bar/BUILD.out similarity index 100% rename from gazelle/testdata/dependency_resolution_order/somewhere/bar/BUILD.out rename to gazelle/python/testdata/dependency_resolution_order/somewhere/bar/BUILD.out diff --git a/gazelle/python/testdata/dependency_resolution_order/somewhere/bar/__init__.py b/gazelle/python/testdata/dependency_resolution_order/somewhere/bar/__init__.py new file mode 100644 index 0000000000..1c0275c070 --- /dev/null +++ b/gazelle/python/testdata/dependency_resolution_order/somewhere/bar/__init__.py @@ -0,0 +1,17 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +_ = os diff --git a/gazelle/python/testdata/dependency_resolution_order/test.yaml b/gazelle/python/testdata/dependency_resolution_order/test.yaml new file mode 100644 index 0000000000..fcea77710f --- /dev/null +++ b/gazelle/python/testdata/dependency_resolution_order/test.yaml @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- diff --git a/gazelle/testdata/disable_import_statements_validation/BUILD.in b/gazelle/python/testdata/disable_import_statements_validation/BUILD.in similarity index 100% rename from gazelle/testdata/disable_import_statements_validation/BUILD.in rename to gazelle/python/testdata/disable_import_statements_validation/BUILD.in diff --git a/gazelle/testdata/disable_import_statements_validation/BUILD.out b/gazelle/python/testdata/disable_import_statements_validation/BUILD.out similarity index 100% rename from gazelle/testdata/disable_import_statements_validation/BUILD.out rename to gazelle/python/testdata/disable_import_statements_validation/BUILD.out diff --git a/gazelle/testdata/disable_import_statements_validation/README.md b/gazelle/python/testdata/disable_import_statements_validation/README.md similarity index 100% rename from gazelle/testdata/disable_import_statements_validation/README.md rename to gazelle/python/testdata/disable_import_statements_validation/README.md diff --git a/gazelle/testdata/disable_import_statements_validation/WORKSPACE b/gazelle/python/testdata/disable_import_statements_validation/WORKSPACE similarity index 100% rename from gazelle/testdata/disable_import_statements_validation/WORKSPACE rename to gazelle/python/testdata/disable_import_statements_validation/WORKSPACE diff --git a/gazelle/python/testdata/disable_import_statements_validation/__init__.py b/gazelle/python/testdata/disable_import_statements_validation/__init__.py new file mode 100644 index 0000000000..fde6e50c27 --- /dev/null +++ b/gazelle/python/testdata/disable_import_statements_validation/__init__.py @@ -0,0 +1,17 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import abcdefg + +_ = abcdefg diff --git a/gazelle/python/testdata/disable_import_statements_validation/test.yaml b/gazelle/python/testdata/disable_import_statements_validation/test.yaml new file mode 100644 index 0000000000..2410223e59 --- /dev/null +++ b/gazelle/python/testdata/disable_import_statements_validation/test.yaml @@ -0,0 +1,17 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- +expect: + exit_code: 0 diff --git a/gazelle/testdata/dont_rename_target/BUILD.in b/gazelle/python/testdata/dont_rename_target/BUILD.in similarity index 100% rename from gazelle/testdata/dont_rename_target/BUILD.in rename to gazelle/python/testdata/dont_rename_target/BUILD.in diff --git a/gazelle/testdata/dont_rename_target/BUILD.out b/gazelle/python/testdata/dont_rename_target/BUILD.out similarity index 100% rename from gazelle/testdata/dont_rename_target/BUILD.out rename to gazelle/python/testdata/dont_rename_target/BUILD.out diff --git a/gazelle/testdata/dont_rename_target/README.md b/gazelle/python/testdata/dont_rename_target/README.md similarity index 100% rename from gazelle/testdata/dont_rename_target/README.md rename to gazelle/python/testdata/dont_rename_target/README.md diff --git a/gazelle/testdata/dont_rename_target/WORKSPACE b/gazelle/python/testdata/dont_rename_target/WORKSPACE similarity index 100% rename from gazelle/testdata/dont_rename_target/WORKSPACE rename to gazelle/python/testdata/dont_rename_target/WORKSPACE diff --git a/gazelle/python/testdata/dont_rename_target/__init__.py b/gazelle/python/testdata/dont_rename_target/__init__.py new file mode 100644 index 0000000000..bbdfb4c588 --- /dev/null +++ b/gazelle/python/testdata/dont_rename_target/__init__.py @@ -0,0 +1,14 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + diff --git a/gazelle/python/testdata/dont_rename_target/test.yaml b/gazelle/python/testdata/dont_rename_target/test.yaml new file mode 100644 index 0000000000..fcea77710f --- /dev/null +++ b/gazelle/python/testdata/dont_rename_target/test.yaml @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- diff --git a/gazelle/testdata/file_name_matches_import_statement/BUILD.in b/gazelle/python/testdata/file_name_matches_import_statement/BUILD.in similarity index 100% rename from gazelle/testdata/file_name_matches_import_statement/BUILD.in rename to gazelle/python/testdata/file_name_matches_import_statement/BUILD.in diff --git a/gazelle/testdata/file_name_matches_import_statement/BUILD.out b/gazelle/python/testdata/file_name_matches_import_statement/BUILD.out similarity index 78% rename from gazelle/testdata/file_name_matches_import_statement/BUILD.out rename to gazelle/python/testdata/file_name_matches_import_statement/BUILD.out index fd6c48559d..0216e4b2e3 100644 --- a/gazelle/testdata/file_name_matches_import_statement/BUILD.out +++ b/gazelle/python/testdata/file_name_matches_import_statement/BUILD.out @@ -7,5 +7,5 @@ py_library( "rest_framework.py", ], visibility = ["//:__subpackages__"], - deps = ["@gazelle_python_test//pypi__djangorestframework"], + deps = ["@gazelle_python_test_djangorestframework//:pkg"], ) diff --git a/gazelle/testdata/file_name_matches_import_statement/README.md b/gazelle/python/testdata/file_name_matches_import_statement/README.md similarity index 100% rename from gazelle/testdata/file_name_matches_import_statement/README.md rename to gazelle/python/testdata/file_name_matches_import_statement/README.md diff --git a/gazelle/testdata/file_name_matches_import_statement/WORKSPACE b/gazelle/python/testdata/file_name_matches_import_statement/WORKSPACE similarity index 100% rename from gazelle/testdata/file_name_matches_import_statement/WORKSPACE rename to gazelle/python/testdata/file_name_matches_import_statement/WORKSPACE diff --git a/gazelle/python/testdata/file_name_matches_import_statement/__init__.py b/gazelle/python/testdata/file_name_matches_import_statement/__init__.py new file mode 100644 index 0000000000..730755995d --- /dev/null +++ b/gazelle/python/testdata/file_name_matches_import_statement/__init__.py @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For test purposes only. diff --git a/gazelle/python/testdata/file_name_matches_import_statement/gazelle_python.yaml b/gazelle/python/testdata/file_name_matches_import_statement/gazelle_python.yaml new file mode 100644 index 0000000000..f50d3ae397 --- /dev/null +++ b/gazelle/python/testdata/file_name_matches_import_statement/gazelle_python.yaml @@ -0,0 +1,18 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +manifest: + modules_mapping: + rest_framework: djangorestframework + pip_deps_repository_name: gazelle_python_test diff --git a/gazelle/python/testdata/file_name_matches_import_statement/rest_framework.py b/gazelle/python/testdata/file_name_matches_import_statement/rest_framework.py new file mode 100644 index 0000000000..43098d29e2 --- /dev/null +++ b/gazelle/python/testdata/file_name_matches_import_statement/rest_framework.py @@ -0,0 +1,17 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import rest_framework + +_ = rest_framework diff --git a/gazelle/python/testdata/file_name_matches_import_statement/test.yaml b/gazelle/python/testdata/file_name_matches_import_statement/test.yaml new file mode 100644 index 0000000000..fcea77710f --- /dev/null +++ b/gazelle/python/testdata/file_name_matches_import_statement/test.yaml @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- diff --git a/gazelle/testdata/first_party_dependencies/BUILD.in b/gazelle/python/testdata/first_party_dependencies/BUILD.in similarity index 100% rename from gazelle/testdata/first_party_dependencies/BUILD.in rename to gazelle/python/testdata/first_party_dependencies/BUILD.in diff --git a/gazelle/testdata/first_party_dependencies/BUILD.out b/gazelle/python/testdata/first_party_dependencies/BUILD.out similarity index 100% rename from gazelle/testdata/first_party_dependencies/BUILD.out rename to gazelle/python/testdata/first_party_dependencies/BUILD.out diff --git a/gazelle/testdata/first_party_dependencies/README.md b/gazelle/python/testdata/first_party_dependencies/README.md similarity index 100% rename from gazelle/testdata/first_party_dependencies/README.md rename to gazelle/python/testdata/first_party_dependencies/README.md diff --git a/gazelle/testdata/first_party_dependencies/WORKSPACE b/gazelle/python/testdata/first_party_dependencies/WORKSPACE similarity index 100% rename from gazelle/testdata/first_party_dependencies/WORKSPACE rename to gazelle/python/testdata/first_party_dependencies/WORKSPACE diff --git a/gazelle/testdata/first_party_dependencies/one/BUILD.in b/gazelle/python/testdata/first_party_dependencies/one/BUILD.in similarity index 100% rename from gazelle/testdata/first_party_dependencies/one/BUILD.in rename to gazelle/python/testdata/first_party_dependencies/one/BUILD.in diff --git a/gazelle/testdata/first_party_dependencies/one/BUILD.out b/gazelle/python/testdata/first_party_dependencies/one/BUILD.out similarity index 100% rename from gazelle/testdata/first_party_dependencies/one/BUILD.out rename to gazelle/python/testdata/first_party_dependencies/one/BUILD.out diff --git a/gazelle/python/testdata/first_party_dependencies/one/__main__.py b/gazelle/python/testdata/first_party_dependencies/one/__main__.py new file mode 100644 index 0000000000..efc7900d53 --- /dev/null +++ b/gazelle/python/testdata/first_party_dependencies/one/__main__.py @@ -0,0 +1,26 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +from bar import bar +from bar.baz import baz +from foo import foo + +if __name__ == "__main__": + INIT_FILENAME = "__init__.py" + dirname = os.path.dirname(os.path.abspath(__file__)) + assert bar() == os.path.join(dirname, "bar", INIT_FILENAME) + assert baz() == os.path.join(dirname, "bar", "baz", INIT_FILENAME) + assert foo() == os.path.join(dirname, "foo", INIT_FILENAME) diff --git a/gazelle/testdata/first_party_dependencies/one/bar/BUILD.in b/gazelle/python/testdata/first_party_dependencies/one/bar/BUILD.in similarity index 100% rename from gazelle/testdata/first_party_dependencies/one/bar/BUILD.in rename to gazelle/python/testdata/first_party_dependencies/one/bar/BUILD.in diff --git a/gazelle/testdata/first_party_dependencies/one/bar/BUILD.out b/gazelle/python/testdata/first_party_dependencies/one/bar/BUILD.out similarity index 100% rename from gazelle/testdata/first_party_dependencies/one/bar/BUILD.out rename to gazelle/python/testdata/first_party_dependencies/one/bar/BUILD.out diff --git a/gazelle/python/testdata/first_party_dependencies/one/bar/__init__.py b/gazelle/python/testdata/first_party_dependencies/one/bar/__init__.py new file mode 100644 index 0000000000..d4b5fb84f1 --- /dev/null +++ b/gazelle/python/testdata/first_party_dependencies/one/bar/__init__.py @@ -0,0 +1,19 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + + +def bar(): + return os.path.abspath(__file__) diff --git a/gazelle/testdata/first_party_dependencies/one/bar/baz/BUILD.in b/gazelle/python/testdata/first_party_dependencies/one/bar/baz/BUILD.in similarity index 100% rename from gazelle/testdata/first_party_dependencies/one/bar/baz/BUILD.in rename to gazelle/python/testdata/first_party_dependencies/one/bar/baz/BUILD.in diff --git a/gazelle/testdata/first_party_dependencies/one/bar/baz/BUILD.out b/gazelle/python/testdata/first_party_dependencies/one/bar/baz/BUILD.out similarity index 100% rename from gazelle/testdata/first_party_dependencies/one/bar/baz/BUILD.out rename to gazelle/python/testdata/first_party_dependencies/one/bar/baz/BUILD.out diff --git a/gazelle/python/testdata/first_party_dependencies/one/bar/baz/__init__.py b/gazelle/python/testdata/first_party_dependencies/one/bar/baz/__init__.py new file mode 100644 index 0000000000..5be74a7d3e --- /dev/null +++ b/gazelle/python/testdata/first_party_dependencies/one/bar/baz/__init__.py @@ -0,0 +1,19 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + + +def baz(): + return os.path.abspath(__file__) diff --git a/gazelle/testdata/first_party_dependencies/one/foo/BUILD.in b/gazelle/python/testdata/first_party_dependencies/one/foo/BUILD.in similarity index 100% rename from gazelle/testdata/first_party_dependencies/one/foo/BUILD.in rename to gazelle/python/testdata/first_party_dependencies/one/foo/BUILD.in diff --git a/gazelle/testdata/first_party_dependencies/one/foo/BUILD.out b/gazelle/python/testdata/first_party_dependencies/one/foo/BUILD.out similarity index 100% rename from gazelle/testdata/first_party_dependencies/one/foo/BUILD.out rename to gazelle/python/testdata/first_party_dependencies/one/foo/BUILD.out diff --git a/gazelle/python/testdata/first_party_dependencies/one/foo/__init__.py b/gazelle/python/testdata/first_party_dependencies/one/foo/__init__.py new file mode 100644 index 0000000000..978fb74567 --- /dev/null +++ b/gazelle/python/testdata/first_party_dependencies/one/foo/__init__.py @@ -0,0 +1,19 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + + +def foo(): + return os.path.abspath(__file__) diff --git a/gazelle/python/testdata/first_party_dependencies/test.yaml b/gazelle/python/testdata/first_party_dependencies/test.yaml new file mode 100644 index 0000000000..fcea77710f --- /dev/null +++ b/gazelle/python/testdata/first_party_dependencies/test.yaml @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- diff --git a/gazelle/testdata/first_party_dependencies/three/BUILD.in b/gazelle/python/testdata/first_party_dependencies/three/BUILD.in similarity index 100% rename from gazelle/testdata/first_party_dependencies/three/BUILD.in rename to gazelle/python/testdata/first_party_dependencies/three/BUILD.in diff --git a/gazelle/testdata/first_party_dependencies/three/BUILD.out b/gazelle/python/testdata/first_party_dependencies/three/BUILD.out similarity index 100% rename from gazelle/testdata/first_party_dependencies/three/BUILD.out rename to gazelle/python/testdata/first_party_dependencies/three/BUILD.out diff --git a/gazelle/python/testdata/first_party_dependencies/three/__init__.py b/gazelle/python/testdata/first_party_dependencies/three/__init__.py new file mode 100644 index 0000000000..9f7d123649 --- /dev/null +++ b/gazelle/python/testdata/first_party_dependencies/three/__init__.py @@ -0,0 +1,24 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +from bar import bar +from bar.baz import baz +from foo import foo + +_ = os +_ = bar +_ = baz +_ = foo diff --git a/gazelle/testdata/first_party_dependencies/two/BUILD.in b/gazelle/python/testdata/first_party_dependencies/two/BUILD.in similarity index 100% rename from gazelle/testdata/first_party_dependencies/two/BUILD.in rename to gazelle/python/testdata/first_party_dependencies/two/BUILD.in diff --git a/gazelle/testdata/first_party_dependencies/two/BUILD.out b/gazelle/python/testdata/first_party_dependencies/two/BUILD.out similarity index 100% rename from gazelle/testdata/first_party_dependencies/two/BUILD.out rename to gazelle/python/testdata/first_party_dependencies/two/BUILD.out diff --git a/gazelle/python/testdata/first_party_dependencies/two/__init__.py b/gazelle/python/testdata/first_party_dependencies/two/__init__.py new file mode 100644 index 0000000000..88ff57bf1b --- /dev/null +++ b/gazelle/python/testdata/first_party_dependencies/two/__init__.py @@ -0,0 +1,20 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +from foo import foo + +_ = os +_ = foo diff --git a/gazelle/testdata/first_party_file_and_directory_modules/BUILD.in b/gazelle/python/testdata/first_party_file_and_directory_modules/BUILD.in similarity index 100% rename from gazelle/testdata/first_party_file_and_directory_modules/BUILD.in rename to gazelle/python/testdata/first_party_file_and_directory_modules/BUILD.in diff --git a/gazelle/testdata/first_party_file_and_directory_modules/BUILD.out b/gazelle/python/testdata/first_party_file_and_directory_modules/BUILD.out similarity index 100% rename from gazelle/testdata/first_party_file_and_directory_modules/BUILD.out rename to gazelle/python/testdata/first_party_file_and_directory_modules/BUILD.out diff --git a/gazelle/testdata/first_party_file_and_directory_modules/README.md b/gazelle/python/testdata/first_party_file_and_directory_modules/README.md similarity index 100% rename from gazelle/testdata/first_party_file_and_directory_modules/README.md rename to gazelle/python/testdata/first_party_file_and_directory_modules/README.md diff --git a/gazelle/testdata/first_party_file_and_directory_modules/WORKSPACE b/gazelle/python/testdata/first_party_file_and_directory_modules/WORKSPACE similarity index 100% rename from gazelle/testdata/first_party_file_and_directory_modules/WORKSPACE rename to gazelle/python/testdata/first_party_file_and_directory_modules/WORKSPACE diff --git a/gazelle/python/testdata/first_party_file_and_directory_modules/__main__.py b/gazelle/python/testdata/first_party_file_and_directory_modules/__main__.py new file mode 100644 index 0000000000..242448d348 --- /dev/null +++ b/gazelle/python/testdata/first_party_file_and_directory_modules/__main__.py @@ -0,0 +1,25 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import foo +from baz import baz as another_baz +from foo.bar import baz +from one.two import two +from package1.subpackage1.module1 import find_me + +assert not hasattr(foo, "foo") +assert baz() == "baz from foo/bar.py" +assert another_baz() == "baz from baz.py" +assert two() == "two" +assert find_me() == "found" diff --git a/gazelle/python/testdata/first_party_file_and_directory_modules/baz.py b/gazelle/python/testdata/first_party_file_and_directory_modules/baz.py new file mode 100644 index 0000000000..e03a9ecb9d --- /dev/null +++ b/gazelle/python/testdata/first_party_file_and_directory_modules/baz.py @@ -0,0 +1,16 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +def baz(): + return "baz from baz.py" diff --git a/gazelle/python/testdata/first_party_file_and_directory_modules/foo.py b/gazelle/python/testdata/first_party_file_and_directory_modules/foo.py new file mode 100644 index 0000000000..04474d83a8 --- /dev/null +++ b/gazelle/python/testdata/first_party_file_and_directory_modules/foo.py @@ -0,0 +1,16 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +def foo(): + print("foo") diff --git a/gazelle/testdata/first_party_file_and_directory_modules/foo/BUILD.in b/gazelle/python/testdata/first_party_file_and_directory_modules/foo/BUILD.in similarity index 100% rename from gazelle/testdata/first_party_file_and_directory_modules/foo/BUILD.in rename to gazelle/python/testdata/first_party_file_and_directory_modules/foo/BUILD.in diff --git a/gazelle/testdata/first_party_file_and_directory_modules/foo/BUILD.out b/gazelle/python/testdata/first_party_file_and_directory_modules/foo/BUILD.out similarity index 100% rename from gazelle/testdata/first_party_file_and_directory_modules/foo/BUILD.out rename to gazelle/python/testdata/first_party_file_and_directory_modules/foo/BUILD.out diff --git a/gazelle/python/testdata/first_party_file_and_directory_modules/foo/__init__.py b/gazelle/python/testdata/first_party_file_and_directory_modules/foo/__init__.py new file mode 100644 index 0000000000..730755995d --- /dev/null +++ b/gazelle/python/testdata/first_party_file_and_directory_modules/foo/__init__.py @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For test purposes only. diff --git a/gazelle/python/testdata/first_party_file_and_directory_modules/foo/bar.py b/gazelle/python/testdata/first_party_file_and_directory_modules/foo/bar.py new file mode 100644 index 0000000000..dacf2d42b2 --- /dev/null +++ b/gazelle/python/testdata/first_party_file_and_directory_modules/foo/bar.py @@ -0,0 +1,21 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import one.two as two + +_ = two + + +def baz(): + return "baz from foo/bar.py" diff --git a/gazelle/testdata/first_party_file_and_directory_modules/one/BUILD.in b/gazelle/python/testdata/first_party_file_and_directory_modules/one/BUILD.in similarity index 100% rename from gazelle/testdata/first_party_file_and_directory_modules/one/BUILD.in rename to gazelle/python/testdata/first_party_file_and_directory_modules/one/BUILD.in diff --git a/gazelle/testdata/first_party_file_and_directory_modules/one/BUILD.out b/gazelle/python/testdata/first_party_file_and_directory_modules/one/BUILD.out similarity index 100% rename from gazelle/testdata/first_party_file_and_directory_modules/one/BUILD.out rename to gazelle/python/testdata/first_party_file_and_directory_modules/one/BUILD.out diff --git a/gazelle/python/testdata/first_party_file_and_directory_modules/one/__init__.py b/gazelle/python/testdata/first_party_file_and_directory_modules/one/__init__.py new file mode 100644 index 0000000000..730755995d --- /dev/null +++ b/gazelle/python/testdata/first_party_file_and_directory_modules/one/__init__.py @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For test purposes only. diff --git a/gazelle/python/testdata/first_party_file_and_directory_modules/one/two.py b/gazelle/python/testdata/first_party_file_and_directory_modules/one/two.py new file mode 100644 index 0000000000..94cca3d002 --- /dev/null +++ b/gazelle/python/testdata/first_party_file_and_directory_modules/one/two.py @@ -0,0 +1,16 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +def two(): + return "two" diff --git a/gazelle/python/testdata/first_party_file_and_directory_modules/test.yaml b/gazelle/python/testdata/first_party_file_and_directory_modules/test.yaml new file mode 100644 index 0000000000..fcea77710f --- /dev/null +++ b/gazelle/python/testdata/first_party_file_and_directory_modules/test.yaml @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- diff --git a/gazelle/testdata/first_party_file_and_directory_modules/undiscoverable/BUILD.in b/gazelle/python/testdata/first_party_file_and_directory_modules/undiscoverable/BUILD.in similarity index 100% rename from gazelle/testdata/first_party_file_and_directory_modules/undiscoverable/BUILD.in rename to gazelle/python/testdata/first_party_file_and_directory_modules/undiscoverable/BUILD.in diff --git a/gazelle/testdata/first_party_file_and_directory_modules/undiscoverable/BUILD.out b/gazelle/python/testdata/first_party_file_and_directory_modules/undiscoverable/BUILD.out similarity index 100% rename from gazelle/testdata/first_party_file_and_directory_modules/undiscoverable/BUILD.out rename to gazelle/python/testdata/first_party_file_and_directory_modules/undiscoverable/BUILD.out diff --git a/gazelle/testdata/first_party_file_and_directory_modules/undiscoverable/package1/subpackage1/BUILD.in b/gazelle/python/testdata/first_party_file_and_directory_modules/undiscoverable/package1/subpackage1/BUILD.in similarity index 100% rename from gazelle/testdata/first_party_file_and_directory_modules/undiscoverable/package1/subpackage1/BUILD.in rename to gazelle/python/testdata/first_party_file_and_directory_modules/undiscoverable/package1/subpackage1/BUILD.in diff --git a/gazelle/testdata/first_party_file_and_directory_modules/undiscoverable/package1/subpackage1/BUILD.out b/gazelle/python/testdata/first_party_file_and_directory_modules/undiscoverable/package1/subpackage1/BUILD.out similarity index 100% rename from gazelle/testdata/first_party_file_and_directory_modules/undiscoverable/package1/subpackage1/BUILD.out rename to gazelle/python/testdata/first_party_file_and_directory_modules/undiscoverable/package1/subpackage1/BUILD.out diff --git a/gazelle/python/testdata/first_party_file_and_directory_modules/undiscoverable/package1/subpackage1/__init__.py b/gazelle/python/testdata/first_party_file_and_directory_modules/undiscoverable/package1/subpackage1/__init__.py new file mode 100644 index 0000000000..730755995d --- /dev/null +++ b/gazelle/python/testdata/first_party_file_and_directory_modules/undiscoverable/package1/subpackage1/__init__.py @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For test purposes only. diff --git a/gazelle/python/testdata/first_party_file_and_directory_modules/undiscoverable/package1/subpackage1/module1.py b/gazelle/python/testdata/first_party_file_and_directory_modules/undiscoverable/package1/subpackage1/module1.py new file mode 100644 index 0000000000..76c72273fa --- /dev/null +++ b/gazelle/python/testdata/first_party_file_and_directory_modules/undiscoverable/package1/subpackage1/module1.py @@ -0,0 +1,16 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +def find_me(): + return "found" diff --git a/gazelle/testdata/from_imports/BUILD.in b/gazelle/python/testdata/from_imports/BUILD.in similarity index 100% rename from gazelle/testdata/from_imports/BUILD.in rename to gazelle/python/testdata/from_imports/BUILD.in diff --git a/gazelle/testdata/from_imports/BUILD.out b/gazelle/python/testdata/from_imports/BUILD.out similarity index 100% rename from gazelle/testdata/from_imports/BUILD.out rename to gazelle/python/testdata/from_imports/BUILD.out diff --git a/gazelle/testdata/from_imports/README.md b/gazelle/python/testdata/from_imports/README.md similarity index 100% rename from gazelle/testdata/from_imports/README.md rename to gazelle/python/testdata/from_imports/README.md diff --git a/gazelle/testdata/from_imports/WORKSPACE b/gazelle/python/testdata/from_imports/WORKSPACE similarity index 100% rename from gazelle/testdata/from_imports/WORKSPACE rename to gazelle/python/testdata/from_imports/WORKSPACE diff --git a/gazelle/testdata/from_imports/foo/BUILD.in b/gazelle/python/testdata/from_imports/foo/BUILD.in similarity index 100% rename from gazelle/testdata/from_imports/foo/BUILD.in rename to gazelle/python/testdata/from_imports/foo/BUILD.in diff --git a/gazelle/testdata/from_imports/foo/BUILD.out b/gazelle/python/testdata/from_imports/foo/BUILD.out similarity index 100% rename from gazelle/testdata/from_imports/foo/BUILD.out rename to gazelle/python/testdata/from_imports/foo/BUILD.out diff --git a/gazelle/python/testdata/from_imports/foo/__init__.py b/gazelle/python/testdata/from_imports/foo/__init__.py new file mode 100644 index 0000000000..d0f74a859a --- /dev/null +++ b/gazelle/python/testdata/from_imports/foo/__init__.py @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +foo = "foo" diff --git a/gazelle/testdata/from_imports/foo/bar/BUILD.in b/gazelle/python/testdata/from_imports/foo/bar/BUILD.in similarity index 100% rename from gazelle/testdata/from_imports/foo/bar/BUILD.in rename to gazelle/python/testdata/from_imports/foo/bar/BUILD.in diff --git a/gazelle/testdata/from_imports/foo/bar/BUILD.out b/gazelle/python/testdata/from_imports/foo/bar/BUILD.out similarity index 100% rename from gazelle/testdata/from_imports/foo/bar/BUILD.out rename to gazelle/python/testdata/from_imports/foo/bar/BUILD.out diff --git a/gazelle/python/testdata/from_imports/foo/bar/__init__.py b/gazelle/python/testdata/from_imports/foo/bar/__init__.py new file mode 100644 index 0000000000..240f382ac6 --- /dev/null +++ b/gazelle/python/testdata/from_imports/foo/bar/__init__.py @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +bar = "bar" diff --git a/gazelle/python/testdata/from_imports/foo/bar/baz.py b/gazelle/python/testdata/from_imports/foo/bar/baz.py new file mode 100644 index 0000000000..9aeae611db --- /dev/null +++ b/gazelle/python/testdata/from_imports/foo/bar/baz.py @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +baz = "baz" diff --git a/gazelle/python/testdata/from_imports/gazelle_python.yaml b/gazelle/python/testdata/from_imports/gazelle_python.yaml new file mode 100644 index 0000000000..132854e842 --- /dev/null +++ b/gazelle/python/testdata/from_imports/gazelle_python.yaml @@ -0,0 +1,19 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +manifest: + modules_mapping: + boto3: rootboto3 + boto4: rootboto4 + pip_deps_repository_name: root_pip_deps diff --git a/gazelle/testdata/from_imports/import_from_init_py/BUILD.in b/gazelle/python/testdata/from_imports/import_from_init_py/BUILD.in similarity index 100% rename from gazelle/testdata/from_imports/import_from_init_py/BUILD.in rename to gazelle/python/testdata/from_imports/import_from_init_py/BUILD.in diff --git a/gazelle/testdata/from_imports/import_from_init_py/BUILD.out b/gazelle/python/testdata/from_imports/import_from_init_py/BUILD.out similarity index 100% rename from gazelle/testdata/from_imports/import_from_init_py/BUILD.out rename to gazelle/python/testdata/from_imports/import_from_init_py/BUILD.out diff --git a/gazelle/python/testdata/from_imports/import_from_init_py/__init__.py b/gazelle/python/testdata/from_imports/import_from_init_py/__init__.py new file mode 100644 index 0000000000..bd6d8a550f --- /dev/null +++ b/gazelle/python/testdata/from_imports/import_from_init_py/__init__.py @@ -0,0 +1,16 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# bar is a variable inside foo/bar/__init__.py +from foo.bar import bar diff --git a/gazelle/testdata/from_imports/import_from_multiple/BUILD.in b/gazelle/python/testdata/from_imports/import_from_multiple/BUILD.in similarity index 100% rename from gazelle/testdata/from_imports/import_from_multiple/BUILD.in rename to gazelle/python/testdata/from_imports/import_from_multiple/BUILD.in diff --git a/gazelle/testdata/from_imports/import_from_multiple/BUILD.out b/gazelle/python/testdata/from_imports/import_from_multiple/BUILD.out similarity index 100% rename from gazelle/testdata/from_imports/import_from_multiple/BUILD.out rename to gazelle/python/testdata/from_imports/import_from_multiple/BUILD.out diff --git a/gazelle/python/testdata/from_imports/import_from_multiple/__init__.py b/gazelle/python/testdata/from_imports/import_from_multiple/__init__.py new file mode 100644 index 0000000000..05cd10460a --- /dev/null +++ b/gazelle/python/testdata/from_imports/import_from_multiple/__init__.py @@ -0,0 +1,16 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Import multiple values from the same import. +from foo.bar import bar, baz diff --git a/gazelle/testdata/from_imports/import_nested_file/BUILD.in b/gazelle/python/testdata/from_imports/import_nested_file/BUILD.in similarity index 100% rename from gazelle/testdata/from_imports/import_nested_file/BUILD.in rename to gazelle/python/testdata/from_imports/import_nested_file/BUILD.in diff --git a/gazelle/testdata/from_imports/import_nested_file/BUILD.out b/gazelle/python/testdata/from_imports/import_nested_file/BUILD.out similarity index 100% rename from gazelle/testdata/from_imports/import_nested_file/BUILD.out rename to gazelle/python/testdata/from_imports/import_nested_file/BUILD.out diff --git a/gazelle/python/testdata/from_imports/import_nested_file/__init__.py b/gazelle/python/testdata/from_imports/import_nested_file/__init__.py new file mode 100644 index 0000000000..55a1621628 --- /dev/null +++ b/gazelle/python/testdata/from_imports/import_nested_file/__init__.py @@ -0,0 +1,16 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# baz.py is a file at foo/bar/baz.py +from foo.bar import baz diff --git a/gazelle/testdata/from_imports/import_nested_module/BUILD.in b/gazelle/python/testdata/from_imports/import_nested_module/BUILD.in similarity index 100% rename from gazelle/testdata/from_imports/import_nested_module/BUILD.in rename to gazelle/python/testdata/from_imports/import_nested_module/BUILD.in diff --git a/gazelle/testdata/from_imports/import_nested_module/BUILD.out b/gazelle/python/testdata/from_imports/import_nested_module/BUILD.out similarity index 100% rename from gazelle/testdata/from_imports/import_nested_module/BUILD.out rename to gazelle/python/testdata/from_imports/import_nested_module/BUILD.out diff --git a/gazelle/python/testdata/from_imports/import_nested_module/__init__.py b/gazelle/python/testdata/from_imports/import_nested_module/__init__.py new file mode 100644 index 0000000000..96fa0e5ecb --- /dev/null +++ b/gazelle/python/testdata/from_imports/import_nested_module/__init__.py @@ -0,0 +1,16 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# bar is a module at foo/bar/__init__.py +from foo import bar diff --git a/gazelle/testdata/from_imports/import_nested_var/BUILD.in b/gazelle/python/testdata/from_imports/import_nested_var/BUILD.in similarity index 100% rename from gazelle/testdata/from_imports/import_nested_var/BUILD.in rename to gazelle/python/testdata/from_imports/import_nested_var/BUILD.in diff --git a/gazelle/testdata/from_imports/import_nested_var/BUILD.out b/gazelle/python/testdata/from_imports/import_nested_var/BUILD.out similarity index 100% rename from gazelle/testdata/from_imports/import_nested_var/BUILD.out rename to gazelle/python/testdata/from_imports/import_nested_var/BUILD.out diff --git a/gazelle/python/testdata/from_imports/import_nested_var/__init__.py b/gazelle/python/testdata/from_imports/import_nested_var/__init__.py new file mode 100644 index 0000000000..d0f51c443c --- /dev/null +++ b/gazelle/python/testdata/from_imports/import_nested_var/__init__.py @@ -0,0 +1,16 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# baz is a variable in foo/bar/baz.py +from foo.bar.baz import baz diff --git a/gazelle/testdata/from_imports/import_top_level_var/BUILD.in b/gazelle/python/testdata/from_imports/import_top_level_var/BUILD.in similarity index 100% rename from gazelle/testdata/from_imports/import_top_level_var/BUILD.in rename to gazelle/python/testdata/from_imports/import_top_level_var/BUILD.in diff --git a/gazelle/testdata/from_imports/import_top_level_var/BUILD.out b/gazelle/python/testdata/from_imports/import_top_level_var/BUILD.out similarity index 100% rename from gazelle/testdata/from_imports/import_top_level_var/BUILD.out rename to gazelle/python/testdata/from_imports/import_top_level_var/BUILD.out diff --git a/gazelle/python/testdata/from_imports/import_top_level_var/__init__.py b/gazelle/python/testdata/from_imports/import_top_level_var/__init__.py new file mode 100644 index 0000000000..71dd7c482f --- /dev/null +++ b/gazelle/python/testdata/from_imports/import_top_level_var/__init__.py @@ -0,0 +1,16 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# foo is a variable in foo/__init__.py +from foo import foo diff --git a/gazelle/testdata/from_imports/std_module/BUILD.in b/gazelle/python/testdata/from_imports/std_module/BUILD.in similarity index 100% rename from gazelle/testdata/from_imports/std_module/BUILD.in rename to gazelle/python/testdata/from_imports/std_module/BUILD.in diff --git a/gazelle/testdata/from_imports/std_module/BUILD.out b/gazelle/python/testdata/from_imports/std_module/BUILD.out similarity index 100% rename from gazelle/testdata/from_imports/std_module/BUILD.out rename to gazelle/python/testdata/from_imports/std_module/BUILD.out diff --git a/gazelle/python/testdata/from_imports/std_module/__init__.py b/gazelle/python/testdata/from_imports/std_module/__init__.py new file mode 100644 index 0000000000..5518cc0239 --- /dev/null +++ b/gazelle/python/testdata/from_imports/std_module/__init__.py @@ -0,0 +1,17 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Gazelle should recognize this from import +# as the standard module __future__. +from __future__ import print_function diff --git a/gazelle/python/testdata/from_imports/test.yaml b/gazelle/python/testdata/from_imports/test.yaml new file mode 100644 index 0000000000..fcea77710f --- /dev/null +++ b/gazelle/python/testdata/from_imports/test.yaml @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- diff --git a/gazelle/testdata/generated_test_entrypoint/BUILD.in b/gazelle/python/testdata/generated_test_entrypoint/BUILD.in similarity index 100% rename from gazelle/testdata/generated_test_entrypoint/BUILD.in rename to gazelle/python/testdata/generated_test_entrypoint/BUILD.in diff --git a/gazelle/testdata/generated_test_entrypoint/BUILD.out b/gazelle/python/testdata/generated_test_entrypoint/BUILD.out similarity index 82% rename from gazelle/testdata/generated_test_entrypoint/BUILD.out rename to gazelle/python/testdata/generated_test_entrypoint/BUILD.out index 48df0688a6..e8e304c72b 100644 --- a/gazelle/testdata/generated_test_entrypoint/BUILD.out +++ b/gazelle/python/testdata/generated_test_entrypoint/BUILD.out @@ -17,8 +17,5 @@ py_test( name = "generated_test_entrypoint_test", srcs = [":__test__"], main = ":__test__.py", - deps = [ - ":__test__", - ":generated_test_entrypoint", - ], + deps = [":__test__"], ) diff --git a/gazelle/testdata/generated_test_entrypoint/README.md b/gazelle/python/testdata/generated_test_entrypoint/README.md similarity index 100% rename from gazelle/testdata/generated_test_entrypoint/README.md rename to gazelle/python/testdata/generated_test_entrypoint/README.md diff --git a/gazelle/testdata/generated_test_entrypoint/WORKSPACE b/gazelle/python/testdata/generated_test_entrypoint/WORKSPACE similarity index 100% rename from gazelle/testdata/generated_test_entrypoint/WORKSPACE rename to gazelle/python/testdata/generated_test_entrypoint/WORKSPACE diff --git a/gazelle/python/testdata/generated_test_entrypoint/__init__.py b/gazelle/python/testdata/generated_test_entrypoint/__init__.py new file mode 100644 index 0000000000..b274b0d921 --- /dev/null +++ b/gazelle/python/testdata/generated_test_entrypoint/__init__.py @@ -0,0 +1,17 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from foo import foo + +_ = foo diff --git a/gazelle/python/testdata/generated_test_entrypoint/foo.py b/gazelle/python/testdata/generated_test_entrypoint/foo.py new file mode 100644 index 0000000000..932de45b74 --- /dev/null +++ b/gazelle/python/testdata/generated_test_entrypoint/foo.py @@ -0,0 +1,16 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +def foo(): + return "foo" diff --git a/gazelle/python/testdata/generated_test_entrypoint/test.yaml b/gazelle/python/testdata/generated_test_entrypoint/test.yaml new file mode 100644 index 0000000000..fcea77710f --- /dev/null +++ b/gazelle/python/testdata/generated_test_entrypoint/test.yaml @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- diff --git a/gazelle/testdata/ignored_invalid_imported_module/BUILD.in b/gazelle/python/testdata/ignored_invalid_imported_module/BUILD.in similarity index 100% rename from gazelle/testdata/ignored_invalid_imported_module/BUILD.in rename to gazelle/python/testdata/ignored_invalid_imported_module/BUILD.in diff --git a/gazelle/testdata/ignored_invalid_imported_module/BUILD.out b/gazelle/python/testdata/ignored_invalid_imported_module/BUILD.out similarity index 79% rename from gazelle/testdata/ignored_invalid_imported_module/BUILD.out rename to gazelle/python/testdata/ignored_invalid_imported_module/BUILD.out index 3cd47a6fe0..b8c936a7dd 100644 --- a/gazelle/testdata/ignored_invalid_imported_module/BUILD.out +++ b/gazelle/python/testdata/ignored_invalid_imported_module/BUILD.out @@ -4,5 +4,5 @@ py_library( name = "ignored_invalid_imported_module", srcs = ["__init__.py"], visibility = ["//:__subpackages__"], - deps = ["@gazelle_python_test//pypi__foo"], + deps = ["@gazelle_python_test_foo//:pkg"], ) diff --git a/gazelle/testdata/ignored_invalid_imported_module/README.md b/gazelle/python/testdata/ignored_invalid_imported_module/README.md similarity index 100% rename from gazelle/testdata/ignored_invalid_imported_module/README.md rename to gazelle/python/testdata/ignored_invalid_imported_module/README.md diff --git a/gazelle/testdata/ignored_invalid_imported_module/WORKSPACE b/gazelle/python/testdata/ignored_invalid_imported_module/WORKSPACE similarity index 100% rename from gazelle/testdata/ignored_invalid_imported_module/WORKSPACE rename to gazelle/python/testdata/ignored_invalid_imported_module/WORKSPACE diff --git a/gazelle/python/testdata/ignored_invalid_imported_module/__init__.py b/gazelle/python/testdata/ignored_invalid_imported_module/__init__.py new file mode 100644 index 0000000000..a094ed0332 --- /dev/null +++ b/gazelle/python/testdata/ignored_invalid_imported_module/__init__.py @@ -0,0 +1,36 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# gazelle:ignore abcdefg1,abcdefg2 +# gazelle:ignore abcdefg3 + +import abcdefg1 +import abcdefg2 +import abcdefg3 +import foo + +_ = abcdefg1 +_ = abcdefg2 +_ = abcdefg3 +_ = foo + +try: + # gazelle:ignore grpc + import grpc + + grpc_available = True +except ImportError: + grpc_available = False + +_ = grpc diff --git a/gazelle/python/testdata/ignored_invalid_imported_module/gazelle_python.yaml b/gazelle/python/testdata/ignored_invalid_imported_module/gazelle_python.yaml new file mode 100644 index 0000000000..4b12372b4e --- /dev/null +++ b/gazelle/python/testdata/ignored_invalid_imported_module/gazelle_python.yaml @@ -0,0 +1,18 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +manifest: + modules_mapping: + foo: foo + pip_deps_repository_name: gazelle_python_test diff --git a/gazelle/python/testdata/ignored_invalid_imported_module/test.yaml b/gazelle/python/testdata/ignored_invalid_imported_module/test.yaml new file mode 100644 index 0000000000..2410223e59 --- /dev/null +++ b/gazelle/python/testdata/ignored_invalid_imported_module/test.yaml @@ -0,0 +1,17 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- +expect: + exit_code: 0 diff --git a/gazelle/testdata/invalid_imported_module/BUILD.in b/gazelle/python/testdata/invalid_annotation/BUILD.in similarity index 100% rename from gazelle/testdata/invalid_imported_module/BUILD.in rename to gazelle/python/testdata/invalid_annotation/BUILD.in diff --git a/gazelle/testdata/invalid_imported_module/BUILD.out b/gazelle/python/testdata/invalid_annotation/BUILD.out similarity index 100% rename from gazelle/testdata/invalid_imported_module/BUILD.out rename to gazelle/python/testdata/invalid_annotation/BUILD.out diff --git a/gazelle/python/testdata/invalid_annotation/README.md b/gazelle/python/testdata/invalid_annotation/README.md new file mode 100644 index 0000000000..b2544b5bda --- /dev/null +++ b/gazelle/python/testdata/invalid_annotation/README.md @@ -0,0 +1,2 @@ +# Invalid annotation +This test case asserts that the parse step fails as expected due to invalid annotation format. diff --git a/gazelle/testdata/invalid_imported_module/WORKSPACE b/gazelle/python/testdata/invalid_annotation/WORKSPACE similarity index 100% rename from gazelle/testdata/invalid_imported_module/WORKSPACE rename to gazelle/python/testdata/invalid_annotation/WORKSPACE diff --git a/gazelle/python/testdata/invalid_annotation/__init__.py b/gazelle/python/testdata/invalid_annotation/__init__.py new file mode 100644 index 0000000000..7aee8768ad --- /dev/null +++ b/gazelle/python/testdata/invalid_annotation/__init__.py @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# gazelle:ignore diff --git a/gazelle/python/testdata/invalid_annotation/test.yaml b/gazelle/python/testdata/invalid_annotation/test.yaml new file mode 100644 index 0000000000..19924b1288 --- /dev/null +++ b/gazelle/python/testdata/invalid_annotation/test.yaml @@ -0,0 +1,19 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- +expect: + exit_code: 1 + stderr: | + gazelle: ERROR: failed to parse annotations: `# gazelle:ignore` requires a value diff --git a/gazelle/testdata/monorepo/wont_generate/BUILD.in b/gazelle/python/testdata/invalid_imported_module/BUILD.in similarity index 100% rename from gazelle/testdata/monorepo/wont_generate/BUILD.in rename to gazelle/python/testdata/invalid_imported_module/BUILD.in diff --git a/gazelle/testdata/monorepo/wont_generate/BUILD.out b/gazelle/python/testdata/invalid_imported_module/BUILD.out similarity index 100% rename from gazelle/testdata/monorepo/wont_generate/BUILD.out rename to gazelle/python/testdata/invalid_imported_module/BUILD.out diff --git a/gazelle/testdata/invalid_imported_module/README.md b/gazelle/python/testdata/invalid_imported_module/README.md similarity index 100% rename from gazelle/testdata/invalid_imported_module/README.md rename to gazelle/python/testdata/invalid_imported_module/README.md diff --git a/gazelle/testdata/naming_convention/WORKSPACE b/gazelle/python/testdata/invalid_imported_module/WORKSPACE similarity index 100% rename from gazelle/testdata/naming_convention/WORKSPACE rename to gazelle/python/testdata/invalid_imported_module/WORKSPACE diff --git a/gazelle/python/testdata/invalid_imported_module/__init__.py b/gazelle/python/testdata/invalid_imported_module/__init__.py new file mode 100644 index 0000000000..dc6fb8519e --- /dev/null +++ b/gazelle/python/testdata/invalid_imported_module/__init__.py @@ -0,0 +1,22 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +try: + import grpc + + grpc_available = True +except ImportError: + grpc_available = False + +_ = grpc diff --git a/gazelle/python/testdata/invalid_imported_module/test.yaml b/gazelle/python/testdata/invalid_imported_module/test.yaml new file mode 100644 index 0000000000..6bcea39d2e --- /dev/null +++ b/gazelle/python/testdata/invalid_imported_module/test.yaml @@ -0,0 +1,22 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- +expect: + exit_code: 1 + stderr: | + gazelle: ERROR: failed to validate dependencies for target "//:invalid_imported_module": "grpc" at line 16 from "__init__.py" is an invalid dependency: possible solutions: + 1. Add it as a dependency in the requirements.txt file. + 2. Instruct Gazelle to resolve to a known dependency using the gazelle:resolve directive. + 3. Ignore it with a comment '# gazelle:ignore grpc' in the Python file. diff --git a/gazelle/testdata/monorepo/BUILD.in b/gazelle/python/testdata/monorepo/BUILD.in similarity index 100% rename from gazelle/testdata/monorepo/BUILD.in rename to gazelle/python/testdata/monorepo/BUILD.in diff --git a/gazelle/testdata/monorepo/BUILD.out b/gazelle/python/testdata/monorepo/BUILD.out similarity index 100% rename from gazelle/testdata/monorepo/BUILD.out rename to gazelle/python/testdata/monorepo/BUILD.out diff --git a/gazelle/testdata/monorepo/README.md b/gazelle/python/testdata/monorepo/README.md similarity index 100% rename from gazelle/testdata/monorepo/README.md rename to gazelle/python/testdata/monorepo/README.md diff --git a/gazelle/testdata/monorepo/WORKSPACE b/gazelle/python/testdata/monorepo/WORKSPACE similarity index 100% rename from gazelle/testdata/monorepo/WORKSPACE rename to gazelle/python/testdata/monorepo/WORKSPACE diff --git a/gazelle/python/testdata/monorepo/a/BUILD.in b/gazelle/python/testdata/monorepo/a/BUILD.in new file mode 100644 index 0000000000..265129ea56 --- /dev/null +++ b/gazelle/python/testdata/monorepo/a/BUILD.in @@ -0,0 +1 @@ +# gazelle:exclude bar/baz/hue.py \ No newline at end of file diff --git a/gazelle/python/testdata/monorepo/a/BUILD.out b/gazelle/python/testdata/monorepo/a/BUILD.out new file mode 100644 index 0000000000..265129ea56 --- /dev/null +++ b/gazelle/python/testdata/monorepo/a/BUILD.out @@ -0,0 +1 @@ +# gazelle:exclude bar/baz/hue.py \ No newline at end of file diff --git a/gazelle/python/testdata/monorepo/a/README.md b/gazelle/python/testdata/monorepo/a/README.md new file mode 100644 index 0000000000..84d3bff052 --- /dev/null +++ b/gazelle/python/testdata/monorepo/a/README.md @@ -0,0 +1,3 @@ +# Exclusions +* Intentionally make the directory "a" so Gazelle visit this before "coarse_grained" +* Making sure that the exclusion here doesn't affect coarse_grained/bar/baz/hue.py \ No newline at end of file diff --git a/gazelle/testdata/monorepo/coarse_grained/BUILD.in b/gazelle/python/testdata/monorepo/coarse_grained/BUILD.in similarity index 100% rename from gazelle/testdata/monorepo/coarse_grained/BUILD.in rename to gazelle/python/testdata/monorepo/coarse_grained/BUILD.in diff --git a/gazelle/testdata/monorepo/coarse_grained/BUILD.out b/gazelle/python/testdata/monorepo/coarse_grained/BUILD.out similarity index 90% rename from gazelle/testdata/monorepo/coarse_grained/BUILD.out rename to gazelle/python/testdata/monorepo/coarse_grained/BUILD.out index 0fba9515a1..b11cbbdaad 100644 --- a/gazelle/testdata/monorepo/coarse_grained/BUILD.out +++ b/gazelle/python/testdata/monorepo/coarse_grained/BUILD.out @@ -16,5 +16,5 @@ py_library( "foo/__init__.py", ], visibility = ["//:__subpackages__"], - deps = ["@root_pip_deps//pypi__rootboto3"], + deps = ["@root_pip_deps_rootboto3//:pkg"], ) diff --git a/gazelle/python/testdata/monorepo/coarse_grained/__init__.py b/gazelle/python/testdata/monorepo/coarse_grained/__init__.py new file mode 100644 index 0000000000..6e77327a42 --- /dev/null +++ b/gazelle/python/testdata/monorepo/coarse_grained/__init__.py @@ -0,0 +1,26 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +import boto3 +from bar import bar +from bar.baz import baz +from foo import foo + +_ = os +_ = boto3 +_ = bar +_ = baz +_ = foo diff --git a/gazelle/testdata/monorepo/coarse_grained/_boundary/BUILD.in b/gazelle/python/testdata/monorepo/coarse_grained/_boundary/BUILD.in similarity index 100% rename from gazelle/testdata/monorepo/coarse_grained/_boundary/BUILD.in rename to gazelle/python/testdata/monorepo/coarse_grained/_boundary/BUILD.in diff --git a/gazelle/testdata/monorepo/coarse_grained/_boundary/BUILD.out b/gazelle/python/testdata/monorepo/coarse_grained/_boundary/BUILD.out similarity index 100% rename from gazelle/testdata/monorepo/coarse_grained/_boundary/BUILD.out rename to gazelle/python/testdata/monorepo/coarse_grained/_boundary/BUILD.out diff --git a/gazelle/testdata/monorepo/coarse_grained/_boundary/README.md b/gazelle/python/testdata/monorepo/coarse_grained/_boundary/README.md similarity index 100% rename from gazelle/testdata/monorepo/coarse_grained/_boundary/README.md rename to gazelle/python/testdata/monorepo/coarse_grained/_boundary/README.md diff --git a/gazelle/python/testdata/monorepo/coarse_grained/_boundary/__init__.py b/gazelle/python/testdata/monorepo/coarse_grained/_boundary/__init__.py new file mode 100644 index 0000000000..bbdfb4c588 --- /dev/null +++ b/gazelle/python/testdata/monorepo/coarse_grained/_boundary/__init__.py @@ -0,0 +1,14 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + diff --git a/gazelle/python/testdata/monorepo/coarse_grained/bar/__init__.py b/gazelle/python/testdata/monorepo/coarse_grained/bar/__init__.py new file mode 100644 index 0000000000..499a0903cc --- /dev/null +++ b/gazelle/python/testdata/monorepo/coarse_grained/bar/__init__.py @@ -0,0 +1,23 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +import boto3 + +_ = boto3 + + +def bar(): + return os.path.abspath(__file__) diff --git a/gazelle/python/testdata/monorepo/coarse_grained/bar/baz/__init__.py b/gazelle/python/testdata/monorepo/coarse_grained/bar/baz/__init__.py new file mode 100644 index 0000000000..5be74a7d3e --- /dev/null +++ b/gazelle/python/testdata/monorepo/coarse_grained/bar/baz/__init__.py @@ -0,0 +1,19 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + + +def baz(): + return os.path.abspath(__file__) diff --git a/gazelle/python/testdata/monorepo/coarse_grained/bar/baz/first_excluded.py b/gazelle/python/testdata/monorepo/coarse_grained/bar/baz/first_excluded.py new file mode 100644 index 0000000000..730755995d --- /dev/null +++ b/gazelle/python/testdata/monorepo/coarse_grained/bar/baz/first_excluded.py @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For test purposes only. diff --git a/gazelle/python/testdata/monorepo/coarse_grained/bar/baz/hue.py b/gazelle/python/testdata/monorepo/coarse_grained/bar/baz/hue.py new file mode 100644 index 0000000000..730755995d --- /dev/null +++ b/gazelle/python/testdata/monorepo/coarse_grained/bar/baz/hue.py @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For test purposes only. diff --git a/gazelle/python/testdata/monorepo/coarse_grained/bar/baz/second_excluded.py b/gazelle/python/testdata/monorepo/coarse_grained/bar/baz/second_excluded.py new file mode 100644 index 0000000000..730755995d --- /dev/null +++ b/gazelle/python/testdata/monorepo/coarse_grained/bar/baz/second_excluded.py @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For test purposes only. diff --git a/gazelle/python/testdata/monorepo/coarse_grained/foo/__init__.py b/gazelle/python/testdata/monorepo/coarse_grained/foo/__init__.py new file mode 100644 index 0000000000..978fb74567 --- /dev/null +++ b/gazelle/python/testdata/monorepo/coarse_grained/foo/__init__.py @@ -0,0 +1,19 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + + +def foo(): + return os.path.abspath(__file__) diff --git a/gazelle/python/testdata/monorepo/gazelle_python.yaml b/gazelle/python/testdata/monorepo/gazelle_python.yaml new file mode 100644 index 0000000000..132854e842 --- /dev/null +++ b/gazelle/python/testdata/monorepo/gazelle_python.yaml @@ -0,0 +1,19 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +manifest: + modules_mapping: + boto3: rootboto3 + boto4: rootboto4 + pip_deps_repository_name: root_pip_deps diff --git a/gazelle/testdata/monorepo/one/BUILD.in b/gazelle/python/testdata/monorepo/one/BUILD.in similarity index 100% rename from gazelle/testdata/monorepo/one/BUILD.in rename to gazelle/python/testdata/monorepo/one/BUILD.in diff --git a/gazelle/testdata/monorepo/one/BUILD.out b/gazelle/python/testdata/monorepo/one/BUILD.out similarity index 89% rename from gazelle/testdata/monorepo/one/BUILD.out rename to gazelle/python/testdata/monorepo/one/BUILD.out index a957227a9a..5098cc9a08 100644 --- a/gazelle/testdata/monorepo/one/BUILD.out +++ b/gazelle/python/testdata/monorepo/one/BUILD.out @@ -12,6 +12,6 @@ py_binary( "//one/bar", "//one/bar/baz:modified_name_baz", "//one/foo", - "@one_pip_deps//pypi__oneboto3", + "@one_pip_deps_oneboto3//:pkg", ], ) diff --git a/gazelle/python/testdata/monorepo/one/__main__.py b/gazelle/python/testdata/monorepo/one/__main__.py new file mode 100644 index 0000000000..7ef50cc97b --- /dev/null +++ b/gazelle/python/testdata/monorepo/one/__main__.py @@ -0,0 +1,29 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +import boto3 +from bar import bar +from bar.baz import baz +from foo import foo + +_ = boto3 + +if __name__ == "__main__": + INIT_FILENAME = "__init__.py" + dirname = os.path.dirname(os.path.abspath(__file__)) + assert bar() == os.path.join(dirname, "bar", INIT_FILENAME) + assert baz() == os.path.join(dirname, "bar", "baz", INIT_FILENAME) + assert foo() == os.path.join(dirname, "foo", INIT_FILENAME) diff --git a/gazelle/testdata/monorepo/one/bar/BUILD.in b/gazelle/python/testdata/monorepo/one/bar/BUILD.in similarity index 100% rename from gazelle/testdata/monorepo/one/bar/BUILD.in rename to gazelle/python/testdata/monorepo/one/bar/BUILD.in diff --git a/gazelle/testdata/monorepo/one/bar/BUILD.out b/gazelle/python/testdata/monorepo/one/bar/BUILD.out similarity index 83% rename from gazelle/testdata/monorepo/one/bar/BUILD.out rename to gazelle/python/testdata/monorepo/one/bar/BUILD.out index 0e85623394..6ee6515eec 100644 --- a/gazelle/testdata/monorepo/one/bar/BUILD.out +++ b/gazelle/python/testdata/monorepo/one/bar/BUILD.out @@ -8,5 +8,5 @@ py_library( "//one:__subpackages__", "//three:__subpackages__", ], - deps = ["@one_pip_deps//pypi__oneboto3"], + deps = ["@one_pip_deps_oneboto3//:pkg"], ) diff --git a/gazelle/python/testdata/monorepo/one/bar/__init__.py b/gazelle/python/testdata/monorepo/one/bar/__init__.py new file mode 100644 index 0000000000..499a0903cc --- /dev/null +++ b/gazelle/python/testdata/monorepo/one/bar/__init__.py @@ -0,0 +1,23 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +import boto3 + +_ = boto3 + + +def bar(): + return os.path.abspath(__file__) diff --git a/gazelle/testdata/monorepo/one/bar/baz/BUILD.in b/gazelle/python/testdata/monorepo/one/bar/baz/BUILD.in similarity index 100% rename from gazelle/testdata/monorepo/one/bar/baz/BUILD.in rename to gazelle/python/testdata/monorepo/one/bar/baz/BUILD.in diff --git a/gazelle/testdata/monorepo/one/bar/baz/BUILD.out b/gazelle/python/testdata/monorepo/one/bar/baz/BUILD.out similarity index 100% rename from gazelle/testdata/monorepo/one/bar/baz/BUILD.out rename to gazelle/python/testdata/monorepo/one/bar/baz/BUILD.out diff --git a/gazelle/python/testdata/monorepo/one/bar/baz/__init__.py b/gazelle/python/testdata/monorepo/one/bar/baz/__init__.py new file mode 100644 index 0000000000..5be74a7d3e --- /dev/null +++ b/gazelle/python/testdata/monorepo/one/bar/baz/__init__.py @@ -0,0 +1,19 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + + +def baz(): + return os.path.abspath(__file__) diff --git a/gazelle/testdata/monorepo/one/foo/BUILD.in b/gazelle/python/testdata/monorepo/one/foo/BUILD.in similarity index 100% rename from gazelle/testdata/monorepo/one/foo/BUILD.in rename to gazelle/python/testdata/monorepo/one/foo/BUILD.in diff --git a/gazelle/testdata/monorepo/one/foo/BUILD.out b/gazelle/python/testdata/monorepo/one/foo/BUILD.out similarity index 100% rename from gazelle/testdata/monorepo/one/foo/BUILD.out rename to gazelle/python/testdata/monorepo/one/foo/BUILD.out diff --git a/gazelle/python/testdata/monorepo/one/foo/__init__.py b/gazelle/python/testdata/monorepo/one/foo/__init__.py new file mode 100644 index 0000000000..978fb74567 --- /dev/null +++ b/gazelle/python/testdata/monorepo/one/foo/__init__.py @@ -0,0 +1,19 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + + +def foo(): + return os.path.abspath(__file__) diff --git a/gazelle/python/testdata/monorepo/one/gazelle_python.yaml b/gazelle/python/testdata/monorepo/one/gazelle_python.yaml new file mode 100644 index 0000000000..6b323b73d2 --- /dev/null +++ b/gazelle/python/testdata/monorepo/one/gazelle_python.yaml @@ -0,0 +1,18 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +manifest: + modules_mapping: + boto3: oneboto3 + pip_deps_repository_name: one_pip_deps diff --git a/gazelle/python/testdata/monorepo/test.yaml b/gazelle/python/testdata/monorepo/test.yaml new file mode 100644 index 0000000000..fcea77710f --- /dev/null +++ b/gazelle/python/testdata/monorepo/test.yaml @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- diff --git a/gazelle/testdata/monorepo/three/BUILD.in b/gazelle/python/testdata/monorepo/three/BUILD.in similarity index 100% rename from gazelle/testdata/monorepo/three/BUILD.in rename to gazelle/python/testdata/monorepo/three/BUILD.in diff --git a/gazelle/testdata/monorepo/three/BUILD.out b/gazelle/python/testdata/monorepo/three/BUILD.out similarity index 92% rename from gazelle/testdata/monorepo/three/BUILD.out rename to gazelle/python/testdata/monorepo/three/BUILD.out index 0da269d644..78a3927db9 100644 --- a/gazelle/testdata/monorepo/three/BUILD.out +++ b/gazelle/python/testdata/monorepo/three/BUILD.out @@ -15,7 +15,7 @@ py_library( "//one/bar", "//one/bar/baz:modified_name_baz", "//one/foo", - "@root_pip_deps//pypi__rootboto4", + "@root_pip_deps_rootboto4//:pkg", "@three_pip_deps_threeboto3//:pkg", ], ) diff --git a/gazelle/python/testdata/monorepo/three/__init__.py b/gazelle/python/testdata/monorepo/three/__init__.py new file mode 100644 index 0000000000..b324b0c416 --- /dev/null +++ b/gazelle/python/testdata/monorepo/three/__init__.py @@ -0,0 +1,30 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +import bar.baz.hue as hue +import boto3 +import boto4 +from bar import bar +from bar.baz import baz +from foo import foo + +_ = os +_ = boto3 +_ = boto4 +_ = bar +_ = baz +_ = foo +_ = hue diff --git a/gazelle/python/testdata/monorepo/three/gazelle_python.yaml b/gazelle/python/testdata/monorepo/three/gazelle_python.yaml new file mode 100644 index 0000000000..8280b38d16 --- /dev/null +++ b/gazelle/python/testdata/monorepo/three/gazelle_python.yaml @@ -0,0 +1,19 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +manifest: + modules_mapping: + boto3: threeboto3 + pip_repository: + name: three_pip_deps diff --git a/gazelle/testdata/monorepo/two/BUILD.in b/gazelle/python/testdata/monorepo/two/BUILD.in similarity index 100% rename from gazelle/testdata/monorepo/two/BUILD.in rename to gazelle/python/testdata/monorepo/two/BUILD.in diff --git a/gazelle/testdata/monorepo/two/BUILD.out b/gazelle/python/testdata/monorepo/two/BUILD.out similarity index 87% rename from gazelle/testdata/monorepo/two/BUILD.out rename to gazelle/python/testdata/monorepo/two/BUILD.out index 4b638edea2..9cda007e59 100644 --- a/gazelle/testdata/monorepo/two/BUILD.out +++ b/gazelle/python/testdata/monorepo/two/BUILD.out @@ -10,6 +10,6 @@ py_library( visibility = ["//two:__subpackages__"], deps = [ "//one/foo", - "@two_pip_deps//pypi__twoboto3", + "@two_pip_deps_twoboto3//:pkg", ], ) diff --git a/gazelle/python/testdata/monorepo/two/__init__.py b/gazelle/python/testdata/monorepo/two/__init__.py new file mode 100644 index 0000000000..d080c27de3 --- /dev/null +++ b/gazelle/python/testdata/monorepo/two/__init__.py @@ -0,0 +1,22 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +import boto3 +from foo import foo + +_ = os +_ = boto3 +_ = foo diff --git a/gazelle/python/testdata/monorepo/two/gazelle_python.yaml b/gazelle/python/testdata/monorepo/two/gazelle_python.yaml new file mode 100644 index 0000000000..88c24d0147 --- /dev/null +++ b/gazelle/python/testdata/monorepo/two/gazelle_python.yaml @@ -0,0 +1,18 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +manifest: + modules_mapping: + boto3: twoboto3 + pip_deps_repository_name: two_pip_deps diff --git a/gazelle/testdata/monorepo/wont_generate/bar/BUILD.in b/gazelle/python/testdata/monorepo/wont_generate/BUILD.in similarity index 100% rename from gazelle/testdata/monorepo/wont_generate/bar/BUILD.in rename to gazelle/python/testdata/monorepo/wont_generate/BUILD.in diff --git a/gazelle/testdata/monorepo/wont_generate/bar/BUILD.out b/gazelle/python/testdata/monorepo/wont_generate/BUILD.out similarity index 100% rename from gazelle/testdata/monorepo/wont_generate/bar/BUILD.out rename to gazelle/python/testdata/monorepo/wont_generate/BUILD.out diff --git a/gazelle/python/testdata/monorepo/wont_generate/__main__.py b/gazelle/python/testdata/monorepo/wont_generate/__main__.py new file mode 100644 index 0000000000..efc7900d53 --- /dev/null +++ b/gazelle/python/testdata/monorepo/wont_generate/__main__.py @@ -0,0 +1,26 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +from bar import bar +from bar.baz import baz +from foo import foo + +if __name__ == "__main__": + INIT_FILENAME = "__init__.py" + dirname = os.path.dirname(os.path.abspath(__file__)) + assert bar() == os.path.join(dirname, "bar", INIT_FILENAME) + assert baz() == os.path.join(dirname, "bar", "baz", INIT_FILENAME) + assert foo() == os.path.join(dirname, "foo", INIT_FILENAME) diff --git a/gazelle/testdata/monorepo/wont_generate/bar/baz/BUILD.in b/gazelle/python/testdata/monorepo/wont_generate/bar/BUILD.in similarity index 100% rename from gazelle/testdata/monorepo/wont_generate/bar/baz/BUILD.in rename to gazelle/python/testdata/monorepo/wont_generate/bar/BUILD.in diff --git a/gazelle/testdata/monorepo/wont_generate/bar/baz/BUILD.out b/gazelle/python/testdata/monorepo/wont_generate/bar/BUILD.out similarity index 100% rename from gazelle/testdata/monorepo/wont_generate/bar/baz/BUILD.out rename to gazelle/python/testdata/monorepo/wont_generate/bar/BUILD.out diff --git a/gazelle/python/testdata/monorepo/wont_generate/bar/__init__.py b/gazelle/python/testdata/monorepo/wont_generate/bar/__init__.py new file mode 100644 index 0000000000..d4b5fb84f1 --- /dev/null +++ b/gazelle/python/testdata/monorepo/wont_generate/bar/__init__.py @@ -0,0 +1,19 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + + +def bar(): + return os.path.abspath(__file__) diff --git a/gazelle/testdata/monorepo/wont_generate/foo/BUILD.in b/gazelle/python/testdata/monorepo/wont_generate/bar/baz/BUILD.in similarity index 100% rename from gazelle/testdata/monorepo/wont_generate/foo/BUILD.in rename to gazelle/python/testdata/monorepo/wont_generate/bar/baz/BUILD.in diff --git a/gazelle/testdata/monorepo/wont_generate/foo/BUILD.out b/gazelle/python/testdata/monorepo/wont_generate/bar/baz/BUILD.out similarity index 100% rename from gazelle/testdata/monorepo/wont_generate/foo/BUILD.out rename to gazelle/python/testdata/monorepo/wont_generate/bar/baz/BUILD.out diff --git a/gazelle/python/testdata/monorepo/wont_generate/bar/baz/__init__.py b/gazelle/python/testdata/monorepo/wont_generate/bar/baz/__init__.py new file mode 100644 index 0000000000..5be74a7d3e --- /dev/null +++ b/gazelle/python/testdata/monorepo/wont_generate/bar/baz/__init__.py @@ -0,0 +1,19 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + + +def baz(): + return os.path.abspath(__file__) diff --git a/gazelle/testdata/python_ignore_files_directive/bar/BUILD.in b/gazelle/python/testdata/monorepo/wont_generate/foo/BUILD.in similarity index 100% rename from gazelle/testdata/python_ignore_files_directive/bar/BUILD.in rename to gazelle/python/testdata/monorepo/wont_generate/foo/BUILD.in diff --git a/gazelle/testdata/simple_library_without_init/BUILD.out b/gazelle/python/testdata/monorepo/wont_generate/foo/BUILD.out similarity index 100% rename from gazelle/testdata/simple_library_without_init/BUILD.out rename to gazelle/python/testdata/monorepo/wont_generate/foo/BUILD.out diff --git a/gazelle/python/testdata/monorepo/wont_generate/foo/__init__.py b/gazelle/python/testdata/monorepo/wont_generate/foo/__init__.py new file mode 100644 index 0000000000..978fb74567 --- /dev/null +++ b/gazelle/python/testdata/monorepo/wont_generate/foo/__init__.py @@ -0,0 +1,19 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + + +def foo(): + return os.path.abspath(__file__) diff --git a/gazelle/python/testdata/multiple_tests/BUILD.in b/gazelle/python/testdata/multiple_tests/BUILD.in new file mode 100644 index 0000000000..9e84e5dc32 --- /dev/null +++ b/gazelle/python/testdata/multiple_tests/BUILD.in @@ -0,0 +1,12 @@ +load("@rules_python//python:defs.bzl", "py_library", "py_test") + +py_library( + name = "multiple_tests", + srcs = ["__init__.py"], + visibility = ["//:__subpackages__"], +) + +py_test( + name = "bar_test", + srcs = ["bar_test.py"], +) diff --git a/gazelle/python/testdata/multiple_tests/BUILD.out b/gazelle/python/testdata/multiple_tests/BUILD.out new file mode 100644 index 0000000000..fd67724e3b --- /dev/null +++ b/gazelle/python/testdata/multiple_tests/BUILD.out @@ -0,0 +1,17 @@ +load("@rules_python//python:defs.bzl", "py_library", "py_test") + +py_library( + name = "multiple_tests", + srcs = ["__init__.py"], + visibility = ["//:__subpackages__"], +) + +py_test( + name = "bar_test", + srcs = ["bar_test.py"], +) + +py_test( + name = "foo_test", + srcs = ["foo_test.py"], +) diff --git a/gazelle/python/testdata/multiple_tests/README.md b/gazelle/python/testdata/multiple_tests/README.md new file mode 100644 index 0000000000..8220f6112d --- /dev/null +++ b/gazelle/python/testdata/multiple_tests/README.md @@ -0,0 +1,3 @@ +# Multiple tests + +This test case asserts that a second `py_test` rule is correctly created when a second `*_test.py` file is added to a package with an existing `py_test` rule. diff --git a/gazelle/testdata/naming_convention_binary_fail/WORKSPACE b/gazelle/python/testdata/multiple_tests/WORKSPACE similarity index 100% rename from gazelle/testdata/naming_convention_binary_fail/WORKSPACE rename to gazelle/python/testdata/multiple_tests/WORKSPACE diff --git a/gazelle/testdata/dont_rename_target/__init__.py b/gazelle/python/testdata/multiple_tests/__init__.py similarity index 100% rename from gazelle/testdata/dont_rename_target/__init__.py rename to gazelle/python/testdata/multiple_tests/__init__.py diff --git a/gazelle/python/testdata/multiple_tests/bar_test.py b/gazelle/python/testdata/multiple_tests/bar_test.py new file mode 100644 index 0000000000..9948f1ccd4 --- /dev/null +++ b/gazelle/python/testdata/multiple_tests/bar_test.py @@ -0,0 +1,24 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import unittest + + +class BarTest(unittest.TestCase): + def test_foo(self): + pass + + +if __name__ == "__main__": + unittest.main() diff --git a/gazelle/python/testdata/multiple_tests/foo_test.py b/gazelle/python/testdata/multiple_tests/foo_test.py new file mode 100644 index 0000000000..a128adf67f --- /dev/null +++ b/gazelle/python/testdata/multiple_tests/foo_test.py @@ -0,0 +1,24 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import unittest + + +class FooTest(unittest.TestCase): + def test_foo(self): + pass + + +if __name__ == "__main__": + unittest.main() diff --git a/gazelle/python/testdata/multiple_tests/test.yaml b/gazelle/python/testdata/multiple_tests/test.yaml new file mode 100644 index 0000000000..2410223e59 --- /dev/null +++ b/gazelle/python/testdata/multiple_tests/test.yaml @@ -0,0 +1,17 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- +expect: + exit_code: 0 diff --git a/gazelle/testdata/naming_convention/BUILD.in b/gazelle/python/testdata/naming_convention/BUILD.in similarity index 100% rename from gazelle/testdata/naming_convention/BUILD.in rename to gazelle/python/testdata/naming_convention/BUILD.in diff --git a/gazelle/testdata/naming_convention/BUILD.out b/gazelle/python/testdata/naming_convention/BUILD.out similarity index 100% rename from gazelle/testdata/naming_convention/BUILD.out rename to gazelle/python/testdata/naming_convention/BUILD.out diff --git a/gazelle/testdata/naming_convention/README.md b/gazelle/python/testdata/naming_convention/README.md similarity index 100% rename from gazelle/testdata/naming_convention/README.md rename to gazelle/python/testdata/naming_convention/README.md diff --git a/gazelle/testdata/naming_convention_library_fail/WORKSPACE b/gazelle/python/testdata/naming_convention/WORKSPACE similarity index 100% rename from gazelle/testdata/naming_convention_library_fail/WORKSPACE rename to gazelle/python/testdata/naming_convention/WORKSPACE diff --git a/gazelle/python/testdata/naming_convention/__init__.py b/gazelle/python/testdata/naming_convention/__init__.py new file mode 100644 index 0000000000..730755995d --- /dev/null +++ b/gazelle/python/testdata/naming_convention/__init__.py @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For test purposes only. diff --git a/gazelle/python/testdata/naming_convention/__main__.py b/gazelle/python/testdata/naming_convention/__main__.py new file mode 100644 index 0000000000..a3afc79dcd --- /dev/null +++ b/gazelle/python/testdata/naming_convention/__main__.py @@ -0,0 +1,16 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For test purposes only. +import __init__ \ No newline at end of file diff --git a/gazelle/python/testdata/naming_convention/__test__.py b/gazelle/python/testdata/naming_convention/__test__.py new file mode 100644 index 0000000000..a3afc79dcd --- /dev/null +++ b/gazelle/python/testdata/naming_convention/__test__.py @@ -0,0 +1,16 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For test purposes only. +import __init__ \ No newline at end of file diff --git a/gazelle/testdata/naming_convention/dont_rename/BUILD.in b/gazelle/python/testdata/naming_convention/dont_rename/BUILD.in similarity index 100% rename from gazelle/testdata/naming_convention/dont_rename/BUILD.in rename to gazelle/python/testdata/naming_convention/dont_rename/BUILD.in diff --git a/gazelle/testdata/naming_convention/dont_rename/BUILD.out b/gazelle/python/testdata/naming_convention/dont_rename/BUILD.out similarity index 100% rename from gazelle/testdata/naming_convention/dont_rename/BUILD.out rename to gazelle/python/testdata/naming_convention/dont_rename/BUILD.out diff --git a/gazelle/python/testdata/naming_convention/dont_rename/__init__.py b/gazelle/python/testdata/naming_convention/dont_rename/__init__.py new file mode 100644 index 0000000000..730755995d --- /dev/null +++ b/gazelle/python/testdata/naming_convention/dont_rename/__init__.py @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For test purposes only. diff --git a/gazelle/python/testdata/naming_convention/dont_rename/__main__.py b/gazelle/python/testdata/naming_convention/dont_rename/__main__.py new file mode 100644 index 0000000000..a3afc79dcd --- /dev/null +++ b/gazelle/python/testdata/naming_convention/dont_rename/__main__.py @@ -0,0 +1,16 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For test purposes only. +import __init__ \ No newline at end of file diff --git a/gazelle/python/testdata/naming_convention/dont_rename/__test__.py b/gazelle/python/testdata/naming_convention/dont_rename/__test__.py new file mode 100644 index 0000000000..a3afc79dcd --- /dev/null +++ b/gazelle/python/testdata/naming_convention/dont_rename/__test__.py @@ -0,0 +1,16 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For test purposes only. +import __init__ \ No newline at end of file diff --git a/gazelle/testdata/naming_convention/resolve_conflict/BUILD.in b/gazelle/python/testdata/naming_convention/resolve_conflict/BUILD.in similarity index 100% rename from gazelle/testdata/naming_convention/resolve_conflict/BUILD.in rename to gazelle/python/testdata/naming_convention/resolve_conflict/BUILD.in diff --git a/gazelle/testdata/naming_convention/resolve_conflict/BUILD.out b/gazelle/python/testdata/naming_convention/resolve_conflict/BUILD.out similarity index 100% rename from gazelle/testdata/naming_convention/resolve_conflict/BUILD.out rename to gazelle/python/testdata/naming_convention/resolve_conflict/BUILD.out diff --git a/gazelle/python/testdata/naming_convention/resolve_conflict/__init__.py b/gazelle/python/testdata/naming_convention/resolve_conflict/__init__.py new file mode 100644 index 0000000000..730755995d --- /dev/null +++ b/gazelle/python/testdata/naming_convention/resolve_conflict/__init__.py @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For test purposes only. diff --git a/gazelle/python/testdata/naming_convention/resolve_conflict/__main__.py b/gazelle/python/testdata/naming_convention/resolve_conflict/__main__.py new file mode 100644 index 0000000000..a3afc79dcd --- /dev/null +++ b/gazelle/python/testdata/naming_convention/resolve_conflict/__main__.py @@ -0,0 +1,16 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For test purposes only. +import __init__ \ No newline at end of file diff --git a/gazelle/python/testdata/naming_convention/resolve_conflict/__test__.py b/gazelle/python/testdata/naming_convention/resolve_conflict/__test__.py new file mode 100644 index 0000000000..a3afc79dcd --- /dev/null +++ b/gazelle/python/testdata/naming_convention/resolve_conflict/__test__.py @@ -0,0 +1,16 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For test purposes only. +import __init__ \ No newline at end of file diff --git a/gazelle/python/testdata/naming_convention/test.yaml b/gazelle/python/testdata/naming_convention/test.yaml new file mode 100644 index 0000000000..fcea77710f --- /dev/null +++ b/gazelle/python/testdata/naming_convention/test.yaml @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- diff --git a/gazelle/testdata/naming_convention_binary_fail/BUILD.in b/gazelle/python/testdata/naming_convention_binary_fail/BUILD.in similarity index 100% rename from gazelle/testdata/naming_convention_binary_fail/BUILD.in rename to gazelle/python/testdata/naming_convention_binary_fail/BUILD.in diff --git a/gazelle/testdata/naming_convention_binary_fail/BUILD.out b/gazelle/python/testdata/naming_convention_binary_fail/BUILD.out similarity index 100% rename from gazelle/testdata/naming_convention_binary_fail/BUILD.out rename to gazelle/python/testdata/naming_convention_binary_fail/BUILD.out diff --git a/gazelle/testdata/naming_convention_binary_fail/README.md b/gazelle/python/testdata/naming_convention_binary_fail/README.md similarity index 100% rename from gazelle/testdata/naming_convention_binary_fail/README.md rename to gazelle/python/testdata/naming_convention_binary_fail/README.md diff --git a/gazelle/testdata/naming_convention_test_fail/WORKSPACE b/gazelle/python/testdata/naming_convention_binary_fail/WORKSPACE similarity index 100% rename from gazelle/testdata/naming_convention_test_fail/WORKSPACE rename to gazelle/python/testdata/naming_convention_binary_fail/WORKSPACE diff --git a/gazelle/python/testdata/naming_convention_binary_fail/__main__.py b/gazelle/python/testdata/naming_convention_binary_fail/__main__.py new file mode 100644 index 0000000000..730755995d --- /dev/null +++ b/gazelle/python/testdata/naming_convention_binary_fail/__main__.py @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For test purposes only. diff --git a/gazelle/python/testdata/naming_convention_binary_fail/test.yaml b/gazelle/python/testdata/naming_convention_binary_fail/test.yaml new file mode 100644 index 0000000000..41eabbfb11 --- /dev/null +++ b/gazelle/python/testdata/naming_convention_binary_fail/test.yaml @@ -0,0 +1,21 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- +expect: + exit_code: 1 + stderr: > + gazelle: ERROR: failed to generate target "//:naming_convention_binary_fail_bin" of kind "py_binary": + a target of kind "go_binary" with the same name already exists. + Use the '# gazelle:python_binary_naming_convention' directive to change the naming convention. diff --git a/gazelle/testdata/naming_convention_library_fail/BUILD.in b/gazelle/python/testdata/naming_convention_library_fail/BUILD.in similarity index 100% rename from gazelle/testdata/naming_convention_library_fail/BUILD.in rename to gazelle/python/testdata/naming_convention_library_fail/BUILD.in diff --git a/gazelle/testdata/naming_convention_library_fail/BUILD.out b/gazelle/python/testdata/naming_convention_library_fail/BUILD.out similarity index 100% rename from gazelle/testdata/naming_convention_library_fail/BUILD.out rename to gazelle/python/testdata/naming_convention_library_fail/BUILD.out diff --git a/gazelle/testdata/naming_convention_library_fail/README.md b/gazelle/python/testdata/naming_convention_library_fail/README.md similarity index 100% rename from gazelle/testdata/naming_convention_library_fail/README.md rename to gazelle/python/testdata/naming_convention_library_fail/README.md diff --git a/gazelle/testdata/python_ignore_dependencies_directive/WORKSPACE b/gazelle/python/testdata/naming_convention_library_fail/WORKSPACE similarity index 100% rename from gazelle/testdata/python_ignore_dependencies_directive/WORKSPACE rename to gazelle/python/testdata/naming_convention_library_fail/WORKSPACE diff --git a/gazelle/python/testdata/naming_convention_library_fail/__init__.py b/gazelle/python/testdata/naming_convention_library_fail/__init__.py new file mode 100644 index 0000000000..730755995d --- /dev/null +++ b/gazelle/python/testdata/naming_convention_library_fail/__init__.py @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For test purposes only. diff --git a/gazelle/python/testdata/naming_convention_library_fail/test.yaml b/gazelle/python/testdata/naming_convention_library_fail/test.yaml new file mode 100644 index 0000000000..f48aa397f1 --- /dev/null +++ b/gazelle/python/testdata/naming_convention_library_fail/test.yaml @@ -0,0 +1,21 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- +expect: + exit_code: 1 + stderr: > + gazelle: ERROR: failed to generate target "//:naming_convention_library_fail" of kind "py_library": + a target of kind "go_library" with the same name already exists. + Use the '# gazelle:python_library_naming_convention' directive to change the naming convention. diff --git a/gazelle/testdata/naming_convention_test_fail/BUILD.in b/gazelle/python/testdata/naming_convention_test_fail/BUILD.in similarity index 100% rename from gazelle/testdata/naming_convention_test_fail/BUILD.in rename to gazelle/python/testdata/naming_convention_test_fail/BUILD.in diff --git a/gazelle/testdata/naming_convention_test_fail/BUILD.out b/gazelle/python/testdata/naming_convention_test_fail/BUILD.out similarity index 100% rename from gazelle/testdata/naming_convention_test_fail/BUILD.out rename to gazelle/python/testdata/naming_convention_test_fail/BUILD.out diff --git a/gazelle/testdata/naming_convention_test_fail/README.md b/gazelle/python/testdata/naming_convention_test_fail/README.md similarity index 100% rename from gazelle/testdata/naming_convention_test_fail/README.md rename to gazelle/python/testdata/naming_convention_test_fail/README.md diff --git a/gazelle/testdata/python_ignore_files_directive/WORKSPACE b/gazelle/python/testdata/naming_convention_test_fail/WORKSPACE similarity index 100% rename from gazelle/testdata/python_ignore_files_directive/WORKSPACE rename to gazelle/python/testdata/naming_convention_test_fail/WORKSPACE diff --git a/gazelle/python/testdata/naming_convention_test_fail/__test__.py b/gazelle/python/testdata/naming_convention_test_fail/__test__.py new file mode 100644 index 0000000000..730755995d --- /dev/null +++ b/gazelle/python/testdata/naming_convention_test_fail/__test__.py @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For test purposes only. diff --git a/gazelle/python/testdata/naming_convention_test_fail/test.yaml b/gazelle/python/testdata/naming_convention_test_fail/test.yaml new file mode 100644 index 0000000000..a8867e567e --- /dev/null +++ b/gazelle/python/testdata/naming_convention_test_fail/test.yaml @@ -0,0 +1,21 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- +expect: + exit_code: 1 + stderr: > + gazelle: ERROR: failed to generate target "//:naming_convention_test_fail_test" of kind "py_test": + a target of kind "go_test" with the same name already exists. + Use the '# gazelle:python_test_naming_convention' directive to change the naming convention. diff --git a/gazelle/testdata/python_ignore_dependencies_directive/BUILD.in b/gazelle/python/testdata/python_ignore_dependencies_directive/BUILD.in similarity index 100% rename from gazelle/testdata/python_ignore_dependencies_directive/BUILD.in rename to gazelle/python/testdata/python_ignore_dependencies_directive/BUILD.in diff --git a/gazelle/testdata/python_ignore_dependencies_directive/BUILD.out b/gazelle/python/testdata/python_ignore_dependencies_directive/BUILD.out similarity index 85% rename from gazelle/testdata/python_ignore_dependencies_directive/BUILD.out rename to gazelle/python/testdata/python_ignore_dependencies_directive/BUILD.out index 37ae4f9aa1..3fb91f5964 100644 --- a/gazelle/testdata/python_ignore_dependencies_directive/BUILD.out +++ b/gazelle/python/testdata/python_ignore_dependencies_directive/BUILD.out @@ -7,5 +7,5 @@ py_library( name = "python_ignore_dependencies_directive", srcs = ["__init__.py"], visibility = ["//:__subpackages__"], - deps = ["@gazelle_python_test//pypi__boto3"], + deps = ["@gazelle_python_test_boto3//:pkg"], ) diff --git a/gazelle/testdata/python_ignore_dependencies_directive/README.md b/gazelle/python/testdata/python_ignore_dependencies_directive/README.md similarity index 100% rename from gazelle/testdata/python_ignore_dependencies_directive/README.md rename to gazelle/python/testdata/python_ignore_dependencies_directive/README.md diff --git a/gazelle/testdata/simple_binary/WORKSPACE b/gazelle/python/testdata/python_ignore_dependencies_directive/WORKSPACE similarity index 100% rename from gazelle/testdata/simple_binary/WORKSPACE rename to gazelle/python/testdata/python_ignore_dependencies_directive/WORKSPACE diff --git a/gazelle/python/testdata/python_ignore_dependencies_directive/__init__.py b/gazelle/python/testdata/python_ignore_dependencies_directive/__init__.py new file mode 100644 index 0000000000..9e6e25a891 --- /dev/null +++ b/gazelle/python/testdata/python_ignore_dependencies_directive/__init__.py @@ -0,0 +1,25 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import bar +import boto3 +import foo +import foo.bar.baz +from baz import baz as bazfn + +_ = foo +_ = bar +_ = bazfn +_ = baz +_ = boto3 diff --git a/gazelle/python/testdata/python_ignore_dependencies_directive/gazelle_python.yaml b/gazelle/python/testdata/python_ignore_dependencies_directive/gazelle_python.yaml new file mode 100644 index 0000000000..1bf594f9b4 --- /dev/null +++ b/gazelle/python/testdata/python_ignore_dependencies_directive/gazelle_python.yaml @@ -0,0 +1,18 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +manifest: + modules_mapping: + boto3: boto3 + pip_deps_repository_name: gazelle_python_test diff --git a/gazelle/python/testdata/python_ignore_dependencies_directive/test.yaml b/gazelle/python/testdata/python_ignore_dependencies_directive/test.yaml new file mode 100644 index 0000000000..fcea77710f --- /dev/null +++ b/gazelle/python/testdata/python_ignore_dependencies_directive/test.yaml @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- diff --git a/gazelle/testdata/python_ignore_files_directive/BUILD.in b/gazelle/python/testdata/python_ignore_files_directive/BUILD.in similarity index 100% rename from gazelle/testdata/python_ignore_files_directive/BUILD.in rename to gazelle/python/testdata/python_ignore_files_directive/BUILD.in diff --git a/gazelle/testdata/python_ignore_files_directive/BUILD.out b/gazelle/python/testdata/python_ignore_files_directive/BUILD.out similarity index 100% rename from gazelle/testdata/python_ignore_files_directive/BUILD.out rename to gazelle/python/testdata/python_ignore_files_directive/BUILD.out diff --git a/gazelle/testdata/python_ignore_files_directive/README.md b/gazelle/python/testdata/python_ignore_files_directive/README.md similarity index 100% rename from gazelle/testdata/python_ignore_files_directive/README.md rename to gazelle/python/testdata/python_ignore_files_directive/README.md diff --git a/gazelle/testdata/simple_binary_with_library/WORKSPACE b/gazelle/python/testdata/python_ignore_files_directive/WORKSPACE similarity index 100% rename from gazelle/testdata/simple_binary_with_library/WORKSPACE rename to gazelle/python/testdata/python_ignore_files_directive/WORKSPACE diff --git a/gazelle/python/testdata/python_ignore_files_directive/__init__.py b/gazelle/python/testdata/python_ignore_files_directive/__init__.py new file mode 100644 index 0000000000..730755995d --- /dev/null +++ b/gazelle/python/testdata/python_ignore_files_directive/__init__.py @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For test purposes only. diff --git a/gazelle/testdata/python_target_with_test_in_name/BUILD.in b/gazelle/python/testdata/python_ignore_files_directive/bar/BUILD.in similarity index 100% rename from gazelle/testdata/python_target_with_test_in_name/BUILD.in rename to gazelle/python/testdata/python_ignore_files_directive/bar/BUILD.in diff --git a/gazelle/testdata/python_ignore_files_directive/bar/BUILD.out b/gazelle/python/testdata/python_ignore_files_directive/bar/BUILD.out similarity index 100% rename from gazelle/testdata/python_ignore_files_directive/bar/BUILD.out rename to gazelle/python/testdata/python_ignore_files_directive/bar/BUILD.out diff --git a/gazelle/python/testdata/python_ignore_files_directive/bar/baz.py b/gazelle/python/testdata/python_ignore_files_directive/bar/baz.py new file mode 100644 index 0000000000..730755995d --- /dev/null +++ b/gazelle/python/testdata/python_ignore_files_directive/bar/baz.py @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For test purposes only. diff --git a/gazelle/python/testdata/python_ignore_files_directive/bar/some_other.py b/gazelle/python/testdata/python_ignore_files_directive/bar/some_other.py new file mode 100644 index 0000000000..730755995d --- /dev/null +++ b/gazelle/python/testdata/python_ignore_files_directive/bar/some_other.py @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For test purposes only. diff --git a/gazelle/testdata/python_ignore_files_directive/foo/BUILD.in b/gazelle/python/testdata/python_ignore_files_directive/foo/BUILD.in similarity index 100% rename from gazelle/testdata/python_ignore_files_directive/foo/BUILD.in rename to gazelle/python/testdata/python_ignore_files_directive/foo/BUILD.in diff --git a/gazelle/testdata/python_ignore_files_directive/foo/BUILD.out b/gazelle/python/testdata/python_ignore_files_directive/foo/BUILD.out similarity index 100% rename from gazelle/testdata/python_ignore_files_directive/foo/BUILD.out rename to gazelle/python/testdata/python_ignore_files_directive/foo/BUILD.out diff --git a/gazelle/python/testdata/python_ignore_files_directive/foo/baz.py b/gazelle/python/testdata/python_ignore_files_directive/foo/baz.py new file mode 100644 index 0000000000..730755995d --- /dev/null +++ b/gazelle/python/testdata/python_ignore_files_directive/foo/baz.py @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For test purposes only. diff --git a/gazelle/python/testdata/python_ignore_files_directive/setup.py b/gazelle/python/testdata/python_ignore_files_directive/setup.py new file mode 100644 index 0000000000..730755995d --- /dev/null +++ b/gazelle/python/testdata/python_ignore_files_directive/setup.py @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For test purposes only. diff --git a/gazelle/python/testdata/python_ignore_files_directive/some_other.py b/gazelle/python/testdata/python_ignore_files_directive/some_other.py new file mode 100644 index 0000000000..730755995d --- /dev/null +++ b/gazelle/python/testdata/python_ignore_files_directive/some_other.py @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For test purposes only. diff --git a/gazelle/python/testdata/python_ignore_files_directive/test.yaml b/gazelle/python/testdata/python_ignore_files_directive/test.yaml new file mode 100644 index 0000000000..fcea77710f --- /dev/null +++ b/gazelle/python/testdata/python_ignore_files_directive/test.yaml @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- diff --git a/gazelle/testdata/relative_imports/BUILD.in b/gazelle/python/testdata/python_target_with_test_in_name/BUILD.in similarity index 100% rename from gazelle/testdata/relative_imports/BUILD.in rename to gazelle/python/testdata/python_target_with_test_in_name/BUILD.in diff --git a/gazelle/python/testdata/python_target_with_test_in_name/BUILD.out b/gazelle/python/testdata/python_target_with_test_in_name/BUILD.out new file mode 100644 index 0000000000..a46f5c40b8 --- /dev/null +++ b/gazelle/python/testdata/python_target_with_test_in_name/BUILD.out @@ -0,0 +1,22 @@ +load("@rules_python//python:defs.bzl", "py_library", "py_test") + +py_library( + name = "python_target_with_test_in_name", + srcs = ["__init__.py"], + visibility = ["//:__subpackages__"], +) + +py_test( + name = "real_test", + srcs = ["real_test.py"], + deps = [ + ":python_target_with_test_in_name", + "@gazelle_python_test_boto3//:pkg", + ], +) + +py_test( + name = "test_reality", + srcs = ["test_reality.py"], + deps = [":python_target_with_test_in_name"], +) diff --git a/gazelle/testdata/python_target_with_test_in_name/README.md b/gazelle/python/testdata/python_target_with_test_in_name/README.md similarity index 100% rename from gazelle/testdata/python_target_with_test_in_name/README.md rename to gazelle/python/testdata/python_target_with_test_in_name/README.md diff --git a/gazelle/testdata/python_target_with_test_in_name/WORKSPACE b/gazelle/python/testdata/python_target_with_test_in_name/WORKSPACE similarity index 100% rename from gazelle/testdata/python_target_with_test_in_name/WORKSPACE rename to gazelle/python/testdata/python_target_with_test_in_name/WORKSPACE diff --git a/gazelle/python/testdata/python_target_with_test_in_name/__init__.py b/gazelle/python/testdata/python_target_with_test_in_name/__init__.py new file mode 100644 index 0000000000..730755995d --- /dev/null +++ b/gazelle/python/testdata/python_target_with_test_in_name/__init__.py @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For test purposes only. diff --git a/gazelle/python/testdata/python_target_with_test_in_name/gazelle_python.yaml b/gazelle/python/testdata/python_target_with_test_in_name/gazelle_python.yaml new file mode 100644 index 0000000000..1bf594f9b4 --- /dev/null +++ b/gazelle/python/testdata/python_target_with_test_in_name/gazelle_python.yaml @@ -0,0 +1,18 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +manifest: + modules_mapping: + boto3: boto3 + pip_deps_repository_name: gazelle_python_test diff --git a/gazelle/python/testdata/python_target_with_test_in_name/real_test.py b/gazelle/python/testdata/python_target_with_test_in_name/real_test.py new file mode 100644 index 0000000000..e390866be3 --- /dev/null +++ b/gazelle/python/testdata/python_target_with_test_in_name/real_test.py @@ -0,0 +1,18 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import boto3 +import __init__ + +_ = boto3 diff --git a/gazelle/python/testdata/python_target_with_test_in_name/test.yaml b/gazelle/python/testdata/python_target_with_test_in_name/test.yaml new file mode 100644 index 0000000000..fcea77710f --- /dev/null +++ b/gazelle/python/testdata/python_target_with_test_in_name/test.yaml @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- diff --git a/gazelle/python/testdata/python_target_with_test_in_name/test_reality.py b/gazelle/python/testdata/python_target_with_test_in_name/test_reality.py new file mode 100644 index 0000000000..a3afc79dcd --- /dev/null +++ b/gazelle/python/testdata/python_target_with_test_in_name/test_reality.py @@ -0,0 +1,16 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For test purposes only. +import __init__ \ No newline at end of file diff --git a/gazelle/testdata/relative_imports/package2/BUILD.in b/gazelle/python/testdata/relative_imports/BUILD.in similarity index 100% rename from gazelle/testdata/relative_imports/package2/BUILD.in rename to gazelle/python/testdata/relative_imports/BUILD.in diff --git a/gazelle/testdata/relative_imports/BUILD.out b/gazelle/python/testdata/relative_imports/BUILD.out similarity index 100% rename from gazelle/testdata/relative_imports/BUILD.out rename to gazelle/python/testdata/relative_imports/BUILD.out diff --git a/gazelle/testdata/relative_imports/README.md b/gazelle/python/testdata/relative_imports/README.md similarity index 100% rename from gazelle/testdata/relative_imports/README.md rename to gazelle/python/testdata/relative_imports/README.md diff --git a/gazelle/testdata/relative_imports/WORKSPACE b/gazelle/python/testdata/relative_imports/WORKSPACE similarity index 100% rename from gazelle/testdata/relative_imports/WORKSPACE rename to gazelle/python/testdata/relative_imports/WORKSPACE diff --git a/gazelle/python/testdata/relative_imports/__main__.py b/gazelle/python/testdata/relative_imports/__main__.py new file mode 100644 index 0000000000..8d468bd643 --- /dev/null +++ b/gazelle/python/testdata/relative_imports/__main__.py @@ -0,0 +1,19 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from package1.module1 import function1 +from package2.module3 import function3 + +print(function1()) +print(function3()) diff --git a/gazelle/python/testdata/relative_imports/package1/module1.py b/gazelle/python/testdata/relative_imports/package1/module1.py new file mode 100644 index 0000000000..28502f1f84 --- /dev/null +++ b/gazelle/python/testdata/relative_imports/package1/module1.py @@ -0,0 +1,19 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from .module2 import function2 + + +def function1(): + return "function1 " + function2() diff --git a/gazelle/python/testdata/relative_imports/package1/module2.py b/gazelle/python/testdata/relative_imports/package1/module2.py new file mode 100644 index 0000000000..f8893b24e6 --- /dev/null +++ b/gazelle/python/testdata/relative_imports/package1/module2.py @@ -0,0 +1,16 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +def function2(): + return "function2" diff --git a/gazelle/testdata/simple_binary/BUILD.in b/gazelle/python/testdata/relative_imports/package2/BUILD.in similarity index 100% rename from gazelle/testdata/simple_binary/BUILD.in rename to gazelle/python/testdata/relative_imports/package2/BUILD.in diff --git a/gazelle/testdata/relative_imports/package2/BUILD.out b/gazelle/python/testdata/relative_imports/package2/BUILD.out similarity index 100% rename from gazelle/testdata/relative_imports/package2/BUILD.out rename to gazelle/python/testdata/relative_imports/package2/BUILD.out diff --git a/gazelle/python/testdata/relative_imports/package2/__init__.py b/gazelle/python/testdata/relative_imports/package2/__init__.py new file mode 100644 index 0000000000..0f5956835b --- /dev/null +++ b/gazelle/python/testdata/relative_imports/package2/__init__.py @@ -0,0 +1,17 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +class Class1: + def method1(self): + return "method1" diff --git a/gazelle/python/testdata/relative_imports/package2/module3.py b/gazelle/python/testdata/relative_imports/package2/module3.py new file mode 100644 index 0000000000..74978a08d9 --- /dev/null +++ b/gazelle/python/testdata/relative_imports/package2/module3.py @@ -0,0 +1,21 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from . import Class1 +from .subpackage1.module5 import function5 + + +def function3(): + c1 = Class1() + return "function3 " + c1.method1() + " " + function5() diff --git a/gazelle/python/testdata/relative_imports/package2/module4.py b/gazelle/python/testdata/relative_imports/package2/module4.py new file mode 100644 index 0000000000..b7509dc7cf --- /dev/null +++ b/gazelle/python/testdata/relative_imports/package2/module4.py @@ -0,0 +1,16 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +def function4(): + return "function4" diff --git a/gazelle/python/testdata/relative_imports/package2/subpackage1/module5.py b/gazelle/python/testdata/relative_imports/package2/subpackage1/module5.py new file mode 100644 index 0000000000..ea0b981fd0 --- /dev/null +++ b/gazelle/python/testdata/relative_imports/package2/subpackage1/module5.py @@ -0,0 +1,19 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from ..module4 import function4 + + +def function5(): + return "function5 " + function4() diff --git a/gazelle/python/testdata/relative_imports/test.yaml b/gazelle/python/testdata/relative_imports/test.yaml new file mode 100644 index 0000000000..fcea77710f --- /dev/null +++ b/gazelle/python/testdata/relative_imports/test.yaml @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- diff --git a/gazelle/python/testdata/respect_kind_mapping/BUILD.in b/gazelle/python/testdata/respect_kind_mapping/BUILD.in new file mode 100644 index 0000000000..6a06737623 --- /dev/null +++ b/gazelle/python/testdata/respect_kind_mapping/BUILD.in @@ -0,0 +1,15 @@ +load("@rules_python//python:defs.bzl", "py_library") + +# gazelle:map_kind py_test my_test :mytest.bzl + +py_library( + name = "respect_kind_mapping", + srcs = ["__init__.py"], +) + +my_test( + name = "respect_kind_mapping_test", + srcs = ["__test__.py"], + main = "__test__.py", + deps = [":respect_kind_mapping"], +) diff --git a/gazelle/python/testdata/respect_kind_mapping/BUILD.out b/gazelle/python/testdata/respect_kind_mapping/BUILD.out new file mode 100644 index 0000000000..7c5fb0bd20 --- /dev/null +++ b/gazelle/python/testdata/respect_kind_mapping/BUILD.out @@ -0,0 +1,20 @@ +load(":mytest.bzl", "my_test") +load("@rules_python//python:defs.bzl", "py_library") + +# gazelle:map_kind py_test my_test :mytest.bzl + +py_library( + name = "respect_kind_mapping", + srcs = [ + "__init__.py", + "foo.py", + ], + visibility = ["//:__subpackages__"], +) + +my_test( + name = "respect_kind_mapping_test", + srcs = ["__test__.py"], + main = "__test__.py", + deps = [":respect_kind_mapping"], +) diff --git a/gazelle/python/testdata/respect_kind_mapping/README.md b/gazelle/python/testdata/respect_kind_mapping/README.md new file mode 100644 index 0000000000..9f0fa6cf39 --- /dev/null +++ b/gazelle/python/testdata/respect_kind_mapping/README.md @@ -0,0 +1,3 @@ +# Respect Kind Mapping + +This test case asserts that when using a kind mapping, gazelle will respect that mapping when parsing a BUILD file containing a mapped kind. diff --git a/gazelle/testdata/simple_library/WORKSPACE b/gazelle/python/testdata/respect_kind_mapping/WORKSPACE similarity index 100% rename from gazelle/testdata/simple_library/WORKSPACE rename to gazelle/python/testdata/respect_kind_mapping/WORKSPACE diff --git a/gazelle/python/testdata/respect_kind_mapping/__init__.py b/gazelle/python/testdata/respect_kind_mapping/__init__.py new file mode 100644 index 0000000000..b274b0d921 --- /dev/null +++ b/gazelle/python/testdata/respect_kind_mapping/__init__.py @@ -0,0 +1,17 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from foo import foo + +_ = foo diff --git a/gazelle/python/testdata/respect_kind_mapping/__test__.py b/gazelle/python/testdata/respect_kind_mapping/__test__.py new file mode 100644 index 0000000000..2b180a5f53 --- /dev/null +++ b/gazelle/python/testdata/respect_kind_mapping/__test__.py @@ -0,0 +1,26 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import unittest + +from __init__ import foo + + +class FooTest(unittest.TestCase): + def test_foo(self): + self.assertEqual("foo", foo()) + + +if __name__ == "__main__": + unittest.main() diff --git a/gazelle/python/testdata/respect_kind_mapping/foo.py b/gazelle/python/testdata/respect_kind_mapping/foo.py new file mode 100644 index 0000000000..932de45b74 --- /dev/null +++ b/gazelle/python/testdata/respect_kind_mapping/foo.py @@ -0,0 +1,16 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +def foo(): + return "foo" diff --git a/gazelle/python/testdata/respect_kind_mapping/test.yaml b/gazelle/python/testdata/respect_kind_mapping/test.yaml new file mode 100644 index 0000000000..2410223e59 --- /dev/null +++ b/gazelle/python/testdata/respect_kind_mapping/test.yaml @@ -0,0 +1,17 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- +expect: + exit_code: 0 diff --git a/gazelle/python/testdata/sibling_imports/README.md b/gazelle/python/testdata/sibling_imports/README.md new file mode 100644 index 0000000000..e59be07634 --- /dev/null +++ b/gazelle/python/testdata/sibling_imports/README.md @@ -0,0 +1,3 @@ +# Sibling imports + +This test case asserts that imports from sibling modules are resolved correctly. It covers 3 different types of imports in `pkg/unit_test.py` \ No newline at end of file diff --git a/gazelle/testdata/simple_library_without_init/WORKSPACE b/gazelle/python/testdata/sibling_imports/WORKSPACE similarity index 100% rename from gazelle/testdata/simple_library_without_init/WORKSPACE rename to gazelle/python/testdata/sibling_imports/WORKSPACE diff --git a/gazelle/testdata/simple_library/BUILD.in b/gazelle/python/testdata/sibling_imports/pkg/BUILD.in similarity index 100% rename from gazelle/testdata/simple_library/BUILD.in rename to gazelle/python/testdata/sibling_imports/pkg/BUILD.in diff --git a/gazelle/python/testdata/sibling_imports/pkg/BUILD.out b/gazelle/python/testdata/sibling_imports/pkg/BUILD.out new file mode 100644 index 0000000000..edb40a8bcb --- /dev/null +++ b/gazelle/python/testdata/sibling_imports/pkg/BUILD.out @@ -0,0 +1,29 @@ +load("@rules_python//python:defs.bzl", "py_library", "py_test") + +py_library( + name = "pkg", + srcs = [ + "__init__.py", + "a.py", + "b.py", + ], + imports = [".."], + visibility = ["//:__subpackages__"], +) + +py_test( + name = "test_util", + srcs = ["test_util.py"], + imports = [".."], +) + +py_test( + name = "unit_test", + srcs = ["unit_test.py"], + imports = [".."], + deps = [ + ":pkg", + ":test_util", + ], +) + diff --git a/gazelle/testdata/monorepo/coarse_grained/_boundary/__init__.py b/gazelle/python/testdata/sibling_imports/pkg/__init__.py similarity index 100% rename from gazelle/testdata/monorepo/coarse_grained/_boundary/__init__.py rename to gazelle/python/testdata/sibling_imports/pkg/__init__.py diff --git a/gazelle/testdata/simple_library_without_init/BUILD.in b/gazelle/python/testdata/sibling_imports/pkg/a.py similarity index 100% rename from gazelle/testdata/simple_library_without_init/BUILD.in rename to gazelle/python/testdata/sibling_imports/pkg/a.py diff --git a/gazelle/python/testdata/sibling_imports/pkg/b.py b/gazelle/python/testdata/sibling_imports/pkg/b.py new file mode 100644 index 0000000000..7095bdcfb2 --- /dev/null +++ b/gazelle/python/testdata/sibling_imports/pkg/b.py @@ -0,0 +1,2 @@ +def run(): + pass \ No newline at end of file diff --git a/gazelle/testdata/simple_library_without_init/foo/BUILD.in b/gazelle/python/testdata/sibling_imports/pkg/test_util.py similarity index 100% rename from gazelle/testdata/simple_library_without_init/foo/BUILD.in rename to gazelle/python/testdata/sibling_imports/pkg/test_util.py diff --git a/gazelle/python/testdata/sibling_imports/pkg/unit_test.py b/gazelle/python/testdata/sibling_imports/pkg/unit_test.py new file mode 100644 index 0000000000..a3218e2ec2 --- /dev/null +++ b/gazelle/python/testdata/sibling_imports/pkg/unit_test.py @@ -0,0 +1,3 @@ +import a +from b import run +import test_util \ No newline at end of file diff --git a/gazelle/testdata/dependency_resolution_order/test.yaml b/gazelle/python/testdata/sibling_imports/test.yaml similarity index 100% rename from gazelle/testdata/dependency_resolution_order/test.yaml rename to gazelle/python/testdata/sibling_imports/test.yaml diff --git a/gazelle/testdata/subdir_sources/BUILD.in b/gazelle/python/testdata/simple_binary/BUILD.in similarity index 100% rename from gazelle/testdata/subdir_sources/BUILD.in rename to gazelle/python/testdata/simple_binary/BUILD.in diff --git a/gazelle/testdata/simple_binary/BUILD.out b/gazelle/python/testdata/simple_binary/BUILD.out similarity index 100% rename from gazelle/testdata/simple_binary/BUILD.out rename to gazelle/python/testdata/simple_binary/BUILD.out diff --git a/gazelle/testdata/simple_binary/README.md b/gazelle/python/testdata/simple_binary/README.md similarity index 100% rename from gazelle/testdata/simple_binary/README.md rename to gazelle/python/testdata/simple_binary/README.md diff --git a/gazelle/testdata/simple_test/WORKSPACE b/gazelle/python/testdata/simple_binary/WORKSPACE similarity index 100% rename from gazelle/testdata/simple_test/WORKSPACE rename to gazelle/python/testdata/simple_binary/WORKSPACE diff --git a/gazelle/python/testdata/simple_binary/__main__.py b/gazelle/python/testdata/simple_binary/__main__.py new file mode 100644 index 0000000000..730755995d --- /dev/null +++ b/gazelle/python/testdata/simple_binary/__main__.py @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For test purposes only. diff --git a/gazelle/python/testdata/simple_binary/test.yaml b/gazelle/python/testdata/simple_binary/test.yaml new file mode 100644 index 0000000000..fcea77710f --- /dev/null +++ b/gazelle/python/testdata/simple_binary/test.yaml @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- diff --git a/gazelle/testdata/simple_binary_with_library/BUILD.in b/gazelle/python/testdata/simple_binary_with_library/BUILD.in similarity index 100% rename from gazelle/testdata/simple_binary_with_library/BUILD.in rename to gazelle/python/testdata/simple_binary_with_library/BUILD.in diff --git a/gazelle/testdata/simple_binary_with_library/BUILD.out b/gazelle/python/testdata/simple_binary_with_library/BUILD.out similarity index 100% rename from gazelle/testdata/simple_binary_with_library/BUILD.out rename to gazelle/python/testdata/simple_binary_with_library/BUILD.out diff --git a/gazelle/testdata/simple_binary_with_library/README.md b/gazelle/python/testdata/simple_binary_with_library/README.md similarity index 100% rename from gazelle/testdata/simple_binary_with_library/README.md rename to gazelle/python/testdata/simple_binary_with_library/README.md diff --git a/gazelle/testdata/subdir_sources/WORKSPACE b/gazelle/python/testdata/simple_binary_with_library/WORKSPACE similarity index 100% rename from gazelle/testdata/subdir_sources/WORKSPACE rename to gazelle/python/testdata/simple_binary_with_library/WORKSPACE diff --git a/gazelle/python/testdata/simple_binary_with_library/__init__.py b/gazelle/python/testdata/simple_binary_with_library/__init__.py new file mode 100644 index 0000000000..730755995d --- /dev/null +++ b/gazelle/python/testdata/simple_binary_with_library/__init__.py @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For test purposes only. diff --git a/gazelle/python/testdata/simple_binary_with_library/__main__.py b/gazelle/python/testdata/simple_binary_with_library/__main__.py new file mode 100644 index 0000000000..bc7ddf0a71 --- /dev/null +++ b/gazelle/python/testdata/simple_binary_with_library/__main__.py @@ -0,0 +1,16 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For test purposes only. +import foo diff --git a/gazelle/python/testdata/simple_binary_with_library/bar.py b/gazelle/python/testdata/simple_binary_with_library/bar.py new file mode 100644 index 0000000000..730755995d --- /dev/null +++ b/gazelle/python/testdata/simple_binary_with_library/bar.py @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For test purposes only. diff --git a/gazelle/python/testdata/simple_binary_with_library/foo.py b/gazelle/python/testdata/simple_binary_with_library/foo.py new file mode 100644 index 0000000000..730755995d --- /dev/null +++ b/gazelle/python/testdata/simple_binary_with_library/foo.py @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For test purposes only. diff --git a/gazelle/python/testdata/simple_binary_with_library/test.yaml b/gazelle/python/testdata/simple_binary_with_library/test.yaml new file mode 100644 index 0000000000..fcea77710f --- /dev/null +++ b/gazelle/python/testdata/simple_binary_with_library/test.yaml @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- diff --git a/gazelle/testdata/subdir_sources/foo/BUILD.in b/gazelle/python/testdata/simple_library/BUILD.in similarity index 100% rename from gazelle/testdata/subdir_sources/foo/BUILD.in rename to gazelle/python/testdata/simple_library/BUILD.in diff --git a/gazelle/testdata/simple_library/BUILD.out b/gazelle/python/testdata/simple_library/BUILD.out similarity index 100% rename from gazelle/testdata/simple_library/BUILD.out rename to gazelle/python/testdata/simple_library/BUILD.out diff --git a/gazelle/testdata/simple_library/README.md b/gazelle/python/testdata/simple_library/README.md similarity index 100% rename from gazelle/testdata/simple_library/README.md rename to gazelle/python/testdata/simple_library/README.md diff --git a/gazelle/testdata/with_nested_import_statements/WORKSPACE b/gazelle/python/testdata/simple_library/WORKSPACE similarity index 100% rename from gazelle/testdata/with_nested_import_statements/WORKSPACE rename to gazelle/python/testdata/simple_library/WORKSPACE diff --git a/gazelle/python/testdata/simple_library/__init__.py b/gazelle/python/testdata/simple_library/__init__.py new file mode 100644 index 0000000000..730755995d --- /dev/null +++ b/gazelle/python/testdata/simple_library/__init__.py @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For test purposes only. diff --git a/gazelle/python/testdata/simple_library/test.yaml b/gazelle/python/testdata/simple_library/test.yaml new file mode 100644 index 0000000000..fcea77710f --- /dev/null +++ b/gazelle/python/testdata/simple_library/test.yaml @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- diff --git a/gazelle/testdata/subdir_sources/foo/has_build/BUILD.in b/gazelle/python/testdata/simple_library_without_init/BUILD.in similarity index 100% rename from gazelle/testdata/subdir_sources/foo/has_build/BUILD.in rename to gazelle/python/testdata/simple_library_without_init/BUILD.in diff --git a/gazelle/testdata/subdir_sources/foo/has_build_bazel/BUILD.bazel.in b/gazelle/python/testdata/simple_library_without_init/BUILD.out similarity index 100% rename from gazelle/testdata/subdir_sources/foo/has_build_bazel/BUILD.bazel.in rename to gazelle/python/testdata/simple_library_without_init/BUILD.out diff --git a/gazelle/testdata/simple_library_without_init/README.md b/gazelle/python/testdata/simple_library_without_init/README.md similarity index 100% rename from gazelle/testdata/simple_library_without_init/README.md rename to gazelle/python/testdata/simple_library_without_init/README.md diff --git a/gazelle/testdata/with_std_requirements/WORKSPACE b/gazelle/python/testdata/simple_library_without_init/WORKSPACE similarity index 100% rename from gazelle/testdata/with_std_requirements/WORKSPACE rename to gazelle/python/testdata/simple_library_without_init/WORKSPACE diff --git a/gazelle/testdata/subdir_sources/foo/has_init/BUILD.in b/gazelle/python/testdata/simple_library_without_init/foo/BUILD.in similarity index 100% rename from gazelle/testdata/subdir_sources/foo/has_init/BUILD.in rename to gazelle/python/testdata/simple_library_without_init/foo/BUILD.in diff --git a/gazelle/testdata/simple_library_without_init/foo/BUILD.out b/gazelle/python/testdata/simple_library_without_init/foo/BUILD.out similarity index 100% rename from gazelle/testdata/simple_library_without_init/foo/BUILD.out rename to gazelle/python/testdata/simple_library_without_init/foo/BUILD.out diff --git a/gazelle/python/testdata/simple_library_without_init/foo/foo.py b/gazelle/python/testdata/simple_library_without_init/foo/foo.py new file mode 100644 index 0000000000..730755995d --- /dev/null +++ b/gazelle/python/testdata/simple_library_without_init/foo/foo.py @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For test purposes only. diff --git a/gazelle/python/testdata/simple_library_without_init/test.yaml b/gazelle/python/testdata/simple_library_without_init/test.yaml new file mode 100644 index 0000000000..fcea77710f --- /dev/null +++ b/gazelle/python/testdata/simple_library_without_init/test.yaml @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- diff --git a/gazelle/testdata/simple_test/BUILD.in b/gazelle/python/testdata/simple_test/BUILD.in similarity index 100% rename from gazelle/testdata/simple_test/BUILD.in rename to gazelle/python/testdata/simple_test/BUILD.in diff --git a/gazelle/testdata/simple_test/BUILD.out b/gazelle/python/testdata/simple_test/BUILD.out similarity index 100% rename from gazelle/testdata/simple_test/BUILD.out rename to gazelle/python/testdata/simple_test/BUILD.out diff --git a/gazelle/testdata/simple_test/README.md b/gazelle/python/testdata/simple_test/README.md similarity index 100% rename from gazelle/testdata/simple_test/README.md rename to gazelle/python/testdata/simple_test/README.md diff --git a/gazelle/testdata/with_third_party_requirements/WORKSPACE b/gazelle/python/testdata/simple_test/WORKSPACE similarity index 100% rename from gazelle/testdata/with_third_party_requirements/WORKSPACE rename to gazelle/python/testdata/simple_test/WORKSPACE diff --git a/gazelle/python/testdata/simple_test/__init__.py b/gazelle/python/testdata/simple_test/__init__.py new file mode 100644 index 0000000000..b274b0d921 --- /dev/null +++ b/gazelle/python/testdata/simple_test/__init__.py @@ -0,0 +1,17 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from foo import foo + +_ = foo diff --git a/gazelle/python/testdata/simple_test/__test__.py b/gazelle/python/testdata/simple_test/__test__.py new file mode 100644 index 0000000000..2b180a5f53 --- /dev/null +++ b/gazelle/python/testdata/simple_test/__test__.py @@ -0,0 +1,26 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import unittest + +from __init__ import foo + + +class FooTest(unittest.TestCase): + def test_foo(self): + self.assertEqual("foo", foo()) + + +if __name__ == "__main__": + unittest.main() diff --git a/gazelle/python/testdata/simple_test/foo.py b/gazelle/python/testdata/simple_test/foo.py new file mode 100644 index 0000000000..932de45b74 --- /dev/null +++ b/gazelle/python/testdata/simple_test/foo.py @@ -0,0 +1,16 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +def foo(): + return "foo" diff --git a/gazelle/python/testdata/simple_test/test.yaml b/gazelle/python/testdata/simple_test/test.yaml new file mode 100644 index 0000000000..2410223e59 --- /dev/null +++ b/gazelle/python/testdata/simple_test/test.yaml @@ -0,0 +1,17 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- +expect: + exit_code: 0 diff --git a/gazelle/python/testdata/simple_test_with_conftest/BUILD.in b/gazelle/python/testdata/simple_test_with_conftest/BUILD.in new file mode 100644 index 0000000000..3f2beb3147 --- /dev/null +++ b/gazelle/python/testdata/simple_test_with_conftest/BUILD.in @@ -0,0 +1 @@ +load("@rules_python//python:defs.bzl", "py_library") diff --git a/gazelle/python/testdata/simple_test_with_conftest/BUILD.out b/gazelle/python/testdata/simple_test_with_conftest/BUILD.out new file mode 100644 index 0000000000..18079bf2f4 --- /dev/null +++ b/gazelle/python/testdata/simple_test_with_conftest/BUILD.out @@ -0,0 +1,27 @@ +load("@rules_python//python:defs.bzl", "py_library", "py_test") + +py_library( + name = "simple_test_with_conftest", + srcs = [ + "__init__.py", + "foo.py", + ], + visibility = ["//:__subpackages__"], +) + +py_library( + name = "conftest", + testonly = True, + srcs = ["conftest.py"], + visibility = ["//:__subpackages__"], +) + +py_test( + name = "simple_test_with_conftest_test", + srcs = ["__test__.py"], + main = "__test__.py", + deps = [ + ":conftest", + ":simple_test_with_conftest", + ], +) diff --git a/gazelle/python/testdata/simple_test_with_conftest/README.md b/gazelle/python/testdata/simple_test_with_conftest/README.md new file mode 100644 index 0000000000..0ff245f808 --- /dev/null +++ b/gazelle/python/testdata/simple_test_with_conftest/README.md @@ -0,0 +1,4 @@ +# Simple test with conftest.py + +This test case asserts that a simple `py_test` is generated as expected when a +`conftest.py` is present. diff --git a/gazelle/testdata/with_third_party_requirements_from_imports/WORKSPACE b/gazelle/python/testdata/simple_test_with_conftest/WORKSPACE similarity index 100% rename from gazelle/testdata/with_third_party_requirements_from_imports/WORKSPACE rename to gazelle/python/testdata/simple_test_with_conftest/WORKSPACE diff --git a/gazelle/python/testdata/simple_test_with_conftest/__init__.py b/gazelle/python/testdata/simple_test_with_conftest/__init__.py new file mode 100644 index 0000000000..b274b0d921 --- /dev/null +++ b/gazelle/python/testdata/simple_test_with_conftest/__init__.py @@ -0,0 +1,17 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from foo import foo + +_ = foo diff --git a/gazelle/python/testdata/simple_test_with_conftest/__test__.py b/gazelle/python/testdata/simple_test_with_conftest/__test__.py new file mode 100644 index 0000000000..2b180a5f53 --- /dev/null +++ b/gazelle/python/testdata/simple_test_with_conftest/__test__.py @@ -0,0 +1,26 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import unittest + +from __init__ import foo + + +class FooTest(unittest.TestCase): + def test_foo(self): + self.assertEqual("foo", foo()) + + +if __name__ == "__main__": + unittest.main() diff --git a/gazelle/python/testdata/simple_test_with_conftest/bar/BUILD.in b/gazelle/python/testdata/simple_test_with_conftest/bar/BUILD.in new file mode 100644 index 0000000000..3f2beb3147 --- /dev/null +++ b/gazelle/python/testdata/simple_test_with_conftest/bar/BUILD.in @@ -0,0 +1 @@ +load("@rules_python//python:defs.bzl", "py_library") diff --git a/gazelle/python/testdata/simple_test_with_conftest/bar/BUILD.out b/gazelle/python/testdata/simple_test_with_conftest/bar/BUILD.out new file mode 100644 index 0000000000..e42c4998b1 --- /dev/null +++ b/gazelle/python/testdata/simple_test_with_conftest/bar/BUILD.out @@ -0,0 +1,30 @@ +load("@rules_python//python:defs.bzl", "py_library", "py_test") + +py_library( + name = "bar", + srcs = [ + "__init__.py", + "bar.py", + ], + imports = [".."], + visibility = ["//:__subpackages__"], +) + +py_library( + name = "conftest", + testonly = True, + srcs = ["conftest.py"], + imports = [".."], + visibility = ["//:__subpackages__"], +) + +py_test( + name = "bar_test", + srcs = ["__test__.py"], + imports = [".."], + main = "__test__.py", + deps = [ + ":bar", + ":conftest", + ], +) diff --git a/gazelle/python/testdata/simple_test_with_conftest/bar/__init__.py b/gazelle/python/testdata/simple_test_with_conftest/bar/__init__.py new file mode 100644 index 0000000000..3f0275e179 --- /dev/null +++ b/gazelle/python/testdata/simple_test_with_conftest/bar/__init__.py @@ -0,0 +1,17 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from bar import bar + +_ = bar diff --git a/gazelle/python/testdata/simple_test_with_conftest/bar/__test__.py b/gazelle/python/testdata/simple_test_with_conftest/bar/__test__.py new file mode 100644 index 0000000000..00c4c28247 --- /dev/null +++ b/gazelle/python/testdata/simple_test_with_conftest/bar/__test__.py @@ -0,0 +1,26 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import unittest + +from __init__ import bar + + +class BarTest(unittest.TestCase): + def test_bar(self): + self.assertEqual("bar", bar()) + + +if __name__ == "__main__": + unittest.main() diff --git a/gazelle/python/testdata/simple_test_with_conftest/bar/bar.py b/gazelle/python/testdata/simple_test_with_conftest/bar/bar.py new file mode 100644 index 0000000000..ba6a62db30 --- /dev/null +++ b/gazelle/python/testdata/simple_test_with_conftest/bar/bar.py @@ -0,0 +1,17 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +def bar(): + return "bar" diff --git a/gazelle/python/testdata/simple_test_with_conftest/bar/conftest.py b/gazelle/python/testdata/simple_test_with_conftest/bar/conftest.py new file mode 100644 index 0000000000..41010956cf --- /dev/null +++ b/gazelle/python/testdata/simple_test_with_conftest/bar/conftest.py @@ -0,0 +1,13 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. diff --git a/gazelle/python/testdata/simple_test_with_conftest/conftest.py b/gazelle/python/testdata/simple_test_with_conftest/conftest.py new file mode 100644 index 0000000000..bbdfb4c588 --- /dev/null +++ b/gazelle/python/testdata/simple_test_with_conftest/conftest.py @@ -0,0 +1,14 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + diff --git a/gazelle/python/testdata/simple_test_with_conftest/foo.py b/gazelle/python/testdata/simple_test_with_conftest/foo.py new file mode 100644 index 0000000000..932de45b74 --- /dev/null +++ b/gazelle/python/testdata/simple_test_with_conftest/foo.py @@ -0,0 +1,16 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +def foo(): + return "foo" diff --git a/gazelle/python/testdata/simple_test_with_conftest/test.yaml b/gazelle/python/testdata/simple_test_with_conftest/test.yaml new file mode 100644 index 0000000000..2410223e59 --- /dev/null +++ b/gazelle/python/testdata/simple_test_with_conftest/test.yaml @@ -0,0 +1,17 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- +expect: + exit_code: 0 diff --git a/gazelle/testdata/subdir_sources/foo/has_main/BUILD.in b/gazelle/python/testdata/subdir_sources/BUILD.in similarity index 100% rename from gazelle/testdata/subdir_sources/foo/has_main/BUILD.in rename to gazelle/python/testdata/subdir_sources/BUILD.in diff --git a/gazelle/testdata/subdir_sources/BUILD.out b/gazelle/python/testdata/subdir_sources/BUILD.out similarity index 100% rename from gazelle/testdata/subdir_sources/BUILD.out rename to gazelle/python/testdata/subdir_sources/BUILD.out diff --git a/gazelle/testdata/subdir_sources/README.md b/gazelle/python/testdata/subdir_sources/README.md similarity index 100% rename from gazelle/testdata/subdir_sources/README.md rename to gazelle/python/testdata/subdir_sources/README.md diff --git a/gazelle/python/testdata/subdir_sources/WORKSPACE b/gazelle/python/testdata/subdir_sources/WORKSPACE new file mode 100644 index 0000000000..faff6af87a --- /dev/null +++ b/gazelle/python/testdata/subdir_sources/WORKSPACE @@ -0,0 +1 @@ +# This is a Bazel workspace for the Gazelle test data. diff --git a/gazelle/python/testdata/subdir_sources/__main__.py b/gazelle/python/testdata/subdir_sources/__main__.py new file mode 100644 index 0000000000..aacfc67bc5 --- /dev/null +++ b/gazelle/python/testdata/subdir_sources/__main__.py @@ -0,0 +1,21 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import foo.bar.bar as bar +import foo.baz.baz as baz +import one.two.three as three + +_ = bar +_ = baz +_ = three diff --git a/gazelle/testdata/subdir_sources/foo/has_test/BUILD.in b/gazelle/python/testdata/subdir_sources/foo/BUILD.in similarity index 100% rename from gazelle/testdata/subdir_sources/foo/has_test/BUILD.in rename to gazelle/python/testdata/subdir_sources/foo/BUILD.in diff --git a/gazelle/testdata/subdir_sources/foo/BUILD.out b/gazelle/python/testdata/subdir_sources/foo/BUILD.out similarity index 100% rename from gazelle/testdata/subdir_sources/foo/BUILD.out rename to gazelle/python/testdata/subdir_sources/foo/BUILD.out diff --git a/gazelle/python/testdata/subdir_sources/foo/__init__.py b/gazelle/python/testdata/subdir_sources/foo/__init__.py new file mode 100644 index 0000000000..730755995d --- /dev/null +++ b/gazelle/python/testdata/subdir_sources/foo/__init__.py @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For test purposes only. diff --git a/gazelle/python/testdata/subdir_sources/foo/bar/bar.py b/gazelle/python/testdata/subdir_sources/foo/bar/bar.py new file mode 100644 index 0000000000..730755995d --- /dev/null +++ b/gazelle/python/testdata/subdir_sources/foo/bar/bar.py @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For test purposes only. diff --git a/gazelle/python/testdata/subdir_sources/foo/baz/baz.py b/gazelle/python/testdata/subdir_sources/foo/baz/baz.py new file mode 100644 index 0000000000..730755995d --- /dev/null +++ b/gazelle/python/testdata/subdir_sources/foo/baz/baz.py @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For test purposes only. diff --git a/gazelle/python/testdata/subdir_sources/foo/foo.py b/gazelle/python/testdata/subdir_sources/foo/foo.py new file mode 100644 index 0000000000..a98c73d4eb --- /dev/null +++ b/gazelle/python/testdata/subdir_sources/foo/foo.py @@ -0,0 +1,17 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import foo.bar.bar as bar + +_ = bar diff --git a/gazelle/testdata/subdir_sources/one/BUILD.in b/gazelle/python/testdata/subdir_sources/foo/has_build/BUILD.in similarity index 100% rename from gazelle/testdata/subdir_sources/one/BUILD.in rename to gazelle/python/testdata/subdir_sources/foo/has_build/BUILD.in diff --git a/gazelle/testdata/subdir_sources/foo/has_build/BUILD.out b/gazelle/python/testdata/subdir_sources/foo/has_build/BUILD.out similarity index 100% rename from gazelle/testdata/subdir_sources/foo/has_build/BUILD.out rename to gazelle/python/testdata/subdir_sources/foo/has_build/BUILD.out diff --git a/gazelle/python/testdata/subdir_sources/foo/has_build/python/my_module.py b/gazelle/python/testdata/subdir_sources/foo/has_build/python/my_module.py new file mode 100644 index 0000000000..730755995d --- /dev/null +++ b/gazelle/python/testdata/subdir_sources/foo/has_build/python/my_module.py @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For test purposes only. diff --git a/gazelle/testdata/subdir_sources/one/two/BUILD.in b/gazelle/python/testdata/subdir_sources/foo/has_build_bazel/BUILD.bazel.in similarity index 100% rename from gazelle/testdata/subdir_sources/one/two/BUILD.in rename to gazelle/python/testdata/subdir_sources/foo/has_build_bazel/BUILD.bazel.in diff --git a/gazelle/python/testdata/subdir_sources/foo/has_build_bazel/python/my_module.py b/gazelle/python/testdata/subdir_sources/foo/has_build_bazel/python/my_module.py new file mode 100644 index 0000000000..730755995d --- /dev/null +++ b/gazelle/python/testdata/subdir_sources/foo/has_build_bazel/python/my_module.py @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For test purposes only. diff --git a/gazelle/testdata/with_nested_import_statements/BUILD.in b/gazelle/python/testdata/subdir_sources/foo/has_init/BUILD.in similarity index 100% rename from gazelle/testdata/with_nested_import_statements/BUILD.in rename to gazelle/python/testdata/subdir_sources/foo/has_init/BUILD.in diff --git a/gazelle/testdata/subdir_sources/foo/has_init/BUILD.out b/gazelle/python/testdata/subdir_sources/foo/has_init/BUILD.out similarity index 100% rename from gazelle/testdata/subdir_sources/foo/has_init/BUILD.out rename to gazelle/python/testdata/subdir_sources/foo/has_init/BUILD.out diff --git a/gazelle/python/testdata/subdir_sources/foo/has_init/__init__.py b/gazelle/python/testdata/subdir_sources/foo/has_init/__init__.py new file mode 100644 index 0000000000..730755995d --- /dev/null +++ b/gazelle/python/testdata/subdir_sources/foo/has_init/__init__.py @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For test purposes only. diff --git a/gazelle/python/testdata/subdir_sources/foo/has_init/python/my_module.py b/gazelle/python/testdata/subdir_sources/foo/has_init/python/my_module.py new file mode 100644 index 0000000000..730755995d --- /dev/null +++ b/gazelle/python/testdata/subdir_sources/foo/has_init/python/my_module.py @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For test purposes only. diff --git a/gazelle/testdata/with_std_requirements/BUILD.in b/gazelle/python/testdata/subdir_sources/foo/has_main/BUILD.in similarity index 100% rename from gazelle/testdata/with_std_requirements/BUILD.in rename to gazelle/python/testdata/subdir_sources/foo/has_main/BUILD.in diff --git a/gazelle/testdata/subdir_sources/foo/has_main/BUILD.out b/gazelle/python/testdata/subdir_sources/foo/has_main/BUILD.out similarity index 100% rename from gazelle/testdata/subdir_sources/foo/has_main/BUILD.out rename to gazelle/python/testdata/subdir_sources/foo/has_main/BUILD.out diff --git a/gazelle/python/testdata/subdir_sources/foo/has_main/__main__.py b/gazelle/python/testdata/subdir_sources/foo/has_main/__main__.py new file mode 100644 index 0000000000..bd0fe61faa --- /dev/null +++ b/gazelle/python/testdata/subdir_sources/foo/has_main/__main__.py @@ -0,0 +1,16 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For test purposes only. +import foo.has_main.python.my_module \ No newline at end of file diff --git a/gazelle/python/testdata/subdir_sources/foo/has_main/python/my_module.py b/gazelle/python/testdata/subdir_sources/foo/has_main/python/my_module.py new file mode 100644 index 0000000000..730755995d --- /dev/null +++ b/gazelle/python/testdata/subdir_sources/foo/has_main/python/my_module.py @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For test purposes only. diff --git a/gazelle/testdata/with_third_party_requirements/BUILD.in b/gazelle/python/testdata/subdir_sources/foo/has_test/BUILD.in similarity index 100% rename from gazelle/testdata/with_third_party_requirements/BUILD.in rename to gazelle/python/testdata/subdir_sources/foo/has_test/BUILD.in diff --git a/gazelle/testdata/subdir_sources/foo/has_test/BUILD.out b/gazelle/python/testdata/subdir_sources/foo/has_test/BUILD.out similarity index 100% rename from gazelle/testdata/subdir_sources/foo/has_test/BUILD.out rename to gazelle/python/testdata/subdir_sources/foo/has_test/BUILD.out diff --git a/gazelle/python/testdata/subdir_sources/foo/has_test/__test__.py b/gazelle/python/testdata/subdir_sources/foo/has_test/__test__.py new file mode 100644 index 0000000000..3c9ed1a1bd --- /dev/null +++ b/gazelle/python/testdata/subdir_sources/foo/has_test/__test__.py @@ -0,0 +1,16 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For test purposes only. +import foo.has_test.python.my_module \ No newline at end of file diff --git a/gazelle/python/testdata/subdir_sources/foo/has_test/python/my_module.py b/gazelle/python/testdata/subdir_sources/foo/has_test/python/my_module.py new file mode 100644 index 0000000000..730755995d --- /dev/null +++ b/gazelle/python/testdata/subdir_sources/foo/has_test/python/my_module.py @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For test purposes only. diff --git a/gazelle/testdata/with_third_party_requirements_from_imports/BUILD.in b/gazelle/python/testdata/subdir_sources/one/BUILD.in similarity index 100% rename from gazelle/testdata/with_third_party_requirements_from_imports/BUILD.in rename to gazelle/python/testdata/subdir_sources/one/BUILD.in diff --git a/gazelle/testdata/subdir_sources/one/BUILD.out b/gazelle/python/testdata/subdir_sources/one/BUILD.out similarity index 100% rename from gazelle/testdata/subdir_sources/one/BUILD.out rename to gazelle/python/testdata/subdir_sources/one/BUILD.out diff --git a/gazelle/python/testdata/subdir_sources/one/__init__.py b/gazelle/python/testdata/subdir_sources/one/__init__.py new file mode 100644 index 0000000000..730755995d --- /dev/null +++ b/gazelle/python/testdata/subdir_sources/one/__init__.py @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For test purposes only. diff --git a/gazelle/python/testdata/subdir_sources/one/two/BUILD.in b/gazelle/python/testdata/subdir_sources/one/two/BUILD.in new file mode 100644 index 0000000000..e69de29bb2 diff --git a/gazelle/testdata/subdir_sources/one/two/BUILD.out b/gazelle/python/testdata/subdir_sources/one/two/BUILD.out similarity index 100% rename from gazelle/testdata/subdir_sources/one/two/BUILD.out rename to gazelle/python/testdata/subdir_sources/one/two/BUILD.out diff --git a/gazelle/python/testdata/subdir_sources/one/two/README.md b/gazelle/python/testdata/subdir_sources/one/two/README.md new file mode 100644 index 0000000000..ec4c15ddaa --- /dev/null +++ b/gazelle/python/testdata/subdir_sources/one/two/README.md @@ -0,0 +1,2 @@ +# Same package imports +This test case asserts that no `deps` is needed when a module imports another module in the same package \ No newline at end of file diff --git a/gazelle/python/testdata/subdir_sources/one/two/__init__.py b/gazelle/python/testdata/subdir_sources/one/two/__init__.py new file mode 100644 index 0000000000..72357b3c46 --- /dev/null +++ b/gazelle/python/testdata/subdir_sources/one/two/__init__.py @@ -0,0 +1,18 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import foo.baz.baz as baz +import three + +_ = baz diff --git a/gazelle/python/testdata/subdir_sources/one/two/three.py b/gazelle/python/testdata/subdir_sources/one/two/three.py new file mode 100644 index 0000000000..730755995d --- /dev/null +++ b/gazelle/python/testdata/subdir_sources/one/two/three.py @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For test purposes only. diff --git a/gazelle/python/testdata/subdir_sources/test.yaml b/gazelle/python/testdata/subdir_sources/test.yaml new file mode 100644 index 0000000000..fcea77710f --- /dev/null +++ b/gazelle/python/testdata/subdir_sources/test.yaml @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- diff --git a/gazelle/python/testdata/with_nested_import_statements/BUILD.in b/gazelle/python/testdata/with_nested_import_statements/BUILD.in new file mode 100644 index 0000000000..e69de29bb2 diff --git a/gazelle/testdata/with_nested_import_statements/BUILD.out b/gazelle/python/testdata/with_nested_import_statements/BUILD.out similarity index 78% rename from gazelle/testdata/with_nested_import_statements/BUILD.out rename to gazelle/python/testdata/with_nested_import_statements/BUILD.out index bb2f34db55..45bf265180 100644 --- a/gazelle/testdata/with_nested_import_statements/BUILD.out +++ b/gazelle/python/testdata/with_nested_import_statements/BUILD.out @@ -4,5 +4,5 @@ py_library( name = "with_nested_import_statements", srcs = ["__init__.py"], visibility = ["//:__subpackages__"], - deps = ["@gazelle_python_test//pypi__boto3"], + deps = ["@gazelle_python_test_boto3//:pkg"], ) diff --git a/gazelle/testdata/with_nested_import_statements/README.md b/gazelle/python/testdata/with_nested_import_statements/README.md similarity index 100% rename from gazelle/testdata/with_nested_import_statements/README.md rename to gazelle/python/testdata/with_nested_import_statements/README.md diff --git a/gazelle/python/testdata/with_nested_import_statements/WORKSPACE b/gazelle/python/testdata/with_nested_import_statements/WORKSPACE new file mode 100644 index 0000000000..faff6af87a --- /dev/null +++ b/gazelle/python/testdata/with_nested_import_statements/WORKSPACE @@ -0,0 +1 @@ +# This is a Bazel workspace for the Gazelle test data. diff --git a/gazelle/python/testdata/with_nested_import_statements/__init__.py b/gazelle/python/testdata/with_nested_import_statements/__init__.py new file mode 100644 index 0000000000..733b51f974 --- /dev/null +++ b/gazelle/python/testdata/with_nested_import_statements/__init__.py @@ -0,0 +1,25 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys + +_ = os +_ = sys + + +def main(): + import boto3 + + _ = boto3 diff --git a/gazelle/python/testdata/with_nested_import_statements/gazelle_python.yaml b/gazelle/python/testdata/with_nested_import_statements/gazelle_python.yaml new file mode 100644 index 0000000000..1bf594f9b4 --- /dev/null +++ b/gazelle/python/testdata/with_nested_import_statements/gazelle_python.yaml @@ -0,0 +1,18 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +manifest: + modules_mapping: + boto3: boto3 + pip_deps_repository_name: gazelle_python_test diff --git a/gazelle/python/testdata/with_nested_import_statements/test.yaml b/gazelle/python/testdata/with_nested_import_statements/test.yaml new file mode 100644 index 0000000000..fcea77710f --- /dev/null +++ b/gazelle/python/testdata/with_nested_import_statements/test.yaml @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- diff --git a/gazelle/python/testdata/with_std_requirements/BUILD.in b/gazelle/python/testdata/with_std_requirements/BUILD.in new file mode 100644 index 0000000000..e69de29bb2 diff --git a/gazelle/testdata/with_std_requirements/BUILD.out b/gazelle/python/testdata/with_std_requirements/BUILD.out similarity index 100% rename from gazelle/testdata/with_std_requirements/BUILD.out rename to gazelle/python/testdata/with_std_requirements/BUILD.out diff --git a/gazelle/testdata/with_std_requirements/README.md b/gazelle/python/testdata/with_std_requirements/README.md similarity index 100% rename from gazelle/testdata/with_std_requirements/README.md rename to gazelle/python/testdata/with_std_requirements/README.md diff --git a/gazelle/python/testdata/with_std_requirements/WORKSPACE b/gazelle/python/testdata/with_std_requirements/WORKSPACE new file mode 100644 index 0000000000..faff6af87a --- /dev/null +++ b/gazelle/python/testdata/with_std_requirements/WORKSPACE @@ -0,0 +1 @@ +# This is a Bazel workspace for the Gazelle test data. diff --git a/gazelle/python/testdata/with_std_requirements/__init__.py b/gazelle/python/testdata/with_std_requirements/__init__.py new file mode 100644 index 0000000000..e51d320213 --- /dev/null +++ b/gazelle/python/testdata/with_std_requirements/__init__.py @@ -0,0 +1,19 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys + +_ = os +_ = sys diff --git a/gazelle/python/testdata/with_std_requirements/test.yaml b/gazelle/python/testdata/with_std_requirements/test.yaml new file mode 100644 index 0000000000..fcea77710f --- /dev/null +++ b/gazelle/python/testdata/with_std_requirements/test.yaml @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- diff --git a/gazelle/python/testdata/with_third_party_requirements/BUILD.in b/gazelle/python/testdata/with_third_party_requirements/BUILD.in new file mode 100644 index 0000000000..e69de29bb2 diff --git a/gazelle/testdata/with_third_party_requirements/BUILD.out b/gazelle/python/testdata/with_third_party_requirements/BUILD.out similarity index 62% rename from gazelle/testdata/with_third_party_requirements/BUILD.out rename to gazelle/python/testdata/with_third_party_requirements/BUILD.out index 9854730a2e..2a97d8bc1e 100644 --- a/gazelle/testdata/with_third_party_requirements/BUILD.out +++ b/gazelle/python/testdata/with_third_party_requirements/BUILD.out @@ -9,9 +9,9 @@ py_library( ], visibility = ["//:__subpackages__"], deps = [ - "@gazelle_python_test//pypi__baz", - "@gazelle_python_test//pypi__boto3", - "@gazelle_python_test//pypi__djangorestframework", + "@gazelle_python_test_baz//:pkg", + "@gazelle_python_test_boto3//:pkg", + "@gazelle_python_test_djangorestframework//:pkg", ], ) @@ -20,8 +20,5 @@ py_binary( srcs = ["__main__.py"], main = "__main__.py", visibility = ["//:__subpackages__"], - deps = [ - ":with_third_party_requirements", - "@gazelle_python_test//pypi__baz", - ], + deps = ["@gazelle_python_test_baz//:pkg"], ) diff --git a/gazelle/python/testdata/with_third_party_requirements/README.md b/gazelle/python/testdata/with_third_party_requirements/README.md new file mode 100644 index 0000000000..a7ef7a3ca7 --- /dev/null +++ b/gazelle/python/testdata/with_third_party_requirements/README.md @@ -0,0 +1,7 @@ +# With third-party requirements + +This test case asserts that +* a `py_library` is generated with dependencies +extracted from its sources and a `py_binary` is generated embeding the +`py_library` and inherits its dependencies, without specifying the `deps` again. +* when a third-party library and a module in the same package having the same name, the one in the same package takes precedence. diff --git a/gazelle/python/testdata/with_third_party_requirements/WORKSPACE b/gazelle/python/testdata/with_third_party_requirements/WORKSPACE new file mode 100644 index 0000000000..faff6af87a --- /dev/null +++ b/gazelle/python/testdata/with_third_party_requirements/WORKSPACE @@ -0,0 +1 @@ +# This is a Bazel workspace for the Gazelle test data. diff --git a/gazelle/python/testdata/with_third_party_requirements/__init__.py b/gazelle/python/testdata/with_third_party_requirements/__init__.py new file mode 100644 index 0000000000..730755995d --- /dev/null +++ b/gazelle/python/testdata/with_third_party_requirements/__init__.py @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For test purposes only. diff --git a/gazelle/python/testdata/with_third_party_requirements/__main__.py b/gazelle/python/testdata/with_third_party_requirements/__main__.py new file mode 100644 index 0000000000..38e9a55fb5 --- /dev/null +++ b/gazelle/python/testdata/with_third_party_requirements/__main__.py @@ -0,0 +1,19 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import bar +import foo + +_ = bar +_ = foo diff --git a/gazelle/python/testdata/with_third_party_requirements/bar.py b/gazelle/python/testdata/with_third_party_requirements/bar.py new file mode 100644 index 0000000000..08f2e7c289 --- /dev/null +++ b/gazelle/python/testdata/with_third_party_requirements/bar.py @@ -0,0 +1,25 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +import bar +import boto3 +import rest_framework + +_ = os + +_ = bar +_ = boto3 +_ = rest_framework diff --git a/gazelle/python/testdata/with_third_party_requirements/foo.py b/gazelle/python/testdata/with_third_party_requirements/foo.py new file mode 100644 index 0000000000..9bebbfcfc6 --- /dev/null +++ b/gazelle/python/testdata/with_third_party_requirements/foo.py @@ -0,0 +1,25 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys + +import boto3 +import foo +import rest_framework + +_ = sys + +_ = boto3 +_ = foo +_ = rest_framework diff --git a/gazelle/python/testdata/with_third_party_requirements/gazelle_python.yaml b/gazelle/python/testdata/with_third_party_requirements/gazelle_python.yaml new file mode 100644 index 0000000000..7753cfff2c --- /dev/null +++ b/gazelle/python/testdata/with_third_party_requirements/gazelle_python.yaml @@ -0,0 +1,21 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +manifest: + modules_mapping: + boto3: boto3 + rest_framework: djangorestframework + foo: baz + bar: baz + pip_deps_repository_name: gazelle_python_test diff --git a/gazelle/python/testdata/with_third_party_requirements/test.yaml b/gazelle/python/testdata/with_third_party_requirements/test.yaml new file mode 100644 index 0000000000..fcea77710f --- /dev/null +++ b/gazelle/python/testdata/with_third_party_requirements/test.yaml @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- diff --git a/gazelle/python/testdata/with_third_party_requirements_from_imports/BUILD.in b/gazelle/python/testdata/with_third_party_requirements_from_imports/BUILD.in new file mode 100644 index 0000000000..e69de29bb2 diff --git a/gazelle/testdata/with_third_party_requirements_from_imports/BUILD.out b/gazelle/python/testdata/with_third_party_requirements_from_imports/BUILD.out similarity index 100% rename from gazelle/testdata/with_third_party_requirements_from_imports/BUILD.out rename to gazelle/python/testdata/with_third_party_requirements_from_imports/BUILD.out diff --git a/gazelle/testdata/with_third_party_requirements_from_imports/README.md b/gazelle/python/testdata/with_third_party_requirements_from_imports/README.md similarity index 100% rename from gazelle/testdata/with_third_party_requirements_from_imports/README.md rename to gazelle/python/testdata/with_third_party_requirements_from_imports/README.md diff --git a/gazelle/python/testdata/with_third_party_requirements_from_imports/WORKSPACE b/gazelle/python/testdata/with_third_party_requirements_from_imports/WORKSPACE new file mode 100644 index 0000000000..faff6af87a --- /dev/null +++ b/gazelle/python/testdata/with_third_party_requirements_from_imports/WORKSPACE @@ -0,0 +1 @@ +# This is a Bazel workspace for the Gazelle test data. diff --git a/gazelle/python/testdata/with_third_party_requirements_from_imports/__init__.py b/gazelle/python/testdata/with_third_party_requirements_from_imports/__init__.py new file mode 100644 index 0000000000..730755995d --- /dev/null +++ b/gazelle/python/testdata/with_third_party_requirements_from_imports/__init__.py @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For test purposes only. diff --git a/gazelle/python/testdata/with_third_party_requirements_from_imports/__main__.py b/gazelle/python/testdata/with_third_party_requirements_from_imports/__main__.py new file mode 100644 index 0000000000..2062a9b04a --- /dev/null +++ b/gazelle/python/testdata/with_third_party_requirements_from_imports/__main__.py @@ -0,0 +1,20 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from bar import main +from google.cloud import aiplatform + +if __name__ == "__main__": + print(aiplatform) + main() diff --git a/gazelle/python/testdata/with_third_party_requirements_from_imports/bar.py b/gazelle/python/testdata/with_third_party_requirements_from_imports/bar.py new file mode 100644 index 0000000000..6886b2b4e9 --- /dev/null +++ b/gazelle/python/testdata/with_third_party_requirements_from_imports/bar.py @@ -0,0 +1,20 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from google.cloud import aiplatform, storage + + +def main(): + a = dir(aiplatform) + b = dir(storage) diff --git a/gazelle/testdata/with_third_party_requirements_from_imports/gazelle_python.yaml b/gazelle/python/testdata/with_third_party_requirements_from_imports/gazelle_python.yaml similarity index 99% rename from gazelle/testdata/with_third_party_requirements_from_imports/gazelle_python.yaml rename to gazelle/python/testdata/with_third_party_requirements_from_imports/gazelle_python.yaml index 21edbc0a0d..8b5694b2d7 100644 --- a/gazelle/testdata/with_third_party_requirements_from_imports/gazelle_python.yaml +++ b/gazelle/python/testdata/with_third_party_requirements_from_imports/gazelle_python.yaml @@ -1,3 +1,17 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + manifest: modules_mapping: cachetools: cachetools @@ -1661,5 +1675,4 @@ manifest: urllib3.util.wait: urllib3 pip_repository: name: gazelle_python_test - incremental: true integrity: 32e38932043eca090a64ca741758d8e4a5817c2cd7dc821fc927914c32fb3114 diff --git a/gazelle/python/testdata/with_third_party_requirements_from_imports/test.yaml b/gazelle/python/testdata/with_third_party_requirements_from_imports/test.yaml new file mode 100644 index 0000000000..fcea77710f --- /dev/null +++ b/gazelle/python/testdata/with_third_party_requirements_from_imports/test.yaml @@ -0,0 +1,15 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- diff --git a/gazelle/pythonconfig/BUILD.bazel b/gazelle/pythonconfig/BUILD.bazel index cff75d9ee3..d0f1690d94 100644 --- a/gazelle/pythonconfig/BUILD.bazel +++ b/gazelle/pythonconfig/BUILD.bazel @@ -1,4 +1,4 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library") +load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") go_library( name = "pythonconfig", @@ -9,8 +9,20 @@ go_library( importpath = "github.com/bazelbuild/rules_python/gazelle/pythonconfig", visibility = ["//visibility:public"], deps = [ - "//gazelle/manifest", + "//manifest", "@bazel_gazelle//label:go_default_library", "@com_github_emirpasic_gods//lists/singlylinkedlist", ], ) + +go_test( + name = "pythonconfig_test", + srcs = ["pythonconfig_test.go"], + deps = [":pythonconfig"], +) + +filegroup( + name = "distribution", + srcs = glob(["**"]), + visibility = ["//:__pkg__"], +) diff --git a/gazelle/pythonconfig/pythonconfig.go b/gazelle/pythonconfig/pythonconfig.go index 7e65fd98d7..c7cd7c1a28 100644 --- a/gazelle/pythonconfig/pythonconfig.go +++ b/gazelle/pythonconfig/pythonconfig.go @@ -1,3 +1,17 @@ +// Copyright 2023 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package pythonconfig import ( @@ -76,6 +90,14 @@ var defaultIgnoreFiles = map[string]struct{}{ "setup.py": {}, } +func SanitizeDistribution(distributionName string) string { + sanitizedDistribution := strings.ToLower(distributionName) + sanitizedDistribution = strings.ReplaceAll(sanitizedDistribution, "-", "_") + sanitizedDistribution = strings.ReplaceAll(sanitizedDistribution, ".", "_") + + return sanitizedDistribution +} + // Configs is an extension of map[string]*Config. It provides finding methods // on top of the mapping. type Configs map[string]*Config @@ -204,18 +226,17 @@ func (c *Config) FindThirdPartyDependency(modName string) (string, bool) { } else if gazelleManifest.PipRepository != nil { distributionRepositoryName = gazelleManifest.PipRepository.Name } - sanitizedDistribution := strings.ToLower(distributionName) - sanitizedDistribution = strings.ReplaceAll(sanitizedDistribution, "-", "_") - var lbl label.Label - if gazelleManifest.PipRepository != nil && gazelleManifest.PipRepository.Incremental { - // @_//:pkg - distributionRepositoryName = distributionRepositoryName + "_" + sanitizedDistribution - lbl = label.New(distributionRepositoryName, "", "pkg") - } else { - // @//pypi__ - distributionPackage := "pypi__" + sanitizedDistribution - lbl = label.New(distributionRepositoryName, distributionPackage, distributionPackage) + sanitizedDistribution := SanitizeDistribution(distributionName) + + if gazelleManifest.PipRepository != nil && gazelleManifest.PipRepository.UsePipRepositoryAliases { + // @// + lbl := label.New(distributionRepositoryName, sanitizedDistribution, sanitizedDistribution) + return lbl.String(), true } + + // @_//:pkg + distributionRepositoryName = distributionRepositoryName + "_" + sanitizedDistribution + lbl := label.New(distributionRepositoryName, "", "pkg") return lbl.String(), true } } diff --git a/gazelle/pythonconfig/pythonconfig_test.go b/gazelle/pythonconfig/pythonconfig_test.go new file mode 100644 index 0000000000..1512eb97ae --- /dev/null +++ b/gazelle/pythonconfig/pythonconfig_test.go @@ -0,0 +1,28 @@ +package pythonconfig + +import ( + "testing" + + "github.com/bazelbuild/rules_python/gazelle/pythonconfig" +) + +func TestDistributionSanitizing(t *testing.T) { + tests := map[string]struct { + input string + want string + }{ + "upper case": {input: "DistWithUpperCase", want: "distwithuppercase"}, + "dashes": {input: "dist-with-dashes", want: "dist_with_dashes"}, + "dots": {input: "dist.with.dots", want: "dist_with_dots"}, + "mixed": {input: "To-be.sanitized", want: "to_be_sanitized"}, + } + + for name, tc := range tests { + t.Run(name, func(t *testing.T) { + got := pythonconfig.SanitizeDistribution(tc.input) + if tc.want != got { + t.Fatalf("expected %q, got %q", tc.want, got) + } + }) + } +} diff --git a/gazelle/pythonconfig/types.go b/gazelle/pythonconfig/types.go index bdb535bf6e..d83d35f015 100644 --- a/gazelle/pythonconfig/types.go +++ b/gazelle/pythonconfig/types.go @@ -1,3 +1,17 @@ +// Copyright 2023 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package pythonconfig import ( diff --git a/gazelle/std_modules.py b/gazelle/std_modules.py deleted file mode 100644 index ccd1dcd3aa..0000000000 --- a/gazelle/std_modules.py +++ /dev/null @@ -1,39 +0,0 @@ -# std_modules.py is a long-living program that communicates over STDIN and -# STDOUT. STDIN receives module names, one per line. For each module statement -# it evaluates, it outputs true/false for whether the module is part of the -# standard library or not. - -import site -import sys - - -# Don't return any paths, all userland site-packages should be ignored. -def __override_getusersitepackages__(): - return "" - - -site.getusersitepackages = __override_getusersitepackages__ - - -def is_std_modules(module): - try: - __import__(module, globals(), locals(), [], 0) - return True - except Exception: - return False - - -def main(stdin, stdout): - for module in stdin: - module = module.strip() - # Don't print the boolean directly as it is captilized in Python. - print( - "true" if is_std_modules(module) else "false", - end="\n", - file=stdout, - ) - stdout.flush() - - -if __name__ == "__main__": - exit(main(sys.stdin, sys.stdout)) diff --git a/gazelle/testdata/dependency_resolution_order/__init__.py b/gazelle/testdata/dependency_resolution_order/__init__.py deleted file mode 100644 index f2a1c081ad..0000000000 --- a/gazelle/testdata/dependency_resolution_order/__init__.py +++ /dev/null @@ -1,10 +0,0 @@ -import sys - -import bar -import baz -import foo - -_ = sys -_ = bar -_ = baz -_ = foo diff --git a/gazelle/testdata/dependency_resolution_order/bar/__init__.py b/gazelle/testdata/dependency_resolution_order/bar/__init__.py deleted file mode 100644 index 76c3313f0e..0000000000 --- a/gazelle/testdata/dependency_resolution_order/bar/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -import os - -_ = os diff --git a/gazelle/testdata/dependency_resolution_order/baz/__init__.py b/gazelle/testdata/dependency_resolution_order/baz/__init__.py deleted file mode 100644 index 76c3313f0e..0000000000 --- a/gazelle/testdata/dependency_resolution_order/baz/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -import os - -_ = os diff --git a/gazelle/testdata/dependency_resolution_order/foo/__init__.py b/gazelle/testdata/dependency_resolution_order/foo/__init__.py deleted file mode 100644 index 76c3313f0e..0000000000 --- a/gazelle/testdata/dependency_resolution_order/foo/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -import os - -_ = os diff --git a/gazelle/testdata/dependency_resolution_order/gazelle_python.yaml b/gazelle/testdata/dependency_resolution_order/gazelle_python.yaml deleted file mode 100644 index 7e911bf29b..0000000000 --- a/gazelle/testdata/dependency_resolution_order/gazelle_python.yaml +++ /dev/null @@ -1,4 +0,0 @@ -manifest: - modules_mapping: - foo: some_foo - pip_deps_repository_name: gazelle_python_test diff --git a/gazelle/testdata/dependency_resolution_order/somewhere/bar/__init__.py b/gazelle/testdata/dependency_resolution_order/somewhere/bar/__init__.py deleted file mode 100644 index 76c3313f0e..0000000000 --- a/gazelle/testdata/dependency_resolution_order/somewhere/bar/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -import os - -_ = os diff --git a/gazelle/testdata/disable_import_statements_validation/__init__.py b/gazelle/testdata/disable_import_statements_validation/__init__.py deleted file mode 100644 index 88eba74539..0000000000 --- a/gazelle/testdata/disable_import_statements_validation/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -import abcdefg - -_ = abcdefg diff --git a/gazelle/testdata/disable_import_statements_validation/test.yaml b/gazelle/testdata/disable_import_statements_validation/test.yaml deleted file mode 100644 index 36dd656b39..0000000000 --- a/gazelle/testdata/disable_import_statements_validation/test.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -expect: - exit_code: 0 diff --git a/gazelle/testdata/dont_rename_target/test.yaml b/gazelle/testdata/dont_rename_target/test.yaml deleted file mode 100644 index ed97d539c0..0000000000 --- a/gazelle/testdata/dont_rename_target/test.yaml +++ /dev/null @@ -1 +0,0 @@ ---- diff --git a/gazelle/testdata/file_name_matches_import_statement/__init__.py b/gazelle/testdata/file_name_matches_import_statement/__init__.py deleted file mode 100644 index 6b58ff30a8..0000000000 --- a/gazelle/testdata/file_name_matches_import_statement/__init__.py +++ /dev/null @@ -1 +0,0 @@ -# For test purposes only. diff --git a/gazelle/testdata/file_name_matches_import_statement/gazelle_python.yaml b/gazelle/testdata/file_name_matches_import_statement/gazelle_python.yaml deleted file mode 100644 index 63e6966941..0000000000 --- a/gazelle/testdata/file_name_matches_import_statement/gazelle_python.yaml +++ /dev/null @@ -1,4 +0,0 @@ -manifest: - modules_mapping: - rest_framework: djangorestframework - pip_deps_repository_name: gazelle_python_test diff --git a/gazelle/testdata/file_name_matches_import_statement/rest_framework.py b/gazelle/testdata/file_name_matches_import_statement/rest_framework.py deleted file mode 100644 index 9bede69c55..0000000000 --- a/gazelle/testdata/file_name_matches_import_statement/rest_framework.py +++ /dev/null @@ -1,3 +0,0 @@ -import rest_framework - -_ = rest_framework diff --git a/gazelle/testdata/file_name_matches_import_statement/test.yaml b/gazelle/testdata/file_name_matches_import_statement/test.yaml deleted file mode 100644 index ed97d539c0..0000000000 --- a/gazelle/testdata/file_name_matches_import_statement/test.yaml +++ /dev/null @@ -1 +0,0 @@ ---- diff --git a/gazelle/testdata/first_party_dependencies/one/__main__.py b/gazelle/testdata/first_party_dependencies/one/__main__.py deleted file mode 100644 index 2d241cc41e..0000000000 --- a/gazelle/testdata/first_party_dependencies/one/__main__.py +++ /dev/null @@ -1,12 +0,0 @@ -import os - -from bar import bar -from bar.baz import baz -from foo import foo - -if __name__ == "__main__": - INIT_FILENAME = "__init__.py" - dirname = os.path.dirname(os.path.abspath(__file__)) - assert bar() == os.path.join(dirname, "bar", INIT_FILENAME) - assert baz() == os.path.join(dirname, "bar", "baz", INIT_FILENAME) - assert foo() == os.path.join(dirname, "foo", INIT_FILENAME) diff --git a/gazelle/testdata/first_party_dependencies/one/bar/__init__.py b/gazelle/testdata/first_party_dependencies/one/bar/__init__.py deleted file mode 100644 index e311ff122a..0000000000 --- a/gazelle/testdata/first_party_dependencies/one/bar/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -import os - - -def bar(): - return os.path.abspath(__file__) diff --git a/gazelle/testdata/first_party_dependencies/one/bar/baz/__init__.py b/gazelle/testdata/first_party_dependencies/one/bar/baz/__init__.py deleted file mode 100644 index e74f519643..0000000000 --- a/gazelle/testdata/first_party_dependencies/one/bar/baz/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -import os - - -def baz(): - return os.path.abspath(__file__) diff --git a/gazelle/testdata/first_party_dependencies/one/foo/__init__.py b/gazelle/testdata/first_party_dependencies/one/foo/__init__.py deleted file mode 100644 index 8aeca3de74..0000000000 --- a/gazelle/testdata/first_party_dependencies/one/foo/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -import os - - -def foo(): - return os.path.abspath(__file__) diff --git a/gazelle/testdata/first_party_dependencies/test.yaml b/gazelle/testdata/first_party_dependencies/test.yaml deleted file mode 100644 index ed97d539c0..0000000000 --- a/gazelle/testdata/first_party_dependencies/test.yaml +++ /dev/null @@ -1 +0,0 @@ ---- diff --git a/gazelle/testdata/first_party_dependencies/three/__init__.py b/gazelle/testdata/first_party_dependencies/three/__init__.py deleted file mode 100644 index 41bec88fd3..0000000000 --- a/gazelle/testdata/first_party_dependencies/three/__init__.py +++ /dev/null @@ -1,10 +0,0 @@ -import os - -from bar import bar -from bar.baz import baz -from foo import foo - -_ = os -_ = bar -_ = baz -_ = foo diff --git a/gazelle/testdata/first_party_dependencies/two/__init__.py b/gazelle/testdata/first_party_dependencies/two/__init__.py deleted file mode 100644 index a0bb5c8715..0000000000 --- a/gazelle/testdata/first_party_dependencies/two/__init__.py +++ /dev/null @@ -1,6 +0,0 @@ -import os - -from foo import foo - -_ = os -_ = foo diff --git a/gazelle/testdata/first_party_file_and_directory_modules/__main__.py b/gazelle/testdata/first_party_file_and_directory_modules/__main__.py deleted file mode 100644 index acf5f10a71..0000000000 --- a/gazelle/testdata/first_party_file_and_directory_modules/__main__.py +++ /dev/null @@ -1,11 +0,0 @@ -import foo -from baz import baz as another_baz -from foo.bar import baz -from one.two import two -from package1.subpackage1.module1 import find_me - -assert not hasattr(foo, "foo") -assert baz() == "baz from foo/bar.py" -assert another_baz() == "baz from baz.py" -assert two() == "two" -assert find_me() == "found" diff --git a/gazelle/testdata/first_party_file_and_directory_modules/baz.py b/gazelle/testdata/first_party_file_and_directory_modules/baz.py deleted file mode 100644 index b161d6ab5e..0000000000 --- a/gazelle/testdata/first_party_file_and_directory_modules/baz.py +++ /dev/null @@ -1,2 +0,0 @@ -def baz(): - return "baz from baz.py" diff --git a/gazelle/testdata/first_party_file_and_directory_modules/foo.py b/gazelle/testdata/first_party_file_and_directory_modules/foo.py deleted file mode 100644 index af3cbda705..0000000000 --- a/gazelle/testdata/first_party_file_and_directory_modules/foo.py +++ /dev/null @@ -1,2 +0,0 @@ -def foo(): - print("foo") diff --git a/gazelle/testdata/first_party_file_and_directory_modules/foo/__init__.py b/gazelle/testdata/first_party_file_and_directory_modules/foo/__init__.py deleted file mode 100644 index 6b58ff30a8..0000000000 --- a/gazelle/testdata/first_party_file_and_directory_modules/foo/__init__.py +++ /dev/null @@ -1 +0,0 @@ -# For test purposes only. diff --git a/gazelle/testdata/first_party_file_and_directory_modules/foo/bar.py b/gazelle/testdata/first_party_file_and_directory_modules/foo/bar.py deleted file mode 100644 index d6524cca2a..0000000000 --- a/gazelle/testdata/first_party_file_and_directory_modules/foo/bar.py +++ /dev/null @@ -1,7 +0,0 @@ -import one.two as two - -_ = two - - -def baz(): - return "baz from foo/bar.py" diff --git a/gazelle/testdata/first_party_file_and_directory_modules/one/__init__.py b/gazelle/testdata/first_party_file_and_directory_modules/one/__init__.py deleted file mode 100644 index 6b58ff30a8..0000000000 --- a/gazelle/testdata/first_party_file_and_directory_modules/one/__init__.py +++ /dev/null @@ -1 +0,0 @@ -# For test purposes only. diff --git a/gazelle/testdata/first_party_file_and_directory_modules/one/two.py b/gazelle/testdata/first_party_file_and_directory_modules/one/two.py deleted file mode 100644 index 0020c44f2f..0000000000 --- a/gazelle/testdata/first_party_file_and_directory_modules/one/two.py +++ /dev/null @@ -1,2 +0,0 @@ -def two(): - return "two" diff --git a/gazelle/testdata/first_party_file_and_directory_modules/test.yaml b/gazelle/testdata/first_party_file_and_directory_modules/test.yaml deleted file mode 100644 index ed97d539c0..0000000000 --- a/gazelle/testdata/first_party_file_and_directory_modules/test.yaml +++ /dev/null @@ -1 +0,0 @@ ---- diff --git a/gazelle/testdata/first_party_file_and_directory_modules/undiscoverable/package1/subpackage1/__init__.py b/gazelle/testdata/first_party_file_and_directory_modules/undiscoverable/package1/subpackage1/__init__.py deleted file mode 100644 index 6b58ff30a8..0000000000 --- a/gazelle/testdata/first_party_file_and_directory_modules/undiscoverable/package1/subpackage1/__init__.py +++ /dev/null @@ -1 +0,0 @@ -# For test purposes only. diff --git a/gazelle/testdata/first_party_file_and_directory_modules/undiscoverable/package1/subpackage1/module1.py b/gazelle/testdata/first_party_file_and_directory_modules/undiscoverable/package1/subpackage1/module1.py deleted file mode 100644 index 0ff1c4256c..0000000000 --- a/gazelle/testdata/first_party_file_and_directory_modules/undiscoverable/package1/subpackage1/module1.py +++ /dev/null @@ -1,2 +0,0 @@ -def find_me(): - return "found" diff --git a/gazelle/testdata/from_imports/foo/__init__.py b/gazelle/testdata/from_imports/foo/__init__.py deleted file mode 100644 index 8c4ff6a255..0000000000 --- a/gazelle/testdata/from_imports/foo/__init__.py +++ /dev/null @@ -1 +0,0 @@ -foo = "foo" diff --git a/gazelle/testdata/from_imports/foo/bar/__init__.py b/gazelle/testdata/from_imports/foo/bar/__init__.py deleted file mode 100644 index 2e96e096cc..0000000000 --- a/gazelle/testdata/from_imports/foo/bar/__init__.py +++ /dev/null @@ -1 +0,0 @@ -bar = "bar" diff --git a/gazelle/testdata/from_imports/foo/bar/baz.py b/gazelle/testdata/from_imports/foo/bar/baz.py deleted file mode 100644 index a15f053fe4..0000000000 --- a/gazelle/testdata/from_imports/foo/bar/baz.py +++ /dev/null @@ -1 +0,0 @@ -baz = "baz" diff --git a/gazelle/testdata/from_imports/gazelle_python.yaml b/gazelle/testdata/from_imports/gazelle_python.yaml deleted file mode 100644 index 5f7922f40f..0000000000 --- a/gazelle/testdata/from_imports/gazelle_python.yaml +++ /dev/null @@ -1,5 +0,0 @@ -manifest: - modules_mapping: - boto3: rootboto3 - boto4: rootboto4 - pip_deps_repository_name: root_pip_deps diff --git a/gazelle/testdata/from_imports/import_from_init_py/__init__.py b/gazelle/testdata/from_imports/import_from_init_py/__init__.py deleted file mode 100644 index 350a327d20..0000000000 --- a/gazelle/testdata/from_imports/import_from_init_py/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -# bar is a variable inside foo/bar/__init__.py -from foo.bar import bar diff --git a/gazelle/testdata/from_imports/import_from_multiple/__init__.py b/gazelle/testdata/from_imports/import_from_multiple/__init__.py deleted file mode 100644 index 864059b428..0000000000 --- a/gazelle/testdata/from_imports/import_from_multiple/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -# Import multiple values from the same import. -from foo.bar import bar, baz diff --git a/gazelle/testdata/from_imports/import_nested_file/__init__.py b/gazelle/testdata/from_imports/import_nested_file/__init__.py deleted file mode 100644 index d5e6b2592b..0000000000 --- a/gazelle/testdata/from_imports/import_nested_file/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -# baz.py is a file at foo/bar/baz.py -from foo.bar import baz diff --git a/gazelle/testdata/from_imports/import_nested_module/__init__.py b/gazelle/testdata/from_imports/import_nested_module/__init__.py deleted file mode 100644 index 3b04f00fed..0000000000 --- a/gazelle/testdata/from_imports/import_nested_module/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -# bar is a module at foo/bar/__init__.py -from foo import bar diff --git a/gazelle/testdata/from_imports/import_nested_var/__init__.py b/gazelle/testdata/from_imports/import_nested_var/__init__.py deleted file mode 100644 index de5069d540..0000000000 --- a/gazelle/testdata/from_imports/import_nested_var/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -# baz is a variable in foo/bar/baz.py -from foo.bar.baz import baz diff --git a/gazelle/testdata/from_imports/import_top_level_var/__init__.py b/gazelle/testdata/from_imports/import_top_level_var/__init__.py deleted file mode 100644 index 532f11a889..0000000000 --- a/gazelle/testdata/from_imports/import_top_level_var/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -# foo is a variable in foo/__init__.py -from foo import foo diff --git a/gazelle/testdata/from_imports/std_module/__init__.py b/gazelle/testdata/from_imports/std_module/__init__.py deleted file mode 100644 index 7e6bc9dc02..0000000000 --- a/gazelle/testdata/from_imports/std_module/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -# Gazelle should recognize this from import -# as the standard module __future__. -from __future__ import print_function diff --git a/gazelle/testdata/from_imports/test.yaml b/gazelle/testdata/from_imports/test.yaml deleted file mode 100644 index ed97d539c0..0000000000 --- a/gazelle/testdata/from_imports/test.yaml +++ /dev/null @@ -1 +0,0 @@ ---- diff --git a/gazelle/testdata/generated_test_entrypoint/__init__.py b/gazelle/testdata/generated_test_entrypoint/__init__.py deleted file mode 100644 index 6a49193fe4..0000000000 --- a/gazelle/testdata/generated_test_entrypoint/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -from foo import foo - -_ = foo diff --git a/gazelle/testdata/generated_test_entrypoint/foo.py b/gazelle/testdata/generated_test_entrypoint/foo.py deleted file mode 100644 index cf68624419..0000000000 --- a/gazelle/testdata/generated_test_entrypoint/foo.py +++ /dev/null @@ -1,2 +0,0 @@ -def foo(): - return "foo" diff --git a/gazelle/testdata/generated_test_entrypoint/test.yaml b/gazelle/testdata/generated_test_entrypoint/test.yaml deleted file mode 100644 index ed97d539c0..0000000000 --- a/gazelle/testdata/generated_test_entrypoint/test.yaml +++ /dev/null @@ -1 +0,0 @@ ---- diff --git a/gazelle/testdata/ignored_invalid_imported_module/__init__.py b/gazelle/testdata/ignored_invalid_imported_module/__init__.py deleted file mode 100644 index 4301453aec..0000000000 --- a/gazelle/testdata/ignored_invalid_imported_module/__init__.py +++ /dev/null @@ -1,22 +0,0 @@ -# gazelle:ignore abcdefg1,abcdefg2 -# gazelle:ignore abcdefg3 - -import abcdefg1 -import abcdefg2 -import abcdefg3 -import foo - -_ = abcdefg1 -_ = abcdefg2 -_ = abcdefg3 -_ = foo - -try: - # gazelle:ignore grpc - import grpc - - grpc_available = True -except ImportError: - grpc_available = False - -_ = grpc diff --git a/gazelle/testdata/ignored_invalid_imported_module/gazelle_python.yaml b/gazelle/testdata/ignored_invalid_imported_module/gazelle_python.yaml deleted file mode 100644 index 54b3148810..0000000000 --- a/gazelle/testdata/ignored_invalid_imported_module/gazelle_python.yaml +++ /dev/null @@ -1,4 +0,0 @@ -manifest: - modules_mapping: - foo: foo - pip_deps_repository_name: gazelle_python_test diff --git a/gazelle/testdata/ignored_invalid_imported_module/test.yaml b/gazelle/testdata/ignored_invalid_imported_module/test.yaml deleted file mode 100644 index 36dd656b39..0000000000 --- a/gazelle/testdata/ignored_invalid_imported_module/test.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -expect: - exit_code: 0 diff --git a/gazelle/testdata/invalid_imported_module/__init__.py b/gazelle/testdata/invalid_imported_module/__init__.py deleted file mode 100644 index c100931cc4..0000000000 --- a/gazelle/testdata/invalid_imported_module/__init__.py +++ /dev/null @@ -1,8 +0,0 @@ -try: - import grpc - - grpc_available = True -except ImportError: - grpc_available = False - -_ = grpc diff --git a/gazelle/testdata/invalid_imported_module/test.yaml b/gazelle/testdata/invalid_imported_module/test.yaml deleted file mode 100644 index f12c36b505..0000000000 --- a/gazelle/testdata/invalid_imported_module/test.yaml +++ /dev/null @@ -1,8 +0,0 @@ ---- -expect: - exit_code: 1 - stderr: | - gazelle: ERROR: failed to validate dependencies for target "//:invalid_imported_module": "grpc" at line 2 from "__init__.py" is an invalid dependency: possible solutions: - 1. Add it as a dependency in the requirements.txt file. - 2. Instruct Gazelle to resolve to a known dependency using the gazelle:resolve directive. - 3. Ignore it with a comment '# gazelle:ignore grpc' in the Python file. diff --git a/gazelle/testdata/monorepo/coarse_grained/__init__.py b/gazelle/testdata/monorepo/coarse_grained/__init__.py deleted file mode 100644 index 2b5b044257..0000000000 --- a/gazelle/testdata/monorepo/coarse_grained/__init__.py +++ /dev/null @@ -1,12 +0,0 @@ -import os - -import boto3 -from bar import bar -from bar.baz import baz -from foo import foo - -_ = os -_ = boto3 -_ = bar -_ = baz -_ = foo diff --git a/gazelle/testdata/monorepo/coarse_grained/bar/__init__.py b/gazelle/testdata/monorepo/coarse_grained/bar/__init__.py deleted file mode 100644 index f6ec21462a..0000000000 --- a/gazelle/testdata/monorepo/coarse_grained/bar/__init__.py +++ /dev/null @@ -1,9 +0,0 @@ -import os - -import boto3 - -_ = boto3 - - -def bar(): - return os.path.abspath(__file__) diff --git a/gazelle/testdata/monorepo/coarse_grained/bar/baz/__init__.py b/gazelle/testdata/monorepo/coarse_grained/bar/baz/__init__.py deleted file mode 100644 index e74f519643..0000000000 --- a/gazelle/testdata/monorepo/coarse_grained/bar/baz/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -import os - - -def baz(): - return os.path.abspath(__file__) diff --git a/gazelle/testdata/monorepo/coarse_grained/bar/baz/first_excluded.py b/gazelle/testdata/monorepo/coarse_grained/bar/baz/first_excluded.py deleted file mode 100644 index 6b58ff30a8..0000000000 --- a/gazelle/testdata/monorepo/coarse_grained/bar/baz/first_excluded.py +++ /dev/null @@ -1 +0,0 @@ -# For test purposes only. diff --git a/gazelle/testdata/monorepo/coarse_grained/bar/baz/hue.py b/gazelle/testdata/monorepo/coarse_grained/bar/baz/hue.py deleted file mode 100644 index 6b58ff30a8..0000000000 --- a/gazelle/testdata/monorepo/coarse_grained/bar/baz/hue.py +++ /dev/null @@ -1 +0,0 @@ -# For test purposes only. diff --git a/gazelle/testdata/monorepo/coarse_grained/bar/baz/second_excluded.py b/gazelle/testdata/monorepo/coarse_grained/bar/baz/second_excluded.py deleted file mode 100644 index 6b58ff30a8..0000000000 --- a/gazelle/testdata/monorepo/coarse_grained/bar/baz/second_excluded.py +++ /dev/null @@ -1 +0,0 @@ -# For test purposes only. diff --git a/gazelle/testdata/monorepo/coarse_grained/foo/__init__.py b/gazelle/testdata/monorepo/coarse_grained/foo/__init__.py deleted file mode 100644 index 8aeca3de74..0000000000 --- a/gazelle/testdata/monorepo/coarse_grained/foo/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -import os - - -def foo(): - return os.path.abspath(__file__) diff --git a/gazelle/testdata/monorepo/gazelle_python.yaml b/gazelle/testdata/monorepo/gazelle_python.yaml deleted file mode 100644 index 5f7922f40f..0000000000 --- a/gazelle/testdata/monorepo/gazelle_python.yaml +++ /dev/null @@ -1,5 +0,0 @@ -manifest: - modules_mapping: - boto3: rootboto3 - boto4: rootboto4 - pip_deps_repository_name: root_pip_deps diff --git a/gazelle/testdata/monorepo/one/__main__.py b/gazelle/testdata/monorepo/one/__main__.py deleted file mode 100644 index f08f5e8009..0000000000 --- a/gazelle/testdata/monorepo/one/__main__.py +++ /dev/null @@ -1,15 +0,0 @@ -import os - -import boto3 -from bar import bar -from bar.baz import baz -from foo import foo - -_ = boto3 - -if __name__ == "__main__": - INIT_FILENAME = "__init__.py" - dirname = os.path.dirname(os.path.abspath(__file__)) - assert bar() == os.path.join(dirname, "bar", INIT_FILENAME) - assert baz() == os.path.join(dirname, "bar", "baz", INIT_FILENAME) - assert foo() == os.path.join(dirname, "foo", INIT_FILENAME) diff --git a/gazelle/testdata/monorepo/one/bar/__init__.py b/gazelle/testdata/monorepo/one/bar/__init__.py deleted file mode 100644 index f6ec21462a..0000000000 --- a/gazelle/testdata/monorepo/one/bar/__init__.py +++ /dev/null @@ -1,9 +0,0 @@ -import os - -import boto3 - -_ = boto3 - - -def bar(): - return os.path.abspath(__file__) diff --git a/gazelle/testdata/monorepo/one/bar/baz/__init__.py b/gazelle/testdata/monorepo/one/bar/baz/__init__.py deleted file mode 100644 index e74f519643..0000000000 --- a/gazelle/testdata/monorepo/one/bar/baz/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -import os - - -def baz(): - return os.path.abspath(__file__) diff --git a/gazelle/testdata/monorepo/one/foo/__init__.py b/gazelle/testdata/monorepo/one/foo/__init__.py deleted file mode 100644 index 8aeca3de74..0000000000 --- a/gazelle/testdata/monorepo/one/foo/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -import os - - -def foo(): - return os.path.abspath(__file__) diff --git a/gazelle/testdata/monorepo/one/gazelle_python.yaml b/gazelle/testdata/monorepo/one/gazelle_python.yaml deleted file mode 100644 index 67c53451b4..0000000000 --- a/gazelle/testdata/monorepo/one/gazelle_python.yaml +++ /dev/null @@ -1,4 +0,0 @@ -manifest: - modules_mapping: - boto3: oneboto3 - pip_deps_repository_name: one_pip_deps diff --git a/gazelle/testdata/monorepo/test.yaml b/gazelle/testdata/monorepo/test.yaml deleted file mode 100644 index ed97d539c0..0000000000 --- a/gazelle/testdata/monorepo/test.yaml +++ /dev/null @@ -1 +0,0 @@ ---- diff --git a/gazelle/testdata/monorepo/three/__init__.py b/gazelle/testdata/monorepo/three/__init__.py deleted file mode 100644 index 6f12bd8033..0000000000 --- a/gazelle/testdata/monorepo/three/__init__.py +++ /dev/null @@ -1,16 +0,0 @@ -import os - -import bar.baz.hue as hue -import boto3 -import boto4 -from bar import bar -from bar.baz import baz -from foo import foo - -_ = os -_ = boto3 -_ = boto4 -_ = bar -_ = baz -_ = foo -_ = hue diff --git a/gazelle/testdata/monorepo/three/gazelle_python.yaml b/gazelle/testdata/monorepo/three/gazelle_python.yaml deleted file mode 100644 index d46a88f444..0000000000 --- a/gazelle/testdata/monorepo/three/gazelle_python.yaml +++ /dev/null @@ -1,6 +0,0 @@ -manifest: - modules_mapping: - boto3: threeboto3 - pip_repository: - name: three_pip_deps - incremental: true diff --git a/gazelle/testdata/monorepo/two/__init__.py b/gazelle/testdata/monorepo/two/__init__.py deleted file mode 100644 index fb3e877fe5..0000000000 --- a/gazelle/testdata/monorepo/two/__init__.py +++ /dev/null @@ -1,8 +0,0 @@ -import os - -import boto3 -from foo import foo - -_ = os -_ = boto3 -_ = foo diff --git a/gazelle/testdata/monorepo/two/gazelle_python.yaml b/gazelle/testdata/monorepo/two/gazelle_python.yaml deleted file mode 100644 index 3bc5939e58..0000000000 --- a/gazelle/testdata/monorepo/two/gazelle_python.yaml +++ /dev/null @@ -1,4 +0,0 @@ -manifest: - modules_mapping: - boto3: twoboto3 - pip_deps_repository_name: two_pip_deps diff --git a/gazelle/testdata/monorepo/wont_generate/__main__.py b/gazelle/testdata/monorepo/wont_generate/__main__.py deleted file mode 100644 index 2d241cc41e..0000000000 --- a/gazelle/testdata/monorepo/wont_generate/__main__.py +++ /dev/null @@ -1,12 +0,0 @@ -import os - -from bar import bar -from bar.baz import baz -from foo import foo - -if __name__ == "__main__": - INIT_FILENAME = "__init__.py" - dirname = os.path.dirname(os.path.abspath(__file__)) - assert bar() == os.path.join(dirname, "bar", INIT_FILENAME) - assert baz() == os.path.join(dirname, "bar", "baz", INIT_FILENAME) - assert foo() == os.path.join(dirname, "foo", INIT_FILENAME) diff --git a/gazelle/testdata/monorepo/wont_generate/bar/__init__.py b/gazelle/testdata/monorepo/wont_generate/bar/__init__.py deleted file mode 100644 index e311ff122a..0000000000 --- a/gazelle/testdata/monorepo/wont_generate/bar/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -import os - - -def bar(): - return os.path.abspath(__file__) diff --git a/gazelle/testdata/monorepo/wont_generate/bar/baz/__init__.py b/gazelle/testdata/monorepo/wont_generate/bar/baz/__init__.py deleted file mode 100644 index e74f519643..0000000000 --- a/gazelle/testdata/monorepo/wont_generate/bar/baz/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -import os - - -def baz(): - return os.path.abspath(__file__) diff --git a/gazelle/testdata/monorepo/wont_generate/foo/__init__.py b/gazelle/testdata/monorepo/wont_generate/foo/__init__.py deleted file mode 100644 index 8aeca3de74..0000000000 --- a/gazelle/testdata/monorepo/wont_generate/foo/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -import os - - -def foo(): - return os.path.abspath(__file__) diff --git a/gazelle/testdata/naming_convention/__init__.py b/gazelle/testdata/naming_convention/__init__.py deleted file mode 100644 index 6b58ff30a8..0000000000 --- a/gazelle/testdata/naming_convention/__init__.py +++ /dev/null @@ -1 +0,0 @@ -# For test purposes only. diff --git a/gazelle/testdata/naming_convention/__main__.py b/gazelle/testdata/naming_convention/__main__.py deleted file mode 100644 index 6b58ff30a8..0000000000 --- a/gazelle/testdata/naming_convention/__main__.py +++ /dev/null @@ -1 +0,0 @@ -# For test purposes only. diff --git a/gazelle/testdata/naming_convention/__test__.py b/gazelle/testdata/naming_convention/__test__.py deleted file mode 100644 index 6b58ff30a8..0000000000 --- a/gazelle/testdata/naming_convention/__test__.py +++ /dev/null @@ -1 +0,0 @@ -# For test purposes only. diff --git a/gazelle/testdata/naming_convention/dont_rename/__init__.py b/gazelle/testdata/naming_convention/dont_rename/__init__.py deleted file mode 100644 index 6b58ff30a8..0000000000 --- a/gazelle/testdata/naming_convention/dont_rename/__init__.py +++ /dev/null @@ -1 +0,0 @@ -# For test purposes only. diff --git a/gazelle/testdata/naming_convention/dont_rename/__main__.py b/gazelle/testdata/naming_convention/dont_rename/__main__.py deleted file mode 100644 index 6b58ff30a8..0000000000 --- a/gazelle/testdata/naming_convention/dont_rename/__main__.py +++ /dev/null @@ -1 +0,0 @@ -# For test purposes only. diff --git a/gazelle/testdata/naming_convention/dont_rename/__test__.py b/gazelle/testdata/naming_convention/dont_rename/__test__.py deleted file mode 100644 index 6b58ff30a8..0000000000 --- a/gazelle/testdata/naming_convention/dont_rename/__test__.py +++ /dev/null @@ -1 +0,0 @@ -# For test purposes only. diff --git a/gazelle/testdata/naming_convention/resolve_conflict/__init__.py b/gazelle/testdata/naming_convention/resolve_conflict/__init__.py deleted file mode 100644 index 6b58ff30a8..0000000000 --- a/gazelle/testdata/naming_convention/resolve_conflict/__init__.py +++ /dev/null @@ -1 +0,0 @@ -# For test purposes only. diff --git a/gazelle/testdata/naming_convention/resolve_conflict/__main__.py b/gazelle/testdata/naming_convention/resolve_conflict/__main__.py deleted file mode 100644 index 6b58ff30a8..0000000000 --- a/gazelle/testdata/naming_convention/resolve_conflict/__main__.py +++ /dev/null @@ -1 +0,0 @@ -# For test purposes only. diff --git a/gazelle/testdata/naming_convention/resolve_conflict/__test__.py b/gazelle/testdata/naming_convention/resolve_conflict/__test__.py deleted file mode 100644 index 6b58ff30a8..0000000000 --- a/gazelle/testdata/naming_convention/resolve_conflict/__test__.py +++ /dev/null @@ -1 +0,0 @@ -# For test purposes only. diff --git a/gazelle/testdata/naming_convention/test.yaml b/gazelle/testdata/naming_convention/test.yaml deleted file mode 100644 index ed97d539c0..0000000000 --- a/gazelle/testdata/naming_convention/test.yaml +++ /dev/null @@ -1 +0,0 @@ ---- diff --git a/gazelle/testdata/naming_convention_binary_fail/__main__.py b/gazelle/testdata/naming_convention_binary_fail/__main__.py deleted file mode 100644 index 6b58ff30a8..0000000000 --- a/gazelle/testdata/naming_convention_binary_fail/__main__.py +++ /dev/null @@ -1 +0,0 @@ -# For test purposes only. diff --git a/gazelle/testdata/naming_convention_binary_fail/test.yaml b/gazelle/testdata/naming_convention_binary_fail/test.yaml deleted file mode 100644 index bc30dd0858..0000000000 --- a/gazelle/testdata/naming_convention_binary_fail/test.yaml +++ /dev/null @@ -1,7 +0,0 @@ ---- -expect: - exit_code: 1 - stderr: > - gazelle: ERROR: failed to generate target "//:naming_convention_binary_fail_bin" of kind "py_binary": - a target of kind "go_binary" with the same name already exists. - Use the '# gazelle:python_binary_naming_convention' directive to change the naming convention. diff --git a/gazelle/testdata/naming_convention_library_fail/__init__.py b/gazelle/testdata/naming_convention_library_fail/__init__.py deleted file mode 100644 index 6b58ff30a8..0000000000 --- a/gazelle/testdata/naming_convention_library_fail/__init__.py +++ /dev/null @@ -1 +0,0 @@ -# For test purposes only. diff --git a/gazelle/testdata/naming_convention_library_fail/test.yaml b/gazelle/testdata/naming_convention_library_fail/test.yaml deleted file mode 100644 index 3743c324df..0000000000 --- a/gazelle/testdata/naming_convention_library_fail/test.yaml +++ /dev/null @@ -1,7 +0,0 @@ ---- -expect: - exit_code: 1 - stderr: > - gazelle: ERROR: failed to generate target "//:naming_convention_library_fail" of kind "py_library": - a target of kind "go_library" with the same name already exists. - Use the '# gazelle:python_library_naming_convention' directive to change the naming convention. diff --git a/gazelle/testdata/naming_convention_test_fail/__test__.py b/gazelle/testdata/naming_convention_test_fail/__test__.py deleted file mode 100644 index 6b58ff30a8..0000000000 --- a/gazelle/testdata/naming_convention_test_fail/__test__.py +++ /dev/null @@ -1 +0,0 @@ -# For test purposes only. diff --git a/gazelle/testdata/naming_convention_test_fail/test.yaml b/gazelle/testdata/naming_convention_test_fail/test.yaml deleted file mode 100644 index fc4e24e830..0000000000 --- a/gazelle/testdata/naming_convention_test_fail/test.yaml +++ /dev/null @@ -1,7 +0,0 @@ ---- -expect: - exit_code: 1 - stderr: > - gazelle: ERROR: failed to generate target "//:naming_convention_test_fail_test" of kind "py_test": - a target of kind "go_test" with the same name already exists. - Use the '# gazelle:python_test_naming_convention' directive to change the naming convention. diff --git a/gazelle/testdata/python_ignore_dependencies_directive/__init__.py b/gazelle/testdata/python_ignore_dependencies_directive/__init__.py deleted file mode 100644 index 79935a70c4..0000000000 --- a/gazelle/testdata/python_ignore_dependencies_directive/__init__.py +++ /dev/null @@ -1,11 +0,0 @@ -import bar -import boto3 -import foo -import foo.bar.baz -from baz import baz as bazfn - -_ = foo -_ = bar -_ = bazfn -_ = baz -_ = boto3 diff --git a/gazelle/testdata/python_ignore_dependencies_directive/gazelle_python.yaml b/gazelle/testdata/python_ignore_dependencies_directive/gazelle_python.yaml deleted file mode 100644 index 7288b798e1..0000000000 --- a/gazelle/testdata/python_ignore_dependencies_directive/gazelle_python.yaml +++ /dev/null @@ -1,4 +0,0 @@ -manifest: - modules_mapping: - boto3: boto3 - pip_deps_repository_name: gazelle_python_test diff --git a/gazelle/testdata/python_ignore_dependencies_directive/test.yaml b/gazelle/testdata/python_ignore_dependencies_directive/test.yaml deleted file mode 100644 index ed97d539c0..0000000000 --- a/gazelle/testdata/python_ignore_dependencies_directive/test.yaml +++ /dev/null @@ -1 +0,0 @@ ---- diff --git a/gazelle/testdata/python_ignore_files_directive/__init__.py b/gazelle/testdata/python_ignore_files_directive/__init__.py deleted file mode 100644 index 6b58ff30a8..0000000000 --- a/gazelle/testdata/python_ignore_files_directive/__init__.py +++ /dev/null @@ -1 +0,0 @@ -# For test purposes only. diff --git a/gazelle/testdata/python_ignore_files_directive/bar/baz.py b/gazelle/testdata/python_ignore_files_directive/bar/baz.py deleted file mode 100644 index 6b58ff30a8..0000000000 --- a/gazelle/testdata/python_ignore_files_directive/bar/baz.py +++ /dev/null @@ -1 +0,0 @@ -# For test purposes only. diff --git a/gazelle/testdata/python_ignore_files_directive/bar/some_other.py b/gazelle/testdata/python_ignore_files_directive/bar/some_other.py deleted file mode 100644 index 6b58ff30a8..0000000000 --- a/gazelle/testdata/python_ignore_files_directive/bar/some_other.py +++ /dev/null @@ -1 +0,0 @@ -# For test purposes only. diff --git a/gazelle/testdata/python_ignore_files_directive/foo/baz.py b/gazelle/testdata/python_ignore_files_directive/foo/baz.py deleted file mode 100644 index 6b58ff30a8..0000000000 --- a/gazelle/testdata/python_ignore_files_directive/foo/baz.py +++ /dev/null @@ -1 +0,0 @@ -# For test purposes only. diff --git a/gazelle/testdata/python_ignore_files_directive/setup.py b/gazelle/testdata/python_ignore_files_directive/setup.py deleted file mode 100644 index 6b58ff30a8..0000000000 --- a/gazelle/testdata/python_ignore_files_directive/setup.py +++ /dev/null @@ -1 +0,0 @@ -# For test purposes only. diff --git a/gazelle/testdata/python_ignore_files_directive/some_other.py b/gazelle/testdata/python_ignore_files_directive/some_other.py deleted file mode 100644 index 6b58ff30a8..0000000000 --- a/gazelle/testdata/python_ignore_files_directive/some_other.py +++ /dev/null @@ -1 +0,0 @@ -# For test purposes only. diff --git a/gazelle/testdata/python_ignore_files_directive/test.yaml b/gazelle/testdata/python_ignore_files_directive/test.yaml deleted file mode 100644 index ed97d539c0..0000000000 --- a/gazelle/testdata/python_ignore_files_directive/test.yaml +++ /dev/null @@ -1 +0,0 @@ ---- diff --git a/gazelle/testdata/python_target_with_test_in_name/BUILD.out b/gazelle/testdata/python_target_with_test_in_name/BUILD.out deleted file mode 100644 index bdde605c09..0000000000 --- a/gazelle/testdata/python_target_with_test_in_name/BUILD.out +++ /dev/null @@ -1,12 +0,0 @@ -load("@rules_python//python:defs.bzl", "py_library") - -py_library( - name = "python_target_with_test_in_name", - srcs = [ - "__init__.py", - "not_a_real_test.py", - "test_not_a_real.py", - ], - visibility = ["//:__subpackages__"], - deps = ["@gazelle_python_test//pypi__boto3"], -) diff --git a/gazelle/testdata/python_target_with_test_in_name/__init__.py b/gazelle/testdata/python_target_with_test_in_name/__init__.py deleted file mode 100644 index 6b58ff30a8..0000000000 --- a/gazelle/testdata/python_target_with_test_in_name/__init__.py +++ /dev/null @@ -1 +0,0 @@ -# For test purposes only. diff --git a/gazelle/testdata/python_target_with_test_in_name/gazelle_python.yaml b/gazelle/testdata/python_target_with_test_in_name/gazelle_python.yaml deleted file mode 100644 index 7288b798e1..0000000000 --- a/gazelle/testdata/python_target_with_test_in_name/gazelle_python.yaml +++ /dev/null @@ -1,4 +0,0 @@ -manifest: - modules_mapping: - boto3: boto3 - pip_deps_repository_name: gazelle_python_test diff --git a/gazelle/testdata/python_target_with_test_in_name/not_a_real_test.py b/gazelle/testdata/python_target_with_test_in_name/not_a_real_test.py deleted file mode 100644 index 57c019daab..0000000000 --- a/gazelle/testdata/python_target_with_test_in_name/not_a_real_test.py +++ /dev/null @@ -1,3 +0,0 @@ -import boto3 - -_ = boto3 diff --git a/gazelle/testdata/python_target_with_test_in_name/test.yaml b/gazelle/testdata/python_target_with_test_in_name/test.yaml deleted file mode 100644 index ed97d539c0..0000000000 --- a/gazelle/testdata/python_target_with_test_in_name/test.yaml +++ /dev/null @@ -1 +0,0 @@ ---- diff --git a/gazelle/testdata/python_target_with_test_in_name/test_not_a_real.py b/gazelle/testdata/python_target_with_test_in_name/test_not_a_real.py deleted file mode 100644 index 6b58ff30a8..0000000000 --- a/gazelle/testdata/python_target_with_test_in_name/test_not_a_real.py +++ /dev/null @@ -1 +0,0 @@ -# For test purposes only. diff --git a/gazelle/testdata/relative_imports/__main__.py b/gazelle/testdata/relative_imports/__main__.py deleted file mode 100644 index 4fb887a803..0000000000 --- a/gazelle/testdata/relative_imports/__main__.py +++ /dev/null @@ -1,5 +0,0 @@ -from package1.module1 import function1 -from package2.module3 import function3 - -print(function1()) -print(function3()) diff --git a/gazelle/testdata/relative_imports/package1/module1.py b/gazelle/testdata/relative_imports/package1/module1.py deleted file mode 100644 index 69cdde2633..0000000000 --- a/gazelle/testdata/relative_imports/package1/module1.py +++ /dev/null @@ -1,5 +0,0 @@ -from .module2 import function2 - - -def function1(): - return "function1 " + function2() diff --git a/gazelle/testdata/relative_imports/package1/module2.py b/gazelle/testdata/relative_imports/package1/module2.py deleted file mode 100644 index 1e731b4ec1..0000000000 --- a/gazelle/testdata/relative_imports/package1/module2.py +++ /dev/null @@ -1,2 +0,0 @@ -def function2(): - return "function2" diff --git a/gazelle/testdata/relative_imports/package2/__init__.py b/gazelle/testdata/relative_imports/package2/__init__.py deleted file mode 100644 index fd0384ba7e..0000000000 --- a/gazelle/testdata/relative_imports/package2/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -class Class1: - def method1(self): - return "method1" diff --git a/gazelle/testdata/relative_imports/package2/module3.py b/gazelle/testdata/relative_imports/package2/module3.py deleted file mode 100644 index a5102dd8bd..0000000000 --- a/gazelle/testdata/relative_imports/package2/module3.py +++ /dev/null @@ -1,7 +0,0 @@ -from . import Class1 -from .subpackage1.module5 import function5 - - -def function3(): - c1 = Class1() - return "function3 " + c1.method1() + " " + function5() diff --git a/gazelle/testdata/relative_imports/package2/module4.py b/gazelle/testdata/relative_imports/package2/module4.py deleted file mode 100644 index 6e69699985..0000000000 --- a/gazelle/testdata/relative_imports/package2/module4.py +++ /dev/null @@ -1,2 +0,0 @@ -def function4(): - return "function4" diff --git a/gazelle/testdata/relative_imports/package2/subpackage1/module5.py b/gazelle/testdata/relative_imports/package2/subpackage1/module5.py deleted file mode 100644 index ac1f7257df..0000000000 --- a/gazelle/testdata/relative_imports/package2/subpackage1/module5.py +++ /dev/null @@ -1,5 +0,0 @@ -from ..module4 import function4 - - -def function5(): - return "function5 " + function4() diff --git a/gazelle/testdata/relative_imports/test.yaml b/gazelle/testdata/relative_imports/test.yaml deleted file mode 100644 index ed97d539c0..0000000000 --- a/gazelle/testdata/relative_imports/test.yaml +++ /dev/null @@ -1 +0,0 @@ ---- diff --git a/gazelle/testdata/simple_binary/__main__.py b/gazelle/testdata/simple_binary/__main__.py deleted file mode 100644 index 6b58ff30a8..0000000000 --- a/gazelle/testdata/simple_binary/__main__.py +++ /dev/null @@ -1 +0,0 @@ -# For test purposes only. diff --git a/gazelle/testdata/simple_binary/test.yaml b/gazelle/testdata/simple_binary/test.yaml deleted file mode 100644 index ed97d539c0..0000000000 --- a/gazelle/testdata/simple_binary/test.yaml +++ /dev/null @@ -1 +0,0 @@ ---- diff --git a/gazelle/testdata/simple_binary_with_library/__init__.py b/gazelle/testdata/simple_binary_with_library/__init__.py deleted file mode 100644 index 6b58ff30a8..0000000000 --- a/gazelle/testdata/simple_binary_with_library/__init__.py +++ /dev/null @@ -1 +0,0 @@ -# For test purposes only. diff --git a/gazelle/testdata/simple_binary_with_library/__main__.py b/gazelle/testdata/simple_binary_with_library/__main__.py deleted file mode 100644 index 6b58ff30a8..0000000000 --- a/gazelle/testdata/simple_binary_with_library/__main__.py +++ /dev/null @@ -1 +0,0 @@ -# For test purposes only. diff --git a/gazelle/testdata/simple_binary_with_library/bar.py b/gazelle/testdata/simple_binary_with_library/bar.py deleted file mode 100644 index 6b58ff30a8..0000000000 --- a/gazelle/testdata/simple_binary_with_library/bar.py +++ /dev/null @@ -1 +0,0 @@ -# For test purposes only. diff --git a/gazelle/testdata/simple_binary_with_library/foo.py b/gazelle/testdata/simple_binary_with_library/foo.py deleted file mode 100644 index 6b58ff30a8..0000000000 --- a/gazelle/testdata/simple_binary_with_library/foo.py +++ /dev/null @@ -1 +0,0 @@ -# For test purposes only. diff --git a/gazelle/testdata/simple_binary_with_library/test.yaml b/gazelle/testdata/simple_binary_with_library/test.yaml deleted file mode 100644 index ed97d539c0..0000000000 --- a/gazelle/testdata/simple_binary_with_library/test.yaml +++ /dev/null @@ -1 +0,0 @@ ---- diff --git a/gazelle/testdata/simple_library/__init__.py b/gazelle/testdata/simple_library/__init__.py deleted file mode 100644 index 6b58ff30a8..0000000000 --- a/gazelle/testdata/simple_library/__init__.py +++ /dev/null @@ -1 +0,0 @@ -# For test purposes only. diff --git a/gazelle/testdata/simple_library/test.yaml b/gazelle/testdata/simple_library/test.yaml deleted file mode 100644 index ed97d539c0..0000000000 --- a/gazelle/testdata/simple_library/test.yaml +++ /dev/null @@ -1 +0,0 @@ ---- diff --git a/gazelle/testdata/simple_library_without_init/foo/foo.py b/gazelle/testdata/simple_library_without_init/foo/foo.py deleted file mode 100644 index 6b58ff30a8..0000000000 --- a/gazelle/testdata/simple_library_without_init/foo/foo.py +++ /dev/null @@ -1 +0,0 @@ -# For test purposes only. diff --git a/gazelle/testdata/simple_library_without_init/test.yaml b/gazelle/testdata/simple_library_without_init/test.yaml deleted file mode 100644 index ed97d539c0..0000000000 --- a/gazelle/testdata/simple_library_without_init/test.yaml +++ /dev/null @@ -1 +0,0 @@ ---- diff --git a/gazelle/testdata/simple_test/__init__.py b/gazelle/testdata/simple_test/__init__.py deleted file mode 100644 index 6a49193fe4..0000000000 --- a/gazelle/testdata/simple_test/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -from foo import foo - -_ = foo diff --git a/gazelle/testdata/simple_test/__test__.py b/gazelle/testdata/simple_test/__test__.py deleted file mode 100644 index d6085a41b4..0000000000 --- a/gazelle/testdata/simple_test/__test__.py +++ /dev/null @@ -1,12 +0,0 @@ -import unittest - -from __init__ import foo - - -class FooTest(unittest.TestCase): - def test_foo(self): - self.assertEqual("foo", foo()) - - -if __name__ == "__main__": - unittest.main() diff --git a/gazelle/testdata/simple_test/foo.py b/gazelle/testdata/simple_test/foo.py deleted file mode 100644 index cf68624419..0000000000 --- a/gazelle/testdata/simple_test/foo.py +++ /dev/null @@ -1,2 +0,0 @@ -def foo(): - return "foo" diff --git a/gazelle/testdata/simple_test/test.yaml b/gazelle/testdata/simple_test/test.yaml deleted file mode 100644 index 36dd656b39..0000000000 --- a/gazelle/testdata/simple_test/test.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -expect: - exit_code: 0 diff --git a/gazelle/testdata/subdir_sources/__main__.py b/gazelle/testdata/subdir_sources/__main__.py deleted file mode 100644 index 3cc8834990..0000000000 --- a/gazelle/testdata/subdir_sources/__main__.py +++ /dev/null @@ -1,7 +0,0 @@ -import foo.bar.bar as bar -import foo.baz.baz as baz -import one.two.three as three - -_ = bar -_ = baz -_ = three diff --git a/gazelle/testdata/subdir_sources/foo/__init__.py b/gazelle/testdata/subdir_sources/foo/__init__.py deleted file mode 100644 index 6b58ff30a8..0000000000 --- a/gazelle/testdata/subdir_sources/foo/__init__.py +++ /dev/null @@ -1 +0,0 @@ -# For test purposes only. diff --git a/gazelle/testdata/subdir_sources/foo/bar/bar.py b/gazelle/testdata/subdir_sources/foo/bar/bar.py deleted file mode 100644 index 6b58ff30a8..0000000000 --- a/gazelle/testdata/subdir_sources/foo/bar/bar.py +++ /dev/null @@ -1 +0,0 @@ -# For test purposes only. diff --git a/gazelle/testdata/subdir_sources/foo/baz/baz.py b/gazelle/testdata/subdir_sources/foo/baz/baz.py deleted file mode 100644 index 6b58ff30a8..0000000000 --- a/gazelle/testdata/subdir_sources/foo/baz/baz.py +++ /dev/null @@ -1 +0,0 @@ -# For test purposes only. diff --git a/gazelle/testdata/subdir_sources/foo/foo.py b/gazelle/testdata/subdir_sources/foo/foo.py deleted file mode 100644 index 6752f22f90..0000000000 --- a/gazelle/testdata/subdir_sources/foo/foo.py +++ /dev/null @@ -1,3 +0,0 @@ -import foo.bar.bar as bar - -_ = bar diff --git a/gazelle/testdata/subdir_sources/foo/has_build/python/my_module.py b/gazelle/testdata/subdir_sources/foo/has_build/python/my_module.py deleted file mode 100644 index 6b58ff30a8..0000000000 --- a/gazelle/testdata/subdir_sources/foo/has_build/python/my_module.py +++ /dev/null @@ -1 +0,0 @@ -# For test purposes only. diff --git a/gazelle/testdata/subdir_sources/foo/has_build_bazel/BUILD.bazel.out b/gazelle/testdata/subdir_sources/foo/has_build_bazel/BUILD.bazel.out deleted file mode 100644 index 79bd70a258..0000000000 --- a/gazelle/testdata/subdir_sources/foo/has_build_bazel/BUILD.bazel.out +++ /dev/null @@ -1,8 +0,0 @@ -load("@rules_python//python:defs.bzl", "py_library") - -py_library( - name = "has_build_bazel", - srcs = ["python/my_module.py"], - imports = ["../.."], - visibility = ["//:__subpackages__"], -) diff --git a/gazelle/testdata/subdir_sources/foo/has_build_bazel/python/my_module.py b/gazelle/testdata/subdir_sources/foo/has_build_bazel/python/my_module.py deleted file mode 100644 index 6b58ff30a8..0000000000 --- a/gazelle/testdata/subdir_sources/foo/has_build_bazel/python/my_module.py +++ /dev/null @@ -1 +0,0 @@ -# For test purposes only. diff --git a/gazelle/testdata/subdir_sources/foo/has_init/__init__.py b/gazelle/testdata/subdir_sources/foo/has_init/__init__.py deleted file mode 100644 index 6b58ff30a8..0000000000 --- a/gazelle/testdata/subdir_sources/foo/has_init/__init__.py +++ /dev/null @@ -1 +0,0 @@ -# For test purposes only. diff --git a/gazelle/testdata/subdir_sources/foo/has_init/python/my_module.py b/gazelle/testdata/subdir_sources/foo/has_init/python/my_module.py deleted file mode 100644 index 6b58ff30a8..0000000000 --- a/gazelle/testdata/subdir_sources/foo/has_init/python/my_module.py +++ /dev/null @@ -1 +0,0 @@ -# For test purposes only. diff --git a/gazelle/testdata/subdir_sources/foo/has_main/__main__.py b/gazelle/testdata/subdir_sources/foo/has_main/__main__.py deleted file mode 100644 index 6b58ff30a8..0000000000 --- a/gazelle/testdata/subdir_sources/foo/has_main/__main__.py +++ /dev/null @@ -1 +0,0 @@ -# For test purposes only. diff --git a/gazelle/testdata/subdir_sources/foo/has_main/python/my_module.py b/gazelle/testdata/subdir_sources/foo/has_main/python/my_module.py deleted file mode 100644 index 6b58ff30a8..0000000000 --- a/gazelle/testdata/subdir_sources/foo/has_main/python/my_module.py +++ /dev/null @@ -1 +0,0 @@ -# For test purposes only. diff --git a/gazelle/testdata/subdir_sources/foo/has_test/__test__.py b/gazelle/testdata/subdir_sources/foo/has_test/__test__.py deleted file mode 100644 index 6b58ff30a8..0000000000 --- a/gazelle/testdata/subdir_sources/foo/has_test/__test__.py +++ /dev/null @@ -1 +0,0 @@ -# For test purposes only. diff --git a/gazelle/testdata/subdir_sources/foo/has_test/python/my_module.py b/gazelle/testdata/subdir_sources/foo/has_test/python/my_module.py deleted file mode 100644 index 6b58ff30a8..0000000000 --- a/gazelle/testdata/subdir_sources/foo/has_test/python/my_module.py +++ /dev/null @@ -1 +0,0 @@ -# For test purposes only. diff --git a/gazelle/testdata/subdir_sources/one/__init__.py b/gazelle/testdata/subdir_sources/one/__init__.py deleted file mode 100644 index 6b58ff30a8..0000000000 --- a/gazelle/testdata/subdir_sources/one/__init__.py +++ /dev/null @@ -1 +0,0 @@ -# For test purposes only. diff --git a/gazelle/testdata/subdir_sources/one/two/__init__.py b/gazelle/testdata/subdir_sources/one/two/__init__.py deleted file mode 100644 index f6c7d2a988..0000000000 --- a/gazelle/testdata/subdir_sources/one/two/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -import foo.baz.baz as baz - -_ = baz diff --git a/gazelle/testdata/subdir_sources/one/two/three.py b/gazelle/testdata/subdir_sources/one/two/three.py deleted file mode 100644 index 6b58ff30a8..0000000000 --- a/gazelle/testdata/subdir_sources/one/two/three.py +++ /dev/null @@ -1 +0,0 @@ -# For test purposes only. diff --git a/gazelle/testdata/subdir_sources/test.yaml b/gazelle/testdata/subdir_sources/test.yaml deleted file mode 100644 index ed97d539c0..0000000000 --- a/gazelle/testdata/subdir_sources/test.yaml +++ /dev/null @@ -1 +0,0 @@ ---- diff --git a/gazelle/testdata/with_nested_import_statements/__init__.py b/gazelle/testdata/with_nested_import_statements/__init__.py deleted file mode 100644 index 6871953f88..0000000000 --- a/gazelle/testdata/with_nested_import_statements/__init__.py +++ /dev/null @@ -1,11 +0,0 @@ -import os -import sys - -_ = os -_ = sys - - -def main(): - import boto3 - - _ = boto3 diff --git a/gazelle/testdata/with_nested_import_statements/gazelle_python.yaml b/gazelle/testdata/with_nested_import_statements/gazelle_python.yaml deleted file mode 100644 index 7288b798e1..0000000000 --- a/gazelle/testdata/with_nested_import_statements/gazelle_python.yaml +++ /dev/null @@ -1,4 +0,0 @@ -manifest: - modules_mapping: - boto3: boto3 - pip_deps_repository_name: gazelle_python_test diff --git a/gazelle/testdata/with_nested_import_statements/test.yaml b/gazelle/testdata/with_nested_import_statements/test.yaml deleted file mode 100644 index ed97d539c0..0000000000 --- a/gazelle/testdata/with_nested_import_statements/test.yaml +++ /dev/null @@ -1 +0,0 @@ ---- diff --git a/gazelle/testdata/with_std_requirements/__init__.py b/gazelle/testdata/with_std_requirements/__init__.py deleted file mode 100644 index 154689a5f4..0000000000 --- a/gazelle/testdata/with_std_requirements/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -import os -import sys - -_ = os -_ = sys diff --git a/gazelle/testdata/with_std_requirements/test.yaml b/gazelle/testdata/with_std_requirements/test.yaml deleted file mode 100644 index ed97d539c0..0000000000 --- a/gazelle/testdata/with_std_requirements/test.yaml +++ /dev/null @@ -1 +0,0 @@ ---- diff --git a/gazelle/testdata/with_third_party_requirements/README.md b/gazelle/testdata/with_third_party_requirements/README.md deleted file mode 100644 index b47101c8f8..0000000000 --- a/gazelle/testdata/with_third_party_requirements/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# With third-party requirements - -This test case asserts that a `py_library` is generated with dependencies -extracted from its sources and a `py_binary` is generated embeding the -`py_library` and inherits its dependencies, without specifying the `deps` again. diff --git a/gazelle/testdata/with_third_party_requirements/__init__.py b/gazelle/testdata/with_third_party_requirements/__init__.py deleted file mode 100644 index 6b58ff30a8..0000000000 --- a/gazelle/testdata/with_third_party_requirements/__init__.py +++ /dev/null @@ -1 +0,0 @@ -# For test purposes only. diff --git a/gazelle/testdata/with_third_party_requirements/__main__.py b/gazelle/testdata/with_third_party_requirements/__main__.py deleted file mode 100644 index fe551aa423..0000000000 --- a/gazelle/testdata/with_third_party_requirements/__main__.py +++ /dev/null @@ -1,5 +0,0 @@ -import bar -import foo - -_ = bar -_ = foo diff --git a/gazelle/testdata/with_third_party_requirements/bar.py b/gazelle/testdata/with_third_party_requirements/bar.py deleted file mode 100644 index 19ddd97a87..0000000000 --- a/gazelle/testdata/with_third_party_requirements/bar.py +++ /dev/null @@ -1,11 +0,0 @@ -import os - -import bar -import boto3 -import rest_framework - -_ = os - -_ = bar -_ = boto3 -_ = rest_framework diff --git a/gazelle/testdata/with_third_party_requirements/foo.py b/gazelle/testdata/with_third_party_requirements/foo.py deleted file mode 100644 index 29a1f3b612..0000000000 --- a/gazelle/testdata/with_third_party_requirements/foo.py +++ /dev/null @@ -1,11 +0,0 @@ -import sys - -import boto3 -import foo -import rest_framework - -_ = sys - -_ = boto3 -_ = foo -_ = rest_framework diff --git a/gazelle/testdata/with_third_party_requirements/gazelle_python.yaml b/gazelle/testdata/with_third_party_requirements/gazelle_python.yaml deleted file mode 100644 index 76bb8bfa7b..0000000000 --- a/gazelle/testdata/with_third_party_requirements/gazelle_python.yaml +++ /dev/null @@ -1,7 +0,0 @@ -manifest: - modules_mapping: - boto3: boto3 - rest_framework: djangorestframework - foo: baz - bar: baz - pip_deps_repository_name: gazelle_python_test diff --git a/gazelle/testdata/with_third_party_requirements/test.yaml b/gazelle/testdata/with_third_party_requirements/test.yaml deleted file mode 100644 index ed97d539c0..0000000000 --- a/gazelle/testdata/with_third_party_requirements/test.yaml +++ /dev/null @@ -1 +0,0 @@ ---- diff --git a/gazelle/testdata/with_third_party_requirements_from_imports/__init__.py b/gazelle/testdata/with_third_party_requirements_from_imports/__init__.py deleted file mode 100644 index 6b58ff30a8..0000000000 --- a/gazelle/testdata/with_third_party_requirements_from_imports/__init__.py +++ /dev/null @@ -1 +0,0 @@ -# For test purposes only. diff --git a/gazelle/testdata/with_third_party_requirements_from_imports/__main__.py b/gazelle/testdata/with_third_party_requirements_from_imports/__main__.py deleted file mode 100644 index 9f529cb0df..0000000000 --- a/gazelle/testdata/with_third_party_requirements_from_imports/__main__.py +++ /dev/null @@ -1,6 +0,0 @@ -from bar import main -from google.cloud import aiplatform - -if __name__ == "__main__": - print(aiplatform) - main() diff --git a/gazelle/testdata/with_third_party_requirements_from_imports/bar.py b/gazelle/testdata/with_third_party_requirements_from_imports/bar.py deleted file mode 100644 index 99a4b1ce95..0000000000 --- a/gazelle/testdata/with_third_party_requirements_from_imports/bar.py +++ /dev/null @@ -1,6 +0,0 @@ -from google.cloud import aiplatform, storage - - -def main(): - a = dir(aiplatform) - b = dir(storage) diff --git a/gazelle/testdata/with_third_party_requirements_from_imports/test.yaml b/gazelle/testdata/with_third_party_requirements_from_imports/test.yaml deleted file mode 100644 index ed97d539c0..0000000000 --- a/gazelle/testdata/with_third_party_requirements_from_imports/test.yaml +++ /dev/null @@ -1 +0,0 @@ ----