Skip to content

Commit 581cddc

Browse files
authored
fix(gazelle) Register pyi_deps as ResolveAttrs (bazel-contrib#3037)
Fix an issue in bazel-contrib#3014 where, when all type-checking dependencies are removed from a file, the corresponding target's `pyi_deps` doesn't get cleaned up. I traced this back to `ResolveAttrs`, though I'm not entirely sure of what other behaviors this may trigger. (Currently, removing `deps` from `ResolveAttrs` doesn't break any existing test case) (No new changelog entry since this is a fix to an unreleased feature that is already in the changelog)
1 parent 57f819c commit 581cddc

File tree

15 files changed

+73
-0
lines changed

15 files changed

+73
-0
lines changed

gazelle/python/kinds.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ var pyKinds = map[string]rule.KindInfo{
4646
},
4747
ResolveAttrs: map[string]bool{
4848
"deps": true,
49+
"pyi_deps": true,
4950
},
5051
},
5152
pyLibraryKind: {
@@ -62,6 +63,7 @@ var pyKinds = map[string]rule.KindInfo{
6263
},
6364
ResolveAttrs: map[string]bool{
6465
"deps": true,
66+
"pyi_deps": true,
6567
},
6668
},
6769
pyTestKind: {
@@ -78,6 +80,7 @@ var pyKinds = map[string]rule.KindInfo{
7880
},
7981
ResolveAttrs: map[string]bool{
8082
"deps": true,
83+
"pyi_deps": true,
8184
},
8285
},
8386
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# gazelle:python_generate_pyi_deps true
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# gazelle:python_generate_pyi_deps true
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Clearing deps / pyi_deps
2+
3+
This test case asserts that an existing `py_library` specifying `deps` and
4+
`pyi_deps` have these attributes removed if the corresponding imports are
5+
removed.
6+
7+
`a/BUILD.in` declares `deps`/`pyi_deps` on non-existing libraries, `b/BUILD.in` declares dependency on `//a`
8+
without a matching import, and `c/BUILD.in` declares both `deps` and `pyi_deps` as `["//a", "//b"]`, but
9+
it should have only `//a` as `deps` and only `//b` as `pyi_deps`.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# This is a Bazel workspace for the Gazelle test data.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
load("@rules_python//python:defs.bzl", "py_library")
2+
3+
py_library(
4+
name = "a",
5+
srcs = ["__init__.py"],
6+
pyi_deps = ["//:nonexistent_pyi_dep"],
7+
visibility = ["//:__subpackages__"],
8+
deps = ["//nonexistent_dep"],
9+
)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
load("@rules_python//python:defs.bzl", "py_library")
2+
3+
py_library(
4+
name = "a",
5+
srcs = ["__init__.py"],
6+
visibility = ["//:__subpackages__"],
7+
)

gazelle/python/testdata/clear_out_deps/a/__init__.py

Whitespace-only changes.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
load("@rules_python//python:defs.bzl", "py_library")
2+
3+
py_library(
4+
name = "b",
5+
srcs = ["__init__.py"],
6+
pyi_deps = ["//a"],
7+
visibility = ["//:__subpackages__"],
8+
deps = ["//a"],
9+
)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
load("@rules_python//python:defs.bzl", "py_library")
2+
3+
py_library(
4+
name = "b",
5+
srcs = ["__init__.py"],
6+
visibility = ["//:__subpackages__"],
7+
)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy