Commit 7053e26
Gazelle: Delete stale py_library and py_test targets (#3817)
## Summary
Fix the issue #3375
Right now the `py_library` and `py_test` targets with missing srcs
wouldn't be cleaned up by Gazelle in file mode.
This can be reproduced by a unit test added in commit
ad0e48c
## Testing
In commit ad0e48c , without the fix,
`bazel test //python/...` failed in the newly added tests. The stale
`py_library ` and `py_test ` cannot be removed.
In latest HEAD d32fb7b, `bazel test
//python/...` can pass
```
INFO: From Testing //python:python_test_remove_invalid_per_file:
==================== Test output for //python:python_test_remove_invalid_per_file:
--- FAIL: TestGazelleBinary (0.02s)
--- FAIL: TestGazelleBinary/remove_invalid_per_file (0.08s)
python_test.go:186: remove_invalid_per_file/BUILD diff (-want,+got):
(
"""
... // 8 identical lines
)
+ py_library(
+ name = "deleted_lib",
+ srcs = ["deleted.py"],
+ visibility = ["//:__subpackages__"],
+ )
+
+ py_test(
+ name = "bar_test",
+ srcs = ["bar_test.py"],
+ )
+
py_test(
- name = "bar_test",
- srcs = ["bar_test.py"],
+ name = "deleted_test",
+ srcs = ["deleted_test.py"],
)
"""
)
```
---------
Co-authored-by: Tao Wang <watao@microsoft.com>1 parent 42c8e75 commit 7053e26
25 files changed
Lines changed: 235 additions & 4 deletions
File tree
- gazelle/python
- testdata
- remove_invalid_library_package_mode
- others
- remove_invalid_per_file
- alias_kind
- map_kind
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
77 | 82 | | |
78 | 83 | | |
79 | 84 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
593 | 593 | | |
594 | 594 | | |
595 | 595 | | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
596 | 607 | | |
597 | 608 | | |
598 | 609 | | |
599 | 610 | | |
600 | | - | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
601 | 628 | | |
602 | 629 | | |
603 | 630 | | |
604 | | - | |
| 631 | + | |
605 | 632 | | |
606 | 633 | | |
607 | 634 | | |
608 | 635 | | |
609 | | - | |
| 636 | + | |
610 | 637 | | |
611 | 638 | | |
612 | 639 | | |
613 | 640 | | |
614 | 641 | | |
615 | | - | |
| 642 | + | |
616 | 643 | | |
617 | 644 | | |
618 | 645 | | |
| |||
0 commit comments