-
-
Notifications
You must be signed in to change notification settings - Fork 607
fix(gazelle) Delete python targets with invalid srcs #3046
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
f0f7a1b
to
c573eb3
Compare
if args.File == nil { | ||
return | ||
} | ||
regularFiles := args.RegularFiles |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we can inline this variable because it's only used once
} | ||
allInvalidSrcs := true | ||
for _, src := range existingRule.AttrStrings("srcs") { | ||
if _, ok := regularFilesMap[src]; ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also need to check:
- whether it's in
args.GenFiles
- whether it's a target. If it starts with either
@
,//
or:
, we can assume it's a target. If not, we can see if it ends with ".py" - whether it is a
glob
IMO this should be handled by properly supporting Specifically (emphasis mine):
We should not be deleting rules when running in I know it's a PITA - my users complain about it too - but there are too many legitimate cases where a |
@linzhp tagged me on this.
I don't know Python well enough to say whether that same behavior makes sense here. What does a The purpose of These days, rule sets are a lot more stable, so |
Ah, well I stand corrected then! Thanks for the background and info - I misunderstood the difference between
It's valid. For example, we use it to handle circular dependencies: # ########## START Autogenerated cycle targets and directives ##########
# See go/qos-doc-2024-24 for more info.
# cycle_c63218a5 (2 targets):
# gazelle:resolve py labrad.client //src:cycle_c63218a5
# gazelle:resolve py labrad.proto_over_labrad //src:cycle_c63218a5
py_library(
name = "cycle_c63218a5",
srcs = [],
imports = ["."],
tags = ["cycle"],
visibility = ["//visibility:public"],
deps = [
"//src/labrad:client",
"//src/labrad:proto_over_labrad",
],
) In the above case, Why do we put the cycles in So Gazelle deleting |
Currently, Gazelle is already cleaning up rules_python/gazelle/python/generate.go Lines 269 to 271 in 4e22d25
The situation we are trying to fix is the per-file There are two ways to move forward with this PR:
Let us know which approach you prefer. |
When running Gazelle, it generated the following target:
After
__main__.py
was deleted and the change committed, re-running Gazelle did not remove the file from the srcs list.This change introduces logic to check whether all entries in a Python target’s srcs attribute correspond to valid files. If none of them exist, the target is added to result.Empty to signal that it should be cleaned up. This cleanup behavior applies to when python_generation mode is package or file, as all
srcs
are expected to reside directly within the current directory.