diff --git a/CHANGELOG.md b/CHANGELOG.md index c52481d52e..9fdd58c2b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,7 +56,7 @@ END_UNRELEASED_TEMPLATE ### Changed * (gazelle) For package mode, resolve dependencies when imports are relative to the package path. This is enabled via the - `# gazelle:experimental_allow_relative_imports` true directive ({gh-issue}`2203`). + `# gazelle:python_experimental_allow_relative_imports` true directive ({gh-issue}`2203`). * (gazelle) Types for exposed members of `python.ParserOutput` are now all public. * (gazelle) Removed the requirement for `__init__.py`, `__main__.py`, or `__test__.py` files to be present in a directory to generate a `BUILD.bazel` file. diff --git a/gazelle/README.md b/gazelle/README.md index 8b088a4e70..83f341c49d 100644 --- a/gazelle/README.md +++ b/gazelle/README.md @@ -222,7 +222,7 @@ Python-specific directives are as follows: | Defines the format of the distribution name in labels to third-party deps. Useful for using Gazelle plugin with other rules with different repository conventions (e.g. `rules_pycross`). Full label is always prepended with (pip) repository name, e.g. `@pip//numpy`. | | `# gazelle:python_label_normalization` | `snake_case` | | Controls how distribution names in labels to third-party deps are normalized. Useful for using Gazelle plugin with other rules with different label conventions (e.g. `rules_pycross` uses PEP-503). Can be "snake_case", "none", or "pep503". | -| `# gazelle:experimental_allow_relative_imports` | `false` | +| `# gazelle:python_experimental_allow_relative_imports` | `false` | | Controls whether Gazelle resolves dependencies for import statements that use paths relative to the current package. Can be "true" or "false".| | `# gazelle:python_generate_pyi_deps` | `false` | | Controls whether to generate a separate `pyi_deps` attribute for type-checking dependencies or merge them into the regular `deps` attribute. When `false` (default), type-checking dependencies are merged into `deps` for backward compatibility. When `true`, generates separate `pyi_deps`. Imports in blocks with the format `if typing.TYPE_CHECKING:`/`if TYPE_CHECKING:` and type-only stub packages (eg. boto3-stubs) are recognized as type-checking dependencies. | @@ -736,7 +736,7 @@ See [Issue #3076][gh3076] for more information. [gh3076]: https://github.com/bazel-contrib/rules_python/issues/3076 -#### Directive: `experimental_allow_relative_imports` +#### Directive: `python_experimental_allow_relative_imports` Enables experimental support for resolving relative imports in `python_generation_mode package`. diff --git a/gazelle/python/testdata/relative_imports_package_mode/BUILD.in b/gazelle/python/testdata/relative_imports_package_mode/BUILD.in index 78ef0a7863..52bcb68600 100644 --- a/gazelle/python/testdata/relative_imports_package_mode/BUILD.in +++ b/gazelle/python/testdata/relative_imports_package_mode/BUILD.in @@ -1,2 +1,2 @@ # gazelle:python_generation_mode package -# gazelle:experimental_allow_relative_imports true +# gazelle:python_experimental_allow_relative_imports true diff --git a/gazelle/python/testdata/relative_imports_package_mode/BUILD.out b/gazelle/python/testdata/relative_imports_package_mode/BUILD.out index f51b516cab..8775c114ef 100644 --- a/gazelle/python/testdata/relative_imports_package_mode/BUILD.out +++ b/gazelle/python/testdata/relative_imports_package_mode/BUILD.out @@ -1,7 +1,7 @@ load("@rules_python//python:defs.bzl", "py_binary") # gazelle:python_generation_mode package -# gazelle:experimental_allow_relative_imports true +# gazelle:python_experimental_allow_relative_imports true py_binary( name = "relative_imports_package_mode_bin", diff --git a/gazelle/python/testdata/sibling_imports_disabled/BUILD.in b/gazelle/python/testdata/sibling_imports_disabled/BUILD.in index 9509fd9727..44f7406e58 100644 --- a/gazelle/python/testdata/sibling_imports_disabled/BUILD.in +++ b/gazelle/python/testdata/sibling_imports_disabled/BUILD.in @@ -1,2 +1,2 @@ # gazelle:python_resolve_sibling_imports false -# gazelle:experimental_allow_relative_imports true +# gazelle:python_experimental_allow_relative_imports true diff --git a/gazelle/python/testdata/sibling_imports_disabled/BUILD.out b/gazelle/python/testdata/sibling_imports_disabled/BUILD.out index 7568f38f50..d3d5c6bfab 100644 --- a/gazelle/python/testdata/sibling_imports_disabled/BUILD.out +++ b/gazelle/python/testdata/sibling_imports_disabled/BUILD.out @@ -1,7 +1,7 @@ load("@rules_python//python:defs.bzl", "py_library", "py_test") # gazelle:python_resolve_sibling_imports false -# gazelle:experimental_allow_relative_imports true +# gazelle:python_experimental_allow_relative_imports true py_library( name = "sibling_imports_disabled", diff --git a/gazelle/python/testdata/sibling_imports_disabled/README.md b/gazelle/python/testdata/sibling_imports_disabled/README.md index d534a44bf1..a39023e8a3 100644 --- a/gazelle/python/testdata/sibling_imports_disabled/README.md +++ b/gazelle/python/testdata/sibling_imports_disabled/README.md @@ -10,7 +10,7 @@ disabled. It covers different types of imports in `pkg/unit_test.py`: (not the sibling `typing.py`). - `from .b import run` / `from .typing import A` - resolves to the sibling `pkg/b.py` / `pkg/typing.py` (with - `gazelle:experimental_allow_relative_imports` enabled) + `gazelle:python_experimental_allow_relative_imports` enabled) - `import test_util` - resolves to the root-level `test_util.py` instead of the sibling `pkg/test_util.py` - `from b import run` - resolves to the root-level `b.py` instead of the diff --git a/gazelle/python/testdata/sibling_imports_disabled_file_mode/BUILD.in b/gazelle/python/testdata/sibling_imports_disabled_file_mode/BUILD.in index 04494394c7..32b0bec20f 100644 --- a/gazelle/python/testdata/sibling_imports_disabled_file_mode/BUILD.in +++ b/gazelle/python/testdata/sibling_imports_disabled_file_mode/BUILD.in @@ -1,3 +1,3 @@ # gazelle:python_generation_mode file # gazelle:python_resolve_sibling_imports false -# gazelle:experimental_allow_relative_imports true +# gazelle:python_experimental_allow_relative_imports true diff --git a/gazelle/python/testdata/sibling_imports_disabled_file_mode/BUILD.out b/gazelle/python/testdata/sibling_imports_disabled_file_mode/BUILD.out index da53e14864..d7a829e8ea 100644 --- a/gazelle/python/testdata/sibling_imports_disabled_file_mode/BUILD.out +++ b/gazelle/python/testdata/sibling_imports_disabled_file_mode/BUILD.out @@ -2,7 +2,7 @@ load("@rules_python//python:defs.bzl", "py_library", "py_test") # gazelle:python_generation_mode file # gazelle:python_resolve_sibling_imports false -# gazelle:experimental_allow_relative_imports true +# gazelle:python_experimental_allow_relative_imports true py_library( name = "a", diff --git a/gazelle/python/testdata/sibling_imports_disabled_file_mode/README.md b/gazelle/python/testdata/sibling_imports_disabled_file_mode/README.md index 0bfbcffb58..124e751b10 100644 --- a/gazelle/python/testdata/sibling_imports_disabled_file_mode/README.md +++ b/gazelle/python/testdata/sibling_imports_disabled_file_mode/README.md @@ -10,7 +10,7 @@ disabled. It covers different types of imports in `pkg/unit_test.py`: (not the sibling `typing.py`). - `from .b import run` / `from .typing import A` - resolves to the sibling `pkg/b.py` / `pkg/typing.py` (with - `gazelle:experimental_allow_relative_imports` enabled) + `gazelle:python_experimental_allow_relative_imports` enabled) - `import test_util` - resolves to the root-level `test_util.py` instead of the sibling `pkg/test_util.py` - `from b import run` - resolves to the root-level `b.py` instead of the diff --git a/gazelle/pythonconfig/pythonconfig.go b/gazelle/pythonconfig/pythonconfig.go index b3d56591ee..ed9b914e82 100644 --- a/gazelle/pythonconfig/pythonconfig.go +++ b/gazelle/pythonconfig/pythonconfig.go @@ -99,7 +99,7 @@ const ( LabelNormalization = "python_label_normalization" // ExperimentalAllowRelativeImports represents the directive that controls // whether relative imports are allowed. - ExperimentalAllowRelativeImports = "experimental_allow_relative_imports" + ExperimentalAllowRelativeImports = "python_experimental_allow_relative_imports" // GeneratePyiDeps represents the directive that controls whether to generate // separate pyi_deps attribute or merge type-checking dependencies into deps. // Defaults to false for backward compatibility.