fix(gazelle): Don't ignore `setup.py` files when running Gazelle (#2536) Don't ignore `setup.py` files when running Gazelle. Fixes #2108. I believe that `setup.py` was originally ignored because it, when found that the repo root, is part of `setuptools` config and may have caused problems with Gazelle. I've been running our Google Quantum code with this patch for a long while now and not seen any issues. I figured it was time to upstream it.
diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c2f84f..3ae28a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md
@@ -77,6 +77,8 @@ are now printing more details and include the currently active flag values. Fixes [#2466](https://github.com/bazelbuild/rules_python/issues/2466). * (py_proto_library) Fix import paths in Bazel 8. ++ (gazelle) Gazelle no longer ignores `setup.py` files by default. To restore + this behavior, apply the `# gazelle:python_ignore_files setup.py` directive. [pep-695]: https://peps.python.org/pep-0695/
diff --git a/gazelle/python/testdata/dont_ignore_setup/BUILD.in b/gazelle/python/testdata/dont_ignore_setup/BUILD.in new file mode 100644 index 0000000..af2c2ce --- /dev/null +++ b/gazelle/python/testdata/dont_ignore_setup/BUILD.in
@@ -0,0 +1 @@ +# gazelle:python_generation_mode file
diff --git a/gazelle/python/testdata/dont_ignore_setup/BUILD.out b/gazelle/python/testdata/dont_ignore_setup/BUILD.out new file mode 100644 index 0000000..acf9324 --- /dev/null +++ b/gazelle/python/testdata/dont_ignore_setup/BUILD.out
@@ -0,0 +1,9 @@ +load("@rules_python//python:defs.bzl", "py_library") + +# gazelle:python_generation_mode file + +py_library( + name = "setup", + srcs = ["setup.py"], + visibility = ["//:__subpackages__"], +)
diff --git a/gazelle/python/testdata/dont_ignore_setup/README.md b/gazelle/python/testdata/dont_ignore_setup/README.md new file mode 100644 index 0000000..d170364 --- /dev/null +++ b/gazelle/python/testdata/dont_ignore_setup/README.md
@@ -0,0 +1,8 @@ +# Don't ignore setup.py files + +Make sure that files named `setup.py` are processed by Gazelle. + +It's believed that `setup.py` was originally ignored because it, when found +in the repository root directory, is part of the `setuptools` build system +and could cause some issues for Gazelle. However, files within source code can +also be called `setup.py` and thus should be processed by Gazelle.
diff --git a/gazelle/python/testdata/dont_ignore_setup/WORKSPACE b/gazelle/python/testdata/dont_ignore_setup/WORKSPACE new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/gazelle/python/testdata/dont_ignore_setup/WORKSPACE
diff --git a/gazelle/python/testdata/dont_ignore_setup/setup.py b/gazelle/python/testdata/dont_ignore_setup/setup.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/gazelle/python/testdata/dont_ignore_setup/setup.py
diff --git a/gazelle/python/testdata/dont_ignore_setup/test.yaml b/gazelle/python/testdata/dont_ignore_setup/test.yaml new file mode 100644 index 0000000..c27e6c8 --- /dev/null +++ b/gazelle/python/testdata/dont_ignore_setup/test.yaml
@@ -0,0 +1,15 @@ +# Copyright 2024 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_ignore_files_directive/BUILD.out b/gazelle/python/testdata/python_ignore_files_directive/BUILD.out index 1fe6030..234ff71 100644 --- a/gazelle/python/testdata/python_ignore_files_directive/BUILD.out +++ b/gazelle/python/testdata/python_ignore_files_directive/BUILD.out
@@ -4,6 +4,9 @@ py_library( name = "python_ignore_files_directive", - srcs = ["__init__.py"], + srcs = [ + "__init__.py", + "setup.py", + ], visibility = ["//:__subpackages__"], )
diff --git a/gazelle/pythonconfig/pythonconfig.go b/gazelle/pythonconfig/pythonconfig.go index 5512138..fde0a98 100644 --- a/gazelle/pythonconfig/pythonconfig.go +++ b/gazelle/pythonconfig/pythonconfig.go
@@ -126,7 +126,6 @@ // defaultIgnoreFiles is the list of default values used in the // python_ignore_files option. var defaultIgnoreFiles = map[string]struct{}{ - "setup.py": {}, } // Configs is an extension of map[string]*Config. It provides finding methods