add support for isort and --fix to spack style#24071
Conversation
a634290 to
a1ca83c
Compare
a1ca83c to
2d3566c
Compare
2d3566c to
1f2fd05
Compare
|
@adamjstewart I made this work on I also reworked the output for |
We enabled import order checking in #23947, but fixing things manually drives people crazy. This used `spack style --fix --all` from #24071 to automatically sort everything in Spack so PR submitters won't have to deal with it. This should go in after #24071, as it assumes we're using `isort`, not `flake8-import-order` to order things. `isort` seems to be more flexible and allows `llnl` mports to be in their own group before `spack` ones, so this seems like a good switch.
adamjstewart
left a comment
There was a problem hiding this comment.
I agree with dropping flake8-import-order in favor of isort as isort seems more powerful and more popular. It is possible to use both (you can write your own custom style for flake8-import-order) but I don't see any advantage in that. It's already hard enough to ensure that flake8 and black agree on style; no need to add both flake8-import-order and isort to the mix. The only annoyance is that flake8 will bring in any plugins it can find, including flake8-import-order which is in my path. We could disable this explicitly, but I might just stop using it for my projects.
adamjstewart
left a comment
There was a problem hiding this comment.
There are still a few things I would change (add color to isort/black), move mypy.ini to pyproject.toml, but those can happen in a follow-up PR.
5bed9de to
7042417
Compare
|
Ok found the issue --
It looks like there was some discussion of this in #23212 (comment), and the issue is that CVS dates can obnoxiously have different formats on different systems. I googled around and it looks like they can look like any of these: So, slashes or dashes, with or without timezone. There never seems to be a sub-second component. It takes 6 lines of YAML and some weird test-skipping logic to get FYI @alalazo, @eschnett, @scheibelp. |
Second thought: I don't see any "Modified file" in the logs
7042417 to
0724cf4
Compare
|
ok we might actually get this in this time -- thanks @alalazo for the late catch |
- [x] Remove flake8-import-order checks, as we only need isort for this - [x] Clean up configuration and requirements
This consolidates code across tools in `spack style` so that each `run_<tool>` function can be called indirecty through a dictionary of handlers, and os that checks like finding the executable for the tool can be shared across commands. - [x] rework `spack style` to use decorators to register tools - [x] define tool order in one place in `spack style` - [x] fix python 2/3 issues to Get `isort` checks working - [x] make isort error regex more robust across versions - [x] remove unused output option - [x] change vestigial `TRAVIS_BRANCH` to `GITHUB_BASE_REF` - [x] update completion
Previous tests of `spack style` didn't really run the tools -- they just ensure that the commands worked enough to get coverage. This adds several real tests and ensures that we hit the corner cases in `spack style`. This also tests sucess as well as failure cases.
`dateutil.parser` was an optional dependency for CVS tests. It was failing on macOS beacuse the dateutil types were not being installed, and mypy was failing *even when the CVS tests were skipped*. This seems like it was an oversight on macOS -- `types-dateutil-parser` was not installed there, though it was on Linux unit tests. It takes 6 lines of YAML and some weird test-skipping logic to get `python-dateutil` and `types-python-dateutil` installed in all the tests where we need them, but it only takes 4 lines of code to write the date parser we need for CVS, so I just did that instead. Note that CVS date format can vary from system to system, but it seems like it's always pretty similar for the parts we care about. - [x] Replace dateutil.parser with a simpler date regex - [x] Lose the dependency on `dateutil.parser`
a4082bf
0724cf4 to
a4082bf
Compare
We enabled import order checking in #23947, but fixing things manually drives people crazy. This used `spack style --fix --all` from #24071 to automatically sort everything in Spack so PR submitters won't have to deal with it. This should go in after #24071, as it assumes we're using `isort`, not `flake8-import-order` to order things. `isort` seems to be more flexible and allows `llnl` mports to be in their own group before `spack` ones, so this seems like a good switch.
We enabled import order checking in #23947, but fixing things manually drives people crazy. This used `spack style --fix --all` from #24071 to automatically sort everything in Spack so PR submitters won't have to deal with it. This should go in after #24071, as it assumes we're using `isort`, not `flake8-import-order` to order things. `isort` seems to be more flexible and allows `llnl` mports to be in their own group before `spack` ones, so this seems like a good switch.
* fix remaining flake8 errors * imports: sort imports everywhere in Spack We enabled import order checking in #23947, but fixing things manually drives people crazy. This used `spack style --fix --all` from #24071 to automatically sort everything in Spack so PR submitters won't have to deal with it. This should go in after #24071, as it assumes we're using `isort`, not `flake8-import-order` to order things. `isort` seems to be more flexible and allows `llnl` mports to be in their own group before `spack` ones, so this seems like a good switch.
Problem
#23947 adds
flake8import style checking, which is awesome. It would be great however if we could forcespack styleto fix import ordering itself.isortallows this and is compatible withblack.Solution
run_isort()tostyle.pyto execute isort inspack style, and add apyproject.tomlconfiguration file.isortto our dependencies inunit_tests.yaml.--fixargument tospack style, which configures isort and black to edit files on the local filesystem instead of printing out a diff.--show-error-codesargument to mypy so that the user can easily see how to disable the warning with a focused# type: ignore[<error-code>]comment.Result
We can automatically fix import sorting errors identified via #23947 with isort, and we can automatically apply the black formatter as well with the
--fixoption tospack style!