aboutsummaryrefslogtreecommitdiff
path: root/gazelle/python/testdata
diff options
context:
space:
mode:
Diffstat (limited to 'gazelle/python/testdata')
-rw-r--r--gazelle/python/testdata/binary_without_entrypoint/BUILD.in8
-rw-r--r--gazelle/python/testdata/binary_without_entrypoint/BUILD.out47
-rw-r--r--gazelle/python/testdata/binary_without_entrypoint/README.md4
-rw-r--r--gazelle/python/testdata/binary_without_entrypoint/WORKSPACE1
-rw-r--r--gazelle/python/testdata/binary_without_entrypoint/__init__.py15
-rw-r--r--gazelle/python/testdata/binary_without_entrypoint/collided_main.py4
-rw-r--r--gazelle/python/testdata/binary_without_entrypoint/main.py5
-rw-r--r--gazelle/python/testdata/binary_without_entrypoint/main2.py4
-rw-r--r--gazelle/python/testdata/binary_without_entrypoint/main_test.py7
-rw-r--r--gazelle/python/testdata/binary_without_entrypoint/test.yaml18
-rw-r--r--gazelle/python/testdata/dependency_resolution_order/BUILD.out2
-rw-r--r--gazelle/python/testdata/dependency_resolution_order/bar/BUILD.out1
-rw-r--r--gazelle/python/testdata/dependency_resolution_order/baz/BUILD.out1
-rw-r--r--gazelle/python/testdata/dependency_resolution_order/foo/BUILD.out1
-rw-r--r--gazelle/python/testdata/dependency_resolution_order/somewhere/bar/BUILD.out1
-rw-r--r--gazelle/python/testdata/dont_rename_target/BUILD.in1
-rw-r--r--gazelle/python/testdata/file_name_matches_import_statement/BUILD.out2
-rw-r--r--gazelle/python/testdata/first_party_file_and_directory_modules/foo/BUILD.out1
-rw-r--r--gazelle/python/testdata/first_party_file_and_directory_modules/one/BUILD.out1
-rw-r--r--gazelle/python/testdata/from_imports/foo/BUILD.out1
-rw-r--r--gazelle/python/testdata/from_imports/import_from_init_py/BUILD.out1
-rw-r--r--gazelle/python/testdata/from_imports/import_from_multiple/BUILD.out1
-rw-r--r--gazelle/python/testdata/from_imports/import_nested_file/BUILD.out1
-rw-r--r--gazelle/python/testdata/from_imports/import_nested_module/BUILD.out1
-rw-r--r--gazelle/python/testdata/from_imports/import_nested_var/BUILD.out1
-rw-r--r--gazelle/python/testdata/from_imports/import_top_level_var/BUILD.out1
-rw-r--r--gazelle/python/testdata/from_imports/std_module/BUILD.out1
-rw-r--r--gazelle/python/testdata/ignored_invalid_imported_module/BUILD.out2
-rw-r--r--gazelle/python/testdata/monorepo/coarse_grained/BUILD.out13
-rw-r--r--gazelle/python/testdata/monorepo/coarse_grained/bar/bar_test.py0
-rw-r--r--gazelle/python/testdata/monorepo/coarse_grained/foo/bar/bar_test.py0
-rw-r--r--gazelle/python/testdata/monorepo/one/BUILD.out2
-rw-r--r--gazelle/python/testdata/monorepo/one/bar/BUILD.out2
-rw-r--r--gazelle/python/testdata/monorepo/three/BUILD.out4
-rw-r--r--gazelle/python/testdata/monorepo/two/BUILD.out2
-rw-r--r--gazelle/python/testdata/naming_convention/dont_rename/BUILD.out3
-rw-r--r--gazelle/python/testdata/naming_convention/resolve_conflict/BUILD.out3
-rw-r--r--gazelle/python/testdata/per_file/BUILD.in11
-rw-r--r--gazelle/python/testdata/per_file/BUILD.out34
-rw-r--r--gazelle/python/testdata/per_file/README.md5
-rw-r--r--gazelle/python/testdata/per_file/WORKSPACE1
-rw-r--r--gazelle/python/testdata/per_file/__init__.py0
-rw-r--r--gazelle/python/testdata/per_file/bar.py15
-rw-r--r--gazelle/python/testdata/per_file/bar_test.py0
-rw-r--r--gazelle/python/testdata/per_file/baz.py15
-rw-r--r--gazelle/python/testdata/per_file/foo.py15
-rw-r--r--gazelle/python/testdata/per_file/foo_test.py0
-rw-r--r--gazelle/python/testdata/per_file/test.yaml15
-rw-r--r--gazelle/python/testdata/per_file_non_empty_init/BUILD.in4
-rw-r--r--gazelle/python/testdata/per_file_non_empty_init/BUILD.out20
-rw-r--r--gazelle/python/testdata/per_file_non_empty_init/README.md3
-rw-r--r--gazelle/python/testdata/per_file_non_empty_init/WORKSPACE1
-rw-r--r--gazelle/python/testdata/per_file_non_empty_init/__init__.py15
-rw-r--r--gazelle/python/testdata/per_file_non_empty_init/foo.py15
-rw-r--r--gazelle/python/testdata/per_file_non_empty_init/test.yaml15
-rw-r--r--gazelle/python/testdata/per_file_subdirs/BUILD.in3
-rw-r--r--gazelle/python/testdata/per_file_subdirs/BUILD.out10
-rw-r--r--gazelle/python/testdata/per_file_subdirs/README.md3
-rw-r--r--gazelle/python/testdata/per_file_subdirs/WORKSPACE1
-rw-r--r--gazelle/python/testdata/per_file_subdirs/bar/BUILD.in1
-rw-r--r--gazelle/python/testdata/per_file_subdirs/bar/BUILD.out45
-rw-r--r--gazelle/python/testdata/per_file_subdirs/bar/__init__.py15
-rw-r--r--gazelle/python/testdata/per_file_subdirs/bar/__test__.py0
-rw-r--r--gazelle/python/testdata/per_file_subdirs/bar/bar.py0
-rw-r--r--gazelle/python/testdata/per_file_subdirs/bar/bar_test.py0
-rw-r--r--gazelle/python/testdata/per_file_subdirs/bar/foo.py16
-rw-r--r--gazelle/python/testdata/per_file_subdirs/bar/foo_test.py0
-rw-r--r--gazelle/python/testdata/per_file_subdirs/baz/baz.py15
-rw-r--r--gazelle/python/testdata/per_file_subdirs/foo.py15
-rw-r--r--gazelle/python/testdata/per_file_subdirs/test.yaml15
-rw-r--r--gazelle/python/testdata/per_file_subdirs/test_target/BUILD.in3
-rw-r--r--gazelle/python/testdata/per_file_subdirs/test_target/BUILD.out25
-rw-r--r--gazelle/python/testdata/per_file_subdirs/test_target/a_test.py0
-rw-r--r--gazelle/python/testdata/per_file_subdirs/test_target/b_test.py0
-rw-r--r--gazelle/python/testdata/python_ignore_dependencies_directive/BUILD.out2
-rw-r--r--gazelle/python/testdata/python_ignore_files_directive/bar/BUILD.out1
-rw-r--r--gazelle/python/testdata/python_target_with_test_in_name/BUILD.out2
-rw-r--r--gazelle/python/testdata/relative_imports/BUILD.in1
-rw-r--r--gazelle/python/testdata/relative_imports/BUILD.out2
-rw-r--r--gazelle/python/testdata/relative_imports/package2/BUILD.out2
-rw-r--r--gazelle/python/testdata/relative_imports/package2/module3.py1
-rw-r--r--gazelle/python/testdata/sibling_imports/pkg/BUILD.out3
-rw-r--r--gazelle/python/testdata/simple_library_without_init/foo/BUILD.out1
-rw-r--r--gazelle/python/testdata/simple_test_with_conftest/bar/BUILD.out3
-rw-r--r--gazelle/python/testdata/subdir_sources/foo/BUILD.out1
-rw-r--r--gazelle/python/testdata/subdir_sources/foo/has_build/BUILD.out1
-rw-r--r--gazelle/python/testdata/subdir_sources/foo/has_init/BUILD.out1
-rw-r--r--gazelle/python/testdata/subdir_sources/foo/has_main/BUILD.out2
-rw-r--r--gazelle/python/testdata/subdir_sources/foo/has_test/BUILD.out2
-rw-r--r--gazelle/python/testdata/subdir_sources/one/BUILD.out1
-rw-r--r--gazelle/python/testdata/subdir_sources/one/two/BUILD.out1
-rw-r--r--gazelle/python/testdata/with_nested_import_statements/BUILD.out2
-rw-r--r--gazelle/python/testdata/with_third_party_requirements/BUILD.out8
-rw-r--r--gazelle/python/testdata/with_third_party_requirements_from_imports/BUILD.out6
94 files changed, 499 insertions, 58 deletions
diff --git a/gazelle/python/testdata/binary_without_entrypoint/BUILD.in b/gazelle/python/testdata/binary_without_entrypoint/BUILD.in
new file mode 100644
index 0000000..1177dce
--- /dev/null
+++ b/gazelle/python/testdata/binary_without_entrypoint/BUILD.in
@@ -0,0 +1,8 @@
+# gazelle:python_library_naming_convention py_default_library
+# gazelle:resolve py numpy @pip//:numpy
+# gazelle:resolve py pandas @pip//:pandas
+
+filegroup(
+ name = "collided_main",
+ srcs = ["collided_main.py"],
+)
diff --git a/gazelle/python/testdata/binary_without_entrypoint/BUILD.out b/gazelle/python/testdata/binary_without_entrypoint/BUILD.out
new file mode 100644
index 0000000..9af8152
--- /dev/null
+++ b/gazelle/python/testdata/binary_without_entrypoint/BUILD.out
@@ -0,0 +1,47 @@
+load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test")
+
+# gazelle:python_library_naming_convention py_default_library
+# gazelle:resolve py numpy @pip//:numpy
+# gazelle:resolve py pandas @pip//:pandas
+
+filegroup(
+ name = "collided_main",
+ srcs = ["collided_main.py"],
+)
+
+py_binary(
+ name = "main",
+ srcs = ["main.py"],
+ visibility = ["//:__subpackages__"],
+ deps = [
+ ":py_default_library",
+ "@pip//:pandas",
+ ],
+)
+
+py_binary(
+ name = "main2",
+ srcs = ["main2.py"],
+ visibility = ["//:__subpackages__"],
+ deps = [":py_default_library"],
+)
+
+py_library(
+ name = "py_default_library",
+ srcs = [
+ "__init__.py",
+ "collided_main.py",
+ "main.py",
+ "main2.py",
+ ],
+ visibility = ["//:__subpackages__"],
+ deps = [
+ "@pip//:numpy",
+ "@pip//:pandas",
+ ],
+)
+
+py_test(
+ name = "main_test",
+ srcs = ["main_test.py"],
+) \ No newline at end of file
diff --git a/gazelle/python/testdata/binary_without_entrypoint/README.md b/gazelle/python/testdata/binary_without_entrypoint/README.md
new file mode 100644
index 0000000..e91250d
--- /dev/null
+++ b/gazelle/python/testdata/binary_without_entrypoint/README.md
@@ -0,0 +1,4 @@
+# Binary without entrypoint
+
+This test case asserts that when there is no __main__.py, a py_binary is generated per main module, unless a main
+module main collides with existing target name.
diff --git a/gazelle/python/testdata/binary_without_entrypoint/WORKSPACE b/gazelle/python/testdata/binary_without_entrypoint/WORKSPACE
new file mode 100644
index 0000000..faff6af
--- /dev/null
+++ b/gazelle/python/testdata/binary_without_entrypoint/WORKSPACE
@@ -0,0 +1 @@
+# This is a Bazel workspace for the Gazelle test data.
diff --git a/gazelle/python/testdata/binary_without_entrypoint/__init__.py b/gazelle/python/testdata/binary_without_entrypoint/__init__.py
new file mode 100644
index 0000000..7307559
--- /dev/null
+++ b/gazelle/python/testdata/binary_without_entrypoint/__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/binary_without_entrypoint/collided_main.py b/gazelle/python/testdata/binary_without_entrypoint/collided_main.py
new file mode 100644
index 0000000..3bf59c7
--- /dev/null
+++ b/gazelle/python/testdata/binary_without_entrypoint/collided_main.py
@@ -0,0 +1,4 @@
+import numpy
+
+if __name__ == "__main__":
+ run() \ No newline at end of file
diff --git a/gazelle/python/testdata/binary_without_entrypoint/main.py b/gazelle/python/testdata/binary_without_entrypoint/main.py
new file mode 100644
index 0000000..f7b3170
--- /dev/null
+++ b/gazelle/python/testdata/binary_without_entrypoint/main.py
@@ -0,0 +1,5 @@
+import collided_main
+import pandas
+
+if __name__ == "__main__":
+ run() \ No newline at end of file
diff --git a/gazelle/python/testdata/binary_without_entrypoint/main2.py b/gazelle/python/testdata/binary_without_entrypoint/main2.py
new file mode 100644
index 0000000..a82a5e6
--- /dev/null
+++ b/gazelle/python/testdata/binary_without_entrypoint/main2.py
@@ -0,0 +1,4 @@
+import collided_main
+
+if __name__ == "__main__":
+ run()
diff --git a/gazelle/python/testdata/binary_without_entrypoint/main_test.py b/gazelle/python/testdata/binary_without_entrypoint/main_test.py
new file mode 100644
index 0000000..505a766
--- /dev/null
+++ b/gazelle/python/testdata/binary_without_entrypoint/main_test.py
@@ -0,0 +1,7 @@
+import unittest
+
+class TestMain(unittest.unittest):
+ pass
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/gazelle/python/testdata/binary_without_entrypoint/test.yaml b/gazelle/python/testdata/binary_without_entrypoint/test.yaml
new file mode 100644
index 0000000..44e4ae8
--- /dev/null
+++ b/gazelle/python/testdata/binary_without_entrypoint/test.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.
+
+---
+expect:
+ stderr: |
+ gazelle: failed to generate target "//:collided_main" of kind "py_binary": a target of kind "filegroup" with the same name already exists
diff --git a/gazelle/python/testdata/dependency_resolution_order/BUILD.out b/gazelle/python/testdata/dependency_resolution_order/BUILD.out
index 3ea83eb..eebe6c3 100644
--- a/gazelle/python/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_some_foo//:pkg",
+ "@gazelle_python_test//some_foo",
],
)
diff --git a/gazelle/python/testdata/dependency_resolution_order/bar/BUILD.out b/gazelle/python/testdata/dependency_resolution_order/bar/BUILD.out
index da9915d..5291471 100644
--- a/gazelle/python/testdata/dependency_resolution_order/bar/BUILD.out
+++ b/gazelle/python/testdata/dependency_resolution_order/bar/BUILD.out
@@ -3,6 +3,5 @@ load("@rules_python//python:defs.bzl", "py_library")
py_library(
name = "bar",
srcs = ["__init__.py"],
- imports = [".."],
visibility = ["//:__subpackages__"],
)
diff --git a/gazelle/python/testdata/dependency_resolution_order/baz/BUILD.out b/gazelle/python/testdata/dependency_resolution_order/baz/BUILD.out
index 749fd3d..fadf5c1 100644
--- a/gazelle/python/testdata/dependency_resolution_order/baz/BUILD.out
+++ b/gazelle/python/testdata/dependency_resolution_order/baz/BUILD.out
@@ -3,6 +3,5 @@ load("@rules_python//python:defs.bzl", "py_library")
py_library(
name = "baz",
srcs = ["__init__.py"],
- imports = [".."],
visibility = ["//:__subpackages__"],
)
diff --git a/gazelle/python/testdata/dependency_resolution_order/foo/BUILD.out b/gazelle/python/testdata/dependency_resolution_order/foo/BUILD.out
index 4404d30..58498ee 100644
--- a/gazelle/python/testdata/dependency_resolution_order/foo/BUILD.out
+++ b/gazelle/python/testdata/dependency_resolution_order/foo/BUILD.out
@@ -3,6 +3,5 @@ load("@rules_python//python:defs.bzl", "py_library")
py_library(
name = "foo",
srcs = ["__init__.py"],
- imports = [".."],
visibility = ["//:__subpackages__"],
)
diff --git a/gazelle/python/testdata/dependency_resolution_order/somewhere/bar/BUILD.out b/gazelle/python/testdata/dependency_resolution_order/somewhere/bar/BUILD.out
index a0d421b..5291471 100644
--- a/gazelle/python/testdata/dependency_resolution_order/somewhere/bar/BUILD.out
+++ b/gazelle/python/testdata/dependency_resolution_order/somewhere/bar/BUILD.out
@@ -3,6 +3,5 @@ load("@rules_python//python:defs.bzl", "py_library")
py_library(
name = "bar",
srcs = ["__init__.py"],
- imports = ["../.."],
visibility = ["//:__subpackages__"],
)
diff --git a/gazelle/python/testdata/dont_rename_target/BUILD.in b/gazelle/python/testdata/dont_rename_target/BUILD.in
index 33e8ec2..e9bc0e6 100644
--- a/gazelle/python/testdata/dont_rename_target/BUILD.in
+++ b/gazelle/python/testdata/dont_rename_target/BUILD.in
@@ -2,4 +2,5 @@ load("@rules_python//python:defs.bzl", "py_library")
py_library(
name = "my_custom_target",
+ srcs = ["__init__.py"],
)
diff --git a/gazelle/python/testdata/file_name_matches_import_statement/BUILD.out b/gazelle/python/testdata/file_name_matches_import_statement/BUILD.out
index 0216e4b..ae1ba81 100644
--- a/gazelle/python/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_djangorestframework//:pkg"],
+ deps = ["@gazelle_python_test//djangorestframework"],
)
diff --git a/gazelle/python/testdata/first_party_file_and_directory_modules/foo/BUILD.out b/gazelle/python/testdata/first_party_file_and_directory_modules/foo/BUILD.out
index 3decd90..8c54e3c 100644
--- a/gazelle/python/testdata/first_party_file_and_directory_modules/foo/BUILD.out
+++ b/gazelle/python/testdata/first_party_file_and_directory_modules/foo/BUILD.out
@@ -6,7 +6,6 @@ py_library(
"__init__.py",
"bar.py",
],
- imports = [".."],
visibility = ["//:__subpackages__"],
deps = ["//one"],
)
diff --git a/gazelle/python/testdata/first_party_file_and_directory_modules/one/BUILD.out b/gazelle/python/testdata/first_party_file_and_directory_modules/one/BUILD.out
index 7063141..3ae64b6 100644
--- a/gazelle/python/testdata/first_party_file_and_directory_modules/one/BUILD.out
+++ b/gazelle/python/testdata/first_party_file_and_directory_modules/one/BUILD.out
@@ -6,6 +6,5 @@ py_library(
"__init__.py",
"two.py",
],
- imports = [".."],
visibility = ["//:__subpackages__"],
)
diff --git a/gazelle/python/testdata/from_imports/foo/BUILD.out b/gazelle/python/testdata/from_imports/foo/BUILD.out
index 4404d30..58498ee 100644
--- a/gazelle/python/testdata/from_imports/foo/BUILD.out
+++ b/gazelle/python/testdata/from_imports/foo/BUILD.out
@@ -3,6 +3,5 @@ load("@rules_python//python:defs.bzl", "py_library")
py_library(
name = "foo",
srcs = ["__init__.py"],
- imports = [".."],
visibility = ["//:__subpackages__"],
)
diff --git a/gazelle/python/testdata/from_imports/import_from_init_py/BUILD.out b/gazelle/python/testdata/from_imports/import_from_init_py/BUILD.out
index 99b4861..8098aa7 100644
--- a/gazelle/python/testdata/from_imports/import_from_init_py/BUILD.out
+++ b/gazelle/python/testdata/from_imports/import_from_init_py/BUILD.out
@@ -3,7 +3,6 @@ load("@rules_python//python:defs.bzl", "py_library")
py_library(
name = "import_from_init_py",
srcs = ["__init__.py"],
- imports = [".."],
visibility = ["//:__subpackages__"],
deps = ["//foo/bar"],
) \ No newline at end of file
diff --git a/gazelle/python/testdata/from_imports/import_from_multiple/BUILD.out b/gazelle/python/testdata/from_imports/import_from_multiple/BUILD.out
index d8219bb..f5e113b 100644
--- a/gazelle/python/testdata/from_imports/import_from_multiple/BUILD.out
+++ b/gazelle/python/testdata/from_imports/import_from_multiple/BUILD.out
@@ -3,7 +3,6 @@ load("@rules_python//python:defs.bzl", "py_library")
py_library(
name = "import_from_multiple",
srcs = ["__init__.py"],
- imports = [".."],
visibility = ["//:__subpackages__"],
deps = [
"//foo/bar",
diff --git a/gazelle/python/testdata/from_imports/import_nested_file/BUILD.out b/gazelle/python/testdata/from_imports/import_nested_file/BUILD.out
index 662da9c..930216b 100644
--- a/gazelle/python/testdata/from_imports/import_nested_file/BUILD.out
+++ b/gazelle/python/testdata/from_imports/import_nested_file/BUILD.out
@@ -3,7 +3,6 @@ load("@rules_python//python:defs.bzl", "py_library")
py_library(
name = "import_nested_file",
srcs = ["__init__.py"],
- imports = [".."],
visibility = ["//:__subpackages__"],
deps = ["//foo/bar:baz"],
) \ No newline at end of file
diff --git a/gazelle/python/testdata/from_imports/import_nested_module/BUILD.out b/gazelle/python/testdata/from_imports/import_nested_module/BUILD.out
index ec6da50..51d3b8c 100644
--- a/gazelle/python/testdata/from_imports/import_nested_module/BUILD.out
+++ b/gazelle/python/testdata/from_imports/import_nested_module/BUILD.out
@@ -3,7 +3,6 @@ load("@rules_python//python:defs.bzl", "py_library")
py_library(
name = "import_nested_module",
srcs = ["__init__.py"],
- imports = [".."],
visibility = ["//:__subpackages__"],
deps = ["//foo/bar"],
) \ No newline at end of file
diff --git a/gazelle/python/testdata/from_imports/import_nested_var/BUILD.out b/gazelle/python/testdata/from_imports/import_nested_var/BUILD.out
index 8ee527e..2129c32 100644
--- a/gazelle/python/testdata/from_imports/import_nested_var/BUILD.out
+++ b/gazelle/python/testdata/from_imports/import_nested_var/BUILD.out
@@ -3,7 +3,6 @@ load("@rules_python//python:defs.bzl", "py_library")
py_library(
name = "import_nested_var",
srcs = ["__init__.py"],
- imports = [".."],
visibility = ["//:__subpackages__"],
deps = ["//foo/bar:baz"],
) \ No newline at end of file
diff --git a/gazelle/python/testdata/from_imports/import_top_level_var/BUILD.out b/gazelle/python/testdata/from_imports/import_top_level_var/BUILD.out
index 6b584d7..c8ef6f4 100644
--- a/gazelle/python/testdata/from_imports/import_top_level_var/BUILD.out
+++ b/gazelle/python/testdata/from_imports/import_top_level_var/BUILD.out
@@ -3,7 +3,6 @@ load("@rules_python//python:defs.bzl", "py_library")
py_library(
name = "import_top_level_var",
srcs = ["__init__.py"],
- imports = [".."],
visibility = ["//:__subpackages__"],
deps = ["//foo"],
) \ No newline at end of file
diff --git a/gazelle/python/testdata/from_imports/std_module/BUILD.out b/gazelle/python/testdata/from_imports/std_module/BUILD.out
index 4903999..b3597a9 100644
--- a/gazelle/python/testdata/from_imports/std_module/BUILD.out
+++ b/gazelle/python/testdata/from_imports/std_module/BUILD.out
@@ -3,6 +3,5 @@ load("@rules_python//python:defs.bzl", "py_library")
py_library(
name = "std_module",
srcs = ["__init__.py"],
- imports = [".."],
visibility = ["//:__subpackages__"],
) \ No newline at end of file
diff --git a/gazelle/python/testdata/ignored_invalid_imported_module/BUILD.out b/gazelle/python/testdata/ignored_invalid_imported_module/BUILD.out
index b8c936a..4744166 100644
--- a/gazelle/python/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_foo//:pkg"],
+ deps = ["@gazelle_python_test//foo"],
)
diff --git a/gazelle/python/testdata/monorepo/coarse_grained/BUILD.out b/gazelle/python/testdata/monorepo/coarse_grained/BUILD.out
index b11cbbd..3a33111 100644
--- a/gazelle/python/testdata/monorepo/coarse_grained/BUILD.out
+++ b/gazelle/python/testdata/monorepo/coarse_grained/BUILD.out
@@ -1,4 +1,4 @@
-load("@rules_python//python:defs.bzl", "py_library")
+load("@rules_python//python:defs.bzl", "py_library", "py_test")
# gazelle:python_extension enabled
# gazelle:python_root
@@ -16,5 +16,14 @@ py_library(
"foo/__init__.py",
],
visibility = ["//:__subpackages__"],
- deps = ["@root_pip_deps_rootboto3//:pkg"],
+ deps = ["@root_pip_deps//rootboto3"],
+)
+
+py_test(
+ name = "coarse_grained_test",
+ srcs = [
+ "bar/bar_test.py",
+ "foo/bar/bar_test.py",
+ ],
+ main = "__test__.py",
)
diff --git a/gazelle/python/testdata/monorepo/coarse_grained/bar/bar_test.py b/gazelle/python/testdata/monorepo/coarse_grained/bar/bar_test.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/gazelle/python/testdata/monorepo/coarse_grained/bar/bar_test.py
diff --git a/gazelle/python/testdata/monorepo/coarse_grained/foo/bar/bar_test.py b/gazelle/python/testdata/monorepo/coarse_grained/foo/bar/bar_test.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/gazelle/python/testdata/monorepo/coarse_grained/foo/bar/bar_test.py
diff --git a/gazelle/python/testdata/monorepo/one/BUILD.out b/gazelle/python/testdata/monorepo/one/BUILD.out
index 5098cc9..af11746 100644
--- a/gazelle/python/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_oneboto3//:pkg",
+ "@one_pip_deps//oneboto3",
],
)
diff --git a/gazelle/python/testdata/monorepo/one/bar/BUILD.out b/gazelle/python/testdata/monorepo/one/bar/BUILD.out
index 6ee6515..7a4a1d6 100644
--- a/gazelle/python/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_oneboto3//:pkg"],
+ deps = ["@one_pip_deps//oneboto3"],
)
diff --git a/gazelle/python/testdata/monorepo/three/BUILD.out b/gazelle/python/testdata/monorepo/three/BUILD.out
index 78a3927..2620d70 100644
--- a/gazelle/python/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_rootboto4//:pkg",
- "@three_pip_deps_threeboto3//:pkg",
+ "@root_pip_deps//rootboto4",
+ "@three_pip_deps//threeboto3",
],
)
diff --git a/gazelle/python/testdata/monorepo/two/BUILD.out b/gazelle/python/testdata/monorepo/two/BUILD.out
index 9cda007..cf22945 100644
--- a/gazelle/python/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_twoboto3//:pkg",
+ "@two_pip_deps//twoboto3",
],
)
diff --git a/gazelle/python/testdata/naming_convention/dont_rename/BUILD.out b/gazelle/python/testdata/naming_convention/dont_rename/BUILD.out
index 4d4ead8..8d418be 100644
--- a/gazelle/python/testdata/naming_convention/dont_rename/BUILD.out
+++ b/gazelle/python/testdata/naming_convention/dont_rename/BUILD.out
@@ -3,14 +3,12 @@ load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test")
py_library(
name = "dont_rename",
srcs = ["__init__.py"],
- imports = [".."],
visibility = ["//:__subpackages__"],
)
py_binary(
name = "my_dont_rename_binary",
srcs = ["__main__.py"],
- imports = [".."],
main = "__main__.py",
visibility = ["//:__subpackages__"],
deps = [":dont_rename"],
@@ -19,7 +17,6 @@ py_binary(
py_test(
name = "my_dont_rename_test",
srcs = ["__test__.py"],
- imports = [".."],
main = "__test__.py",
deps = [":dont_rename"],
)
diff --git a/gazelle/python/testdata/naming_convention/resolve_conflict/BUILD.out b/gazelle/python/testdata/naming_convention/resolve_conflict/BUILD.out
index 3fa5de2..e155fa6 100644
--- a/gazelle/python/testdata/naming_convention/resolve_conflict/BUILD.out
+++ b/gazelle/python/testdata/naming_convention/resolve_conflict/BUILD.out
@@ -9,14 +9,12 @@ go_test(name = "resolve_conflict_test")
py_library(
name = "my_resolve_conflict_library",
srcs = ["__init__.py"],
- imports = [".."],
visibility = ["//:__subpackages__"],
)
py_binary(
name = "my_resolve_conflict_binary",
srcs = ["__main__.py"],
- imports = [".."],
main = "__main__.py",
visibility = ["//:__subpackages__"],
deps = [":my_resolve_conflict_library"],
@@ -25,7 +23,6 @@ py_binary(
py_test(
name = "my_resolve_conflict_test",
srcs = ["__test__.py"],
- imports = [".."],
main = "__test__.py",
deps = [":my_resolve_conflict_library"],
)
diff --git a/gazelle/python/testdata/per_file/BUILD.in b/gazelle/python/testdata/per_file/BUILD.in
new file mode 100644
index 0000000..01b0904
--- /dev/null
+++ b/gazelle/python/testdata/per_file/BUILD.in
@@ -0,0 +1,11 @@
+load("@rules_python//python:defs.bzl", "py_library")
+
+# gazelle:python_generation_mode file
+
+# This target should be kept unmodified by Gazelle.
+py_library(
+ name = "custom",
+ srcs = ["bar.py"],
+ visibility = ["//visibility:private"],
+ tags = ["cant_touch_this"],
+)
diff --git a/gazelle/python/testdata/per_file/BUILD.out b/gazelle/python/testdata/per_file/BUILD.out
new file mode 100644
index 0000000..6deada8
--- /dev/null
+++ b/gazelle/python/testdata/per_file/BUILD.out
@@ -0,0 +1,34 @@
+load("@rules_python//python:defs.bzl", "py_library", "py_test")
+
+# gazelle:python_generation_mode file
+
+# This target should be kept unmodified by Gazelle.
+py_library(
+ name = "custom",
+ srcs = ["bar.py"],
+ tags = ["cant_touch_this"],
+ visibility = ["//visibility:private"],
+)
+
+py_library(
+ name = "baz",
+ srcs = ["baz.py"],
+ visibility = ["//:__subpackages__"],
+)
+
+py_library(
+ name = "foo",
+ srcs = ["foo.py"],
+ visibility = ["//:__subpackages__"],
+ deps = [":custom"],
+)
+
+py_test(
+ name = "bar_test",
+ srcs = ["bar_test.py"],
+)
+
+py_test(
+ name = "foo_test",
+ srcs = ["foo_test.py"],
+)
diff --git a/gazelle/python/testdata/per_file/README.md b/gazelle/python/testdata/per_file/README.md
new file mode 100644
index 0000000..3ddeb21
--- /dev/null
+++ b/gazelle/python/testdata/per_file/README.md
@@ -0,0 +1,5 @@
+# Per-file generation
+
+This test case generates one `py_library` per file.
+
+`__init__.py` is left empty so no target is generated for it.
diff --git a/gazelle/python/testdata/per_file/WORKSPACE b/gazelle/python/testdata/per_file/WORKSPACE
new file mode 100644
index 0000000..faff6af
--- /dev/null
+++ b/gazelle/python/testdata/per_file/WORKSPACE
@@ -0,0 +1 @@
+# This is a Bazel workspace for the Gazelle test data.
diff --git a/gazelle/python/testdata/per_file/__init__.py b/gazelle/python/testdata/per_file/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/gazelle/python/testdata/per_file/__init__.py
diff --git a/gazelle/python/testdata/per_file/bar.py b/gazelle/python/testdata/per_file/bar.py
new file mode 100644
index 0000000..7307559
--- /dev/null
+++ b/gazelle/python/testdata/per_file/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/per_file/bar_test.py b/gazelle/python/testdata/per_file/bar_test.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/gazelle/python/testdata/per_file/bar_test.py
diff --git a/gazelle/python/testdata/per_file/baz.py b/gazelle/python/testdata/per_file/baz.py
new file mode 100644
index 0000000..7307559
--- /dev/null
+++ b/gazelle/python/testdata/per_file/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/per_file/foo.py b/gazelle/python/testdata/per_file/foo.py
new file mode 100644
index 0000000..c000990
--- /dev/null
+++ b/gazelle/python/testdata/per_file/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.
+
+import bar
diff --git a/gazelle/python/testdata/per_file/foo_test.py b/gazelle/python/testdata/per_file/foo_test.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/gazelle/python/testdata/per_file/foo_test.py
diff --git a/gazelle/python/testdata/per_file/test.yaml b/gazelle/python/testdata/per_file/test.yaml
new file mode 100644
index 0000000..fcea777
--- /dev/null
+++ b/gazelle/python/testdata/per_file/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/per_file_non_empty_init/BUILD.in b/gazelle/python/testdata/per_file_non_empty_init/BUILD.in
new file mode 100644
index 0000000..f76a3d0
--- /dev/null
+++ b/gazelle/python/testdata/per_file_non_empty_init/BUILD.in
@@ -0,0 +1,4 @@
+load("@rules_python//python:defs.bzl", "py_library")
+
+# gazelle:python_generation_mode file
+# gazelle:python_generation_mode_per_file_include_init true
diff --git a/gazelle/python/testdata/per_file_non_empty_init/BUILD.out b/gazelle/python/testdata/per_file_non_empty_init/BUILD.out
new file mode 100644
index 0000000..ee4a417
--- /dev/null
+++ b/gazelle/python/testdata/per_file_non_empty_init/BUILD.out
@@ -0,0 +1,20 @@
+load("@rules_python//python:defs.bzl", "py_library")
+
+# gazelle:python_generation_mode file
+# gazelle:python_generation_mode_per_file_include_init true
+
+py_library(
+ name = "__init__",
+ srcs = ["__init__.py"],
+ visibility = ["//:__subpackages__"],
+ deps = [":foo"],
+)
+
+py_library(
+ name = "foo",
+ srcs = [
+ "__init__.py",
+ "foo.py",
+ ],
+ visibility = ["//:__subpackages__"],
+)
diff --git a/gazelle/python/testdata/per_file_non_empty_init/README.md b/gazelle/python/testdata/per_file_non_empty_init/README.md
new file mode 100644
index 0000000..6e6e9e2
--- /dev/null
+++ b/gazelle/python/testdata/per_file_non_empty_init/README.md
@@ -0,0 +1,3 @@
+# Per-file generation
+
+This test case generates one `py_library` per file, including `__init__.py`.
diff --git a/gazelle/python/testdata/per_file_non_empty_init/WORKSPACE b/gazelle/python/testdata/per_file_non_empty_init/WORKSPACE
new file mode 100644
index 0000000..faff6af
--- /dev/null
+++ b/gazelle/python/testdata/per_file_non_empty_init/WORKSPACE
@@ -0,0 +1 @@
+# This is a Bazel workspace for the Gazelle test data.
diff --git a/gazelle/python/testdata/per_file_non_empty_init/__init__.py b/gazelle/python/testdata/per_file_non_empty_init/__init__.py
new file mode 100644
index 0000000..492cbc0
--- /dev/null
+++ b/gazelle/python/testdata/per_file_non_empty_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.
+
+import foo
diff --git a/gazelle/python/testdata/per_file_non_empty_init/foo.py b/gazelle/python/testdata/per_file_non_empty_init/foo.py
new file mode 100644
index 0000000..7307559
--- /dev/null
+++ b/gazelle/python/testdata/per_file_non_empty_init/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/per_file_non_empty_init/test.yaml b/gazelle/python/testdata/per_file_non_empty_init/test.yaml
new file mode 100644
index 0000000..fcea777
--- /dev/null
+++ b/gazelle/python/testdata/per_file_non_empty_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/python/testdata/per_file_subdirs/BUILD.in b/gazelle/python/testdata/per_file_subdirs/BUILD.in
new file mode 100644
index 0000000..a5853f6
--- /dev/null
+++ b/gazelle/python/testdata/per_file_subdirs/BUILD.in
@@ -0,0 +1,3 @@
+load("@rules_python//python:defs.bzl", "py_library")
+
+# gazelle:python_generation_mode file
diff --git a/gazelle/python/testdata/per_file_subdirs/BUILD.out b/gazelle/python/testdata/per_file_subdirs/BUILD.out
new file mode 100644
index 0000000..69c42e0
--- /dev/null
+++ b/gazelle/python/testdata/per_file_subdirs/BUILD.out
@@ -0,0 +1,10 @@
+load("@rules_python//python:defs.bzl", "py_library")
+
+# gazelle:python_generation_mode file
+
+py_library(
+ name = "foo",
+ srcs = ["foo.py"],
+ visibility = ["//:__subpackages__"],
+ deps = ["//bar:__init__"],
+)
diff --git a/gazelle/python/testdata/per_file_subdirs/README.md b/gazelle/python/testdata/per_file_subdirs/README.md
new file mode 100644
index 0000000..9eda2fa
--- /dev/null
+++ b/gazelle/python/testdata/per_file_subdirs/README.md
@@ -0,0 +1,3 @@
+# Per-file generation
+
+This test case generates one `py_library` per file in subdirectories.
diff --git a/gazelle/python/testdata/per_file_subdirs/WORKSPACE b/gazelle/python/testdata/per_file_subdirs/WORKSPACE
new file mode 100644
index 0000000..faff6af
--- /dev/null
+++ b/gazelle/python/testdata/per_file_subdirs/WORKSPACE
@@ -0,0 +1 @@
+# This is a Bazel workspace for the Gazelle test data.
diff --git a/gazelle/python/testdata/per_file_subdirs/bar/BUILD.in b/gazelle/python/testdata/per_file_subdirs/bar/BUILD.in
new file mode 100644
index 0000000..4fc674a
--- /dev/null
+++ b/gazelle/python/testdata/per_file_subdirs/bar/BUILD.in
@@ -0,0 +1 @@
+# gazelle:python_generation_mode_per_file_include_init true
diff --git a/gazelle/python/testdata/per_file_subdirs/bar/BUILD.out b/gazelle/python/testdata/per_file_subdirs/bar/BUILD.out
new file mode 100644
index 0000000..8835fb2
--- /dev/null
+++ b/gazelle/python/testdata/per_file_subdirs/bar/BUILD.out
@@ -0,0 +1,45 @@
+load("@rules_python//python:defs.bzl", "py_library", "py_test")
+
+# gazelle:python_generation_mode_per_file_include_init true
+
+py_library(
+ name = "__init__",
+ srcs = ["__init__.py"],
+ visibility = ["//:__subpackages__"],
+)
+
+py_library(
+ name = "bar",
+ srcs = [
+ "__init__.py",
+ "bar.py",
+ ],
+ visibility = ["//:__subpackages__"],
+)
+
+py_library(
+ name = "foo",
+ srcs = [
+ "__init__.py",
+ "foo.py",
+ ],
+ visibility = ["//:__subpackages__"],
+)
+
+py_test(
+ name = "bar_test",
+ srcs = [
+ "__test__.py",
+ "bar_test.py",
+ ],
+ main = "__test__.py",
+)
+
+py_test(
+ name = "foo_test",
+ srcs = [
+ "__test__.py",
+ "foo_test.py",
+ ],
+ main = "__test__.py",
+)
diff --git a/gazelle/python/testdata/per_file_subdirs/bar/__init__.py b/gazelle/python/testdata/per_file_subdirs/bar/__init__.py
new file mode 100644
index 0000000..5799152
--- /dev/null
+++ b/gazelle/python/testdata/per_file_subdirs/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.
+
+from .foo import func
diff --git a/gazelle/python/testdata/per_file_subdirs/bar/__test__.py b/gazelle/python/testdata/per_file_subdirs/bar/__test__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/gazelle/python/testdata/per_file_subdirs/bar/__test__.py
diff --git a/gazelle/python/testdata/per_file_subdirs/bar/bar.py b/gazelle/python/testdata/per_file_subdirs/bar/bar.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/gazelle/python/testdata/per_file_subdirs/bar/bar.py
diff --git a/gazelle/python/testdata/per_file_subdirs/bar/bar_test.py b/gazelle/python/testdata/per_file_subdirs/bar/bar_test.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/gazelle/python/testdata/per_file_subdirs/bar/bar_test.py
diff --git a/gazelle/python/testdata/per_file_subdirs/bar/foo.py b/gazelle/python/testdata/per_file_subdirs/bar/foo.py
new file mode 100644
index 0000000..59eb08c
--- /dev/null
+++ b/gazelle/python/testdata/per_file_subdirs/bar/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 func():
+ pass
diff --git a/gazelle/python/testdata/per_file_subdirs/bar/foo_test.py b/gazelle/python/testdata/per_file_subdirs/bar/foo_test.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/gazelle/python/testdata/per_file_subdirs/bar/foo_test.py
diff --git a/gazelle/python/testdata/per_file_subdirs/baz/baz.py b/gazelle/python/testdata/per_file_subdirs/baz/baz.py
new file mode 100644
index 0000000..5256394
--- /dev/null
+++ b/gazelle/python/testdata/per_file_subdirs/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.
+
+from bar.foo import func
diff --git a/gazelle/python/testdata/per_file_subdirs/foo.py b/gazelle/python/testdata/per_file_subdirs/foo.py
new file mode 100644
index 0000000..b5e6cff
--- /dev/null
+++ b/gazelle/python/testdata/per_file_subdirs/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.
+
+from bar import func
diff --git a/gazelle/python/testdata/per_file_subdirs/test.yaml b/gazelle/python/testdata/per_file_subdirs/test.yaml
new file mode 100644
index 0000000..fcea777
--- /dev/null
+++ b/gazelle/python/testdata/per_file_subdirs/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/per_file_subdirs/test_target/BUILD.in b/gazelle/python/testdata/per_file_subdirs/test_target/BUILD.in
new file mode 100644
index 0000000..b5733da
--- /dev/null
+++ b/gazelle/python/testdata/per_file_subdirs/test_target/BUILD.in
@@ -0,0 +1,3 @@
+some_target(
+ name = "__test__",
+)
diff --git a/gazelle/python/testdata/per_file_subdirs/test_target/BUILD.out b/gazelle/python/testdata/per_file_subdirs/test_target/BUILD.out
new file mode 100644
index 0000000..f4a9236
--- /dev/null
+++ b/gazelle/python/testdata/per_file_subdirs/test_target/BUILD.out
@@ -0,0 +1,25 @@
+load("@rules_python//python:defs.bzl", "py_test")
+
+some_target(
+ name = "__test__",
+)
+
+py_test(
+ name = "a_test",
+ srcs = [
+ "a_test.py",
+ ":__test__",
+ ],
+ main = ":__test__.py",
+ deps = [":__test__"],
+)
+
+py_test(
+ name = "b_test",
+ srcs = [
+ "b_test.py",
+ ":__test__",
+ ],
+ main = ":__test__.py",
+ deps = [":__test__"],
+)
diff --git a/gazelle/python/testdata/per_file_subdirs/test_target/a_test.py b/gazelle/python/testdata/per_file_subdirs/test_target/a_test.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/gazelle/python/testdata/per_file_subdirs/test_target/a_test.py
diff --git a/gazelle/python/testdata/per_file_subdirs/test_target/b_test.py b/gazelle/python/testdata/per_file_subdirs/test_target/b_test.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/gazelle/python/testdata/per_file_subdirs/test_target/b_test.py
diff --git a/gazelle/python/testdata/python_ignore_dependencies_directive/BUILD.out b/gazelle/python/testdata/python_ignore_dependencies_directive/BUILD.out
index 3fb91f5..7afe61b 100644
--- a/gazelle/python/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_boto3//:pkg"],
+ deps = ["@gazelle_python_test//boto3"],
)
diff --git a/gazelle/python/testdata/python_ignore_files_directive/bar/BUILD.out b/gazelle/python/testdata/python_ignore_files_directive/bar/BUILD.out
index af3c398..94259f9 100644
--- a/gazelle/python/testdata/python_ignore_files_directive/bar/BUILD.out
+++ b/gazelle/python/testdata/python_ignore_files_directive/bar/BUILD.out
@@ -3,6 +3,5 @@ load("@rules_python//python:defs.bzl", "py_library")
py_library(
name = "bar",
srcs = ["baz.py"],
- imports = [".."],
visibility = ["//:__subpackages__"],
)
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
index a46f5c4..32e899b 100644
--- a/gazelle/python/testdata/python_target_with_test_in_name/BUILD.out
+++ b/gazelle/python/testdata/python_target_with_test_in_name/BUILD.out
@@ -11,7 +11,7 @@ py_test(
srcs = ["real_test.py"],
deps = [
":python_target_with_test_in_name",
- "@gazelle_python_test_boto3//:pkg",
+ "@gazelle_python_test//boto3",
],
)
diff --git a/gazelle/python/testdata/relative_imports/BUILD.in b/gazelle/python/testdata/relative_imports/BUILD.in
index e69de29..c04b5e5 100644
--- a/gazelle/python/testdata/relative_imports/BUILD.in
+++ b/gazelle/python/testdata/relative_imports/BUILD.in
@@ -0,0 +1 @@
+# gazelle:resolve py resolved_package //package2:resolved_package
diff --git a/gazelle/python/testdata/relative_imports/BUILD.out b/gazelle/python/testdata/relative_imports/BUILD.out
index 2c08627..bf95244 100644
--- a/gazelle/python/testdata/relative_imports/BUILD.out
+++ b/gazelle/python/testdata/relative_imports/BUILD.out
@@ -1,5 +1,7 @@
load("@rules_python//python:defs.bzl", "py_binary", "py_library")
+# gazelle:resolve py resolved_package //package2:resolved_package
+
py_library(
name = "relative_imports",
srcs = [
diff --git a/gazelle/python/testdata/relative_imports/package2/BUILD.out b/gazelle/python/testdata/relative_imports/package2/BUILD.out
index bbbc9f8..3e03e75 100644
--- a/gazelle/python/testdata/relative_imports/package2/BUILD.out
+++ b/gazelle/python/testdata/relative_imports/package2/BUILD.out
@@ -8,6 +8,6 @@ py_library(
"module4.py",
"subpackage1/module5.py",
],
- imports = [".."],
visibility = ["//:__subpackages__"],
+ deps = [":resolved_package"],
)
diff --git a/gazelle/python/testdata/relative_imports/package2/module3.py b/gazelle/python/testdata/relative_imports/package2/module3.py
index 74978a0..478dea9 100644
--- a/gazelle/python/testdata/relative_imports/package2/module3.py
+++ b/gazelle/python/testdata/relative_imports/package2/module3.py
@@ -15,6 +15,7 @@
from . import Class1
from .subpackage1.module5 import function5
+import resolved_package
def function3():
c1 = Class1()
diff --git a/gazelle/python/testdata/sibling_imports/pkg/BUILD.out b/gazelle/python/testdata/sibling_imports/pkg/BUILD.out
index edb40a8..cae6c3f 100644
--- a/gazelle/python/testdata/sibling_imports/pkg/BUILD.out
+++ b/gazelle/python/testdata/sibling_imports/pkg/BUILD.out
@@ -7,20 +7,17 @@ py_library(
"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/python/testdata/simple_library_without_init/foo/BUILD.out b/gazelle/python/testdata/simple_library_without_init/foo/BUILD.out
index 2faa046..8e50095 100644
--- a/gazelle/python/testdata/simple_library_without_init/foo/BUILD.out
+++ b/gazelle/python/testdata/simple_library_without_init/foo/BUILD.out
@@ -3,6 +3,5 @@ load("@rules_python//python:defs.bzl", "py_library")
py_library(
name = "foo",
srcs = ["foo.py"],
- imports = [".."],
visibility = ["//:__subpackages__"],
)
diff --git a/gazelle/python/testdata/simple_test_with_conftest/bar/BUILD.out b/gazelle/python/testdata/simple_test_with_conftest/bar/BUILD.out
index e42c499..4a1204e 100644
--- a/gazelle/python/testdata/simple_test_with_conftest/bar/BUILD.out
+++ b/gazelle/python/testdata/simple_test_with_conftest/bar/BUILD.out
@@ -6,7 +6,6 @@ py_library(
"__init__.py",
"bar.py",
],
- imports = [".."],
visibility = ["//:__subpackages__"],
)
@@ -14,14 +13,12 @@ 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",
diff --git a/gazelle/python/testdata/subdir_sources/foo/BUILD.out b/gazelle/python/testdata/subdir_sources/foo/BUILD.out
index f99857d..9107d2d 100644
--- a/gazelle/python/testdata/subdir_sources/foo/BUILD.out
+++ b/gazelle/python/testdata/subdir_sources/foo/BUILD.out
@@ -8,6 +8,5 @@ py_library(
"baz/baz.py",
"foo.py",
],
- imports = [".."],
visibility = ["//:__subpackages__"],
)
diff --git a/gazelle/python/testdata/subdir_sources/foo/has_build/BUILD.out b/gazelle/python/testdata/subdir_sources/foo/has_build/BUILD.out
index 0ef0cc1..d5196e5 100644
--- a/gazelle/python/testdata/subdir_sources/foo/has_build/BUILD.out
+++ b/gazelle/python/testdata/subdir_sources/foo/has_build/BUILD.out
@@ -3,6 +3,5 @@ load("@rules_python//python:defs.bzl", "py_library")
py_library(
name = "has_build",
srcs = ["python/my_module.py"],
- imports = ["../.."],
visibility = ["//:__subpackages__"],
)
diff --git a/gazelle/python/testdata/subdir_sources/foo/has_init/BUILD.out b/gazelle/python/testdata/subdir_sources/foo/has_init/BUILD.out
index ce59ee2..de61008 100644
--- a/gazelle/python/testdata/subdir_sources/foo/has_init/BUILD.out
+++ b/gazelle/python/testdata/subdir_sources/foo/has_init/BUILD.out
@@ -6,6 +6,5 @@ py_library(
"__init__.py",
"python/my_module.py",
],
- imports = ["../.."],
visibility = ["//:__subpackages__"],
)
diff --git a/gazelle/python/testdata/subdir_sources/foo/has_main/BUILD.out b/gazelle/python/testdata/subdir_sources/foo/has_main/BUILD.out
index 265c08b..1c56f72 100644
--- a/gazelle/python/testdata/subdir_sources/foo/has_main/BUILD.out
+++ b/gazelle/python/testdata/subdir_sources/foo/has_main/BUILD.out
@@ -3,14 +3,12 @@ load("@rules_python//python:defs.bzl", "py_binary", "py_library")
py_library(
name = "has_main",
srcs = ["python/my_module.py"],
- imports = ["../.."],
visibility = ["//:__subpackages__"],
)
py_binary(
name = "has_main_bin",
srcs = ["__main__.py"],
- imports = ["../.."],
main = "__main__.py",
visibility = ["//:__subpackages__"],
deps = [":has_main"],
diff --git a/gazelle/python/testdata/subdir_sources/foo/has_test/BUILD.out b/gazelle/python/testdata/subdir_sources/foo/has_test/BUILD.out
index 80739d9..a99278e 100644
--- a/gazelle/python/testdata/subdir_sources/foo/has_test/BUILD.out
+++ b/gazelle/python/testdata/subdir_sources/foo/has_test/BUILD.out
@@ -3,14 +3,12 @@ load("@rules_python//python:defs.bzl", "py_library", "py_test")
py_library(
name = "has_test",
srcs = ["python/my_module.py"],
- imports = ["../.."],
visibility = ["//:__subpackages__"],
)
py_test(
name = "has_test_test",
srcs = ["__test__.py"],
- imports = ["../.."],
main = "__test__.py",
deps = [":has_test"],
)
diff --git a/gazelle/python/testdata/subdir_sources/one/BUILD.out b/gazelle/python/testdata/subdir_sources/one/BUILD.out
index f2e5745..b78b650 100644
--- a/gazelle/python/testdata/subdir_sources/one/BUILD.out
+++ b/gazelle/python/testdata/subdir_sources/one/BUILD.out
@@ -3,6 +3,5 @@ load("@rules_python//python:defs.bzl", "py_library")
py_library(
name = "one",
srcs = ["__init__.py"],
- imports = [".."],
visibility = ["//:__subpackages__"],
)
diff --git a/gazelle/python/testdata/subdir_sources/one/two/BUILD.out b/gazelle/python/testdata/subdir_sources/one/two/BUILD.out
index f632eed..8f0ac17 100644
--- a/gazelle/python/testdata/subdir_sources/one/two/BUILD.out
+++ b/gazelle/python/testdata/subdir_sources/one/two/BUILD.out
@@ -6,7 +6,6 @@ py_library(
"__init__.py",
"three.py",
],
- imports = ["../.."],
visibility = ["//:__subpackages__"],
deps = ["//foo"],
)
diff --git a/gazelle/python/testdata/with_nested_import_statements/BUILD.out b/gazelle/python/testdata/with_nested_import_statements/BUILD.out
index 45bf265..c54bea7 100644
--- a/gazelle/python/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_boto3//:pkg"],
+ deps = ["@gazelle_python_test//boto3"],
)
diff --git a/gazelle/python/testdata/with_third_party_requirements/BUILD.out b/gazelle/python/testdata/with_third_party_requirements/BUILD.out
index 2a97d8b..c9330d9 100644
--- a/gazelle/python/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_baz//:pkg",
- "@gazelle_python_test_boto3//:pkg",
- "@gazelle_python_test_djangorestframework//:pkg",
+ "@gazelle_python_test//baz",
+ "@gazelle_python_test//boto3",
+ "@gazelle_python_test//djangorestframework",
],
)
@@ -20,5 +20,5 @@ py_binary(
srcs = ["__main__.py"],
main = "__main__.py",
visibility = ["//:__subpackages__"],
- deps = ["@gazelle_python_test_baz//:pkg"],
+ deps = ["@gazelle_python_test//baz"],
)
diff --git a/gazelle/python/testdata/with_third_party_requirements_from_imports/BUILD.out b/gazelle/python/testdata/with_third_party_requirements_from_imports/BUILD.out
index 577f167..9d6904f 100644
--- a/gazelle/python/testdata/with_third_party_requirements_from_imports/BUILD.out
+++ b/gazelle/python/testdata/with_third_party_requirements_from_imports/BUILD.out
@@ -8,8 +8,8 @@ py_library(
],
visibility = ["//:__subpackages__"],
deps = [
- "@gazelle_python_test_google_cloud_aiplatform//:pkg",
- "@gazelle_python_test_google_cloud_storage//:pkg",
+ "@gazelle_python_test//google_cloud_aiplatform",
+ "@gazelle_python_test//google_cloud_storage",
],
)
@@ -20,6 +20,6 @@ py_binary(
visibility = ["//:__subpackages__"],
deps = [
":with_third_party_requirements_from_imports",
- "@gazelle_python_test_google_cloud_aiplatform//:pkg",
+ "@gazelle_python_test//google_cloud_aiplatform",
],
)