-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
lint: Should add basic linter for Python import statements #13571
Comments
Using a community tool would be best, if there is a suitable one. First search shows https://github.com/timothycrosley/isort as a contender. (Found via mention at psf/black#333. To the extent we canonicalize on formatting, IMO we should prefer |
If I'm reading the intention here correctly, then FYI in Anzu we have an implementation of this already. We could post that code somewhere for someone to adapt it to Drake, if there was interest. |
xref as likely related via |
Here's some
|
Also a reminder from f2f: we don't need a big-bang PR that adds linters and fixes everything. Instead, we should PR the tool and one 1 sample subdir that enables it. Then, incrementally we'll work on getting more and more parts of the tree to pass. |
The import order linter & auto-fixer imagined here will prescribe exactly how the imports should look. In terms of choosing a configuration file for that tool, the first-order goal should be to match (as closely as reasonable) the existing import ordering that Drake's code already uses. Of course some existing code will be wrong/inconsistent and the linter will end up fixing those files, but the first stab at config file settings should be ones that have as small of diffs as practical. |
Should formalize import statements
Relates #13572 (issue) in that this should be a idempotent projection to one format (ideal thing for linting)
Steps:
Some design thoughts:
pydrake
is imported beforetorch
(for Anzu)mut
andmut_*
modules being imported first (or encourage it, as well)My preferred styles and ordering (aside from the PEP8 sections):
EDIT: On second thought, perhaps
import pkg.sub as sub
is better thanfrom pkg import sub
, just as a way to show that it's a module, not a symbol.\cc @thduynguyen @RussTedrake
The text was updated successfully, but these errors were encountered: