Skip to content

Commit 9035db2

Browse files
authored
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.
1 parent c8346f9 commit 9035db2

File tree

9 files changed

+39
-2
lines changed

9 files changed

+39
-2
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ Unreleased changes template.
7777
are now printing more details and include the currently active flag
7878
values. Fixes [#2466](https://github.com/bazelbuild/rules_python/issues/2466).
7979
* (py_proto_library) Fix import paths in Bazel 8.
80+
+ (gazelle) Gazelle no longer ignores `setup.py` files by default. To restore
81+
this behavior, apply the `# gazelle:python_ignore_files setup.py` directive.
8082

8183
[pep-695]: https://peps.python.org/pep-0695/
8284

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# gazelle:python_generation_mode file
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
load("@rules_python//python:defs.bzl", "py_library")
2+
3+
# gazelle:python_generation_mode file
4+
5+
py_library(
6+
name = "setup",
7+
srcs = ["setup.py"],
8+
visibility = ["//:__subpackages__"],
9+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Don't ignore setup.py files
2+
3+
Make sure that files named `setup.py` are processed by Gazelle.
4+
5+
It's believed that `setup.py` was originally ignored because it, when found
6+
in the repository root directory, is part of the `setuptools` build system
7+
and could cause some issues for Gazelle. However, files within source code can
8+
also be called `setup.py` and thus should be processed by Gazelle.

gazelle/python/testdata/dont_ignore_setup/WORKSPACE

Whitespace-only changes.

gazelle/python/testdata/dont_ignore_setup/setup.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright 2024 The Bazel Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
---

gazelle/python/testdata/python_ignore_files_directive/BUILD.out

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ load("@rules_python//python:defs.bzl", "py_library")
44

55
py_library(
66
name = "python_ignore_files_directive",
7-
srcs = ["__init__.py"],
7+
srcs = [
8+
"__init__.py",
9+
"setup.py",
10+
],
811
visibility = ["//:__subpackages__"],
912
)

gazelle/pythonconfig/pythonconfig.go

-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ const (
126126
// defaultIgnoreFiles is the list of default values used in the
127127
// python_ignore_files option.
128128
var defaultIgnoreFiles = map[string]struct{}{
129-
"setup.py": {},
130129
}
131130

132131
// Configs is an extension of map[string]*Config. It provides finding methods

0 commit comments

Comments
 (0)