Skip to content

Commit

Permalink
fix(gazelle): Don't ignore setup.py files when running Gazelle (#2536)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dougthor42 authored Dec 31, 2024
1 parent c8346f9 commit 9035db2
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ Unreleased changes template.
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/

Expand Down
1 change: 1 addition & 0 deletions gazelle/python/testdata/dont_ignore_setup/BUILD.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# gazelle:python_generation_mode file
9 changes: 9 additions & 0 deletions gazelle/python/testdata/dont_ignore_setup/BUILD.out
Original file line number Diff line number Diff line change
@@ -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__"],
)
8 changes: 8 additions & 0 deletions gazelle/python/testdata/dont_ignore_setup/README.md
Original file line number Diff line number Diff line change
@@ -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.
Empty file.
Empty file.
15 changes: 15 additions & 0 deletions gazelle/python/testdata/dont_ignore_setup/test.yaml
Original file line number Diff line number Diff line change
@@ -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.

---
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ load("@rules_python//python:defs.bzl", "py_library")

py_library(
name = "python_ignore_files_directive",
srcs = ["__init__.py"],
srcs = [
"__init__.py",
"setup.py",
],
visibility = ["//:__subpackages__"],
)
1 change: 0 additions & 1 deletion gazelle/pythonconfig/pythonconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ const (
// 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
Expand Down

0 comments on commit 9035db2

Please sign in to comment.