ci: find and automatically remove unused imports#2318
ci: find and automatically remove unused imports#2318
Conversation
tbennun
left a comment
There was a problem hiding this comment.
Good effort here! Only a few comments on things that I could catch
|
|
||
| if __name__ == '__main__': | ||
| try: | ||
| import tensorflow |
There was a problem hiding this comment.
import should stay (dependency tester)
|
|
||
| if __name__ == '__main__': | ||
| try: | ||
| import tensorflow |
There was a problem hiding this comment.
import should stay (dependency tester)
|
|
||
| if __name__ == '__main__': | ||
| try: | ||
| import tensorflow |
There was a problem hiding this comment.
import should stay (dependency tester)
|
|
||
| if __name__ == '__main__': | ||
| try: | ||
| import tensorflow |
There was a problem hiding this comment.
import should stay (dependency tester)
|
|
||
| if __name__ == '__main__': | ||
| try: | ||
| import tensorflow |
There was a problem hiding this comment.
import should stay (dependency tester)
|
cscs-ci run |
cuda codegen had an `isinstance` check that compared ageinst `dace.nodes.data.Stream`. This worked because `dace.nodes` had an import that read `from dace import data` (which is implicitly re-exporting `data` from where it's imported. That `data` import was unused within `dace/sdfg/nodes.py` and thus was removed by `ruff`. The proposed solution here is to simply compare the instance against `dace.data.Stream` without the indirection.
Head branch was pushed to by a user without write access
|
newest commit should fix the GPU tests |
|
Now one of the (cpu bound) ML tests is suddenly failing after being fine twice in a row. I've only changed cuda codegen in the last commit. Could it be that this test is unstable? I can't seem to just re-run the ML tests. |
Unused imports add a performance overhead at runtime, and risk creating import cycles. To automatically detect and remove them in the future, this PR suggests to add ruff as a
pre-commithook to detect unused imports. I've added an exception for__init__.pyfiles to allow re-exports without adding an explicit__all__list or adding extra annotations.The PR grew quite big. However, non-automatic changes are only in the following seven files
.pre-commit-config.yaml: configurepre-committo run therufflinterruff.toml: configure therufflinter to only search for unused imports (ruleF401)dace/autodiff/library/library.py: make sure we keep theParameterArrayimport for backwards compatibilitydace/frontend/python/replacements/operators.py: make sure we keep thedaceimport for evaluation of data typestests/library/include_test.py: make sure we keep the necessary import in the middle of the testdace/sdfg/analysis/schedule_tree/treenodes.py: manually remove the now trivialif TYPE_CHECKINGbranch