-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Format all of Spack with black #24718
Conversation
Oddly I can't repro the |
Ok trying again now that #24695 is in. I think we need to allow packages to ignore black for long directives with SHA's. I think that includes @adamjstewart: thoughts? |
Let me download locally and see how badly black has messed things up. |
Okay, I took a look at a few big packages that I maintain. I'm actually surprisingly okay with most of the changes? I agree that version lists are a bit more verbose now than they used to be. I wouldn't be opposed to some solution that causes black to leave them alone (or formats them consistently and allows them to be longer). Black doesn't allow for much configuration, right? Would |
I think inserting |
That, or maybe I could get used to this. OpenMPI, HDF5, and LLVM are ones with long version lists, and they're not awful. I looked at MFEM and my heuristic above doesn't work very well for it -- if I substituted both URLs and SHA's out of the |
Let's get input from a few more people. I think the main reason we originally exempted all of Spack's directives from flake8 was because of me. I think I could also live with things as they are, especially if |
The other possibly much simpler option would be to go to a line length of 100. I tried it and it only adds 7k lines to Spack, vs. 60k for a line length of 88. It formats most directives nicely -- notably |
I would also be okay with that solution. |
I kind of like it better because it's uniform across the code and the packages, and we do not have to make exceptions for our package DSL -- something that's been a bit awkward when looking at package files for a while. |
Could we consider offering a "versions" directive to take a large number of fees ions and hashes instead and just let maintainers use it if they care? Or increase the allowed width for packages to account for hashes? This is a lot of complexity for relatively little IMO. |
Having read later comments I'm also good with a length of 100 for packages. The 88 length in black is because the author found on codes they tested on that it was best for reducing spurious extra lines like that. If 100 is more appropriate for packages in spack we should do it. Thinking about it having a multi-version directive might still be nice though, might mock that up and see how it looks. |
I'm running the numbers on this as we speak. Leaning towards 99 (so that editors can put the |
Ok here are the relevant numbers. I blackened Spack for line lengths from 79 to 120, and I looked at the total lines in python files for each of those settings. Horizontal lines are current total lines in core, packages, and both. Vertical lines are the settings we're considering. CoreThere isn't much of a difference for core -- there isn't really a knee in the curve and the benefits are small as the limit gets longer. PackagesFor packages, there is a big knee in the curve around 96 characters -- that's the length of a line like this:
There are a lot of those in packages. There is a smaller knee at ~90 characters, which is where I think most If we choose 88 as our limit, the packages will be around 40% longer than they are now. I think that's bad for readability, and we already felt strongly enough about versions, URLs, etc. fitting on a line that we made exceptions for directives in the original RecommendationGiven the data and the spirit of black's 88-character limit, my inclination is to set the limit to 99 characters for all of Spack, because:
The only downside I can see is that 99 is a bit longer than our longstanding limit of 80, and we might not be able to fit everything in an 80-char terminal anymore. I think 100 is still on the smaller side, so you can have a few terminals open, and they will fit on a screen. Thoughts? |
@tgamblin that looks good to me -- I think 100 char terminals won't offend many people. |
@tgamblin I also think that's a good choice. I'd be fine with anything in the 100-120 chars range |
I know I am stating the obvious, but we need to advertize this PR before we merge it since it has the potential to conflict with everything. |
This adds necessary configuration for flake8 and black to work together. This alos sets the line length to 99, per the data here: * #24718 (comment) Given the data and the spirit of black's 88-character limit, we set the limit to 99 characters for all of Spack, because: * 99 is one less than 100, a nice round number, and all lines will fit in a 100-character wide terminal (even when the text editor puts a \ at EOL). * 99 is just past the knee the file size curve for packages, and it means that packages remain readable and not significantly longer than they are now. * It doesn't seem to hurt core -- files in core might change length by a few percent but seem like they'll be mostly the same as before -- just a bit more roomy. - [x] set line length to 99 - [x] add exceptions to `.flake8` and add `[tool.black]` to `pyproject.toml`
As I mentioned before, I’m in favor, but do take a look at the output in core code before making the final decision. Since black will put things entirely on one line when it can, a long line limit there may make certain things, dict literals particularly, a bit rougher. Probably still worth it in the balance to keep things consistent, but worth a look to verify.
|
💯 works for me! |
This adds necessary configuration for flake8 and black to work together. This alos sets the line length to 99, per the data here: * #24718 (comment) Given the data and the spirit of black's 88-character limit, we set the limit to 99 characters for all of Spack, because: * 99 is one less than 100, a nice round number, and all lines will fit in a 100-character wide terminal (even when the text editor puts a \ at EOL). * 99 is just past the knee the file size curve for packages, and it means that packages remain readable and not significantly longer than they are now. * It doesn't seem to hurt core -- files in core might change length by a few percent but seem like they'll be mostly the same as before -- just a bit more roomy. - [x] set line length to 99 - [x] add exceptions to `.flake8` and add `[tool.black]` to `pyproject.toml`
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.
Contains everything I was looking for. Can't check individual files, but once the tests pass, this should be good to merge!
- [x] remove alignment spaces from tempaltes - [x] replace single with double quotes - [x] Makefile template now generates parsable code (function body is `pass` instead of just a comment) - [x] template checks now run black to check output
c22c7f2
to
f8ea8ec
Compare
`spack style` tests were annoyingly brittle because we could not easily be specific about which tools to run (we had to use `--no-black`, `--no-isort`, `--no-flake8`, and `--no-mypy`). We should be able to specify what to run OR what to skip. Now you can run, e.g.: spack style --tool black,flake8 or: spack style --skip black,isort - [x] Remove `--no-black`, `--no-isort`, `--no-flake8`, and `--no-mypy` args. - [x] Add `--tool TOOL` argument. - [x] Add `--skip TOOL` argument. - [x] Allow either `--tool black --tool flake8` or `--tool black,flake8` syntax.
Did you also update https://github.com/spack/spack/blob/v0.18.0/lib/spack/spack/build_systems/autotools.py#L327? Not sure if there are any other places in Spack where we print |
Oh, all of the docs still probably use the old format. Not crucial, but still worth updating someday (not necessarily in this PR). Does anyone know of a Sphinx plugin that lets you run |
I didn't but I don't really think it's worth updating that in this PR. Diff coverage is wrong -- it's 92% per codecov (if you click the link). I dunno why that number becomes more wrong the longer the PR has been around. |
This PR is tricky b/c it has a commit ref in it (in the blame ignore file), so it really needs to be rebased and fast-forward on |
This adds necessary configuration for flake8 and black to work together. This also sets the line length to 99, per the data here: * #24718 (comment) Given the data and the spirit of black's 88-character limit, we set the limit to 99 characters for all of Spack, because: * 99 is one less than 100, a nice round number, and all lines will fit in a 100-character wide terminal (even when the text editor puts a \ at EOL). * 99 is just past the knee the file size curve for packages, and it means that packages remain readable and not significantly longer than they are now. * It doesn't seem to hurt core -- files in core might change length by a few percent but seem like they'll be mostly the same as before -- just a bit more roomy. - [x] set line length to 99 - [x] remove most exceptions from `.flake8` and add the ones black cares about - [x] add `[tool.black]` to `pyproject.toml` - [x] make `black` run if available in `spack style --fix` Co-Authored-By: Tom Scogland <tscogland@llnl.gov>
A GitHub rebase merge seems to rewrite commits even if it would be a fast-forward, which means that the commit merged from #24718 is wrong. - [x] update `.git-blame-ignore-revs` with real commit from `develop`
A GitHub rebase merge seems to rewrite commits even if it would be a fast-forward, which means that the commit merged from #24718 is wrong. - [x] update `.git-blame-ignore-revs` with real commit from `develop`
Totally missed this earlier! Just wanted to say yay! 🥳 |
This adds necessary configuration for flake8 and black to work together. This also sets the line length to 99, per the data here: * spack#24718 (comment) Given the data and the spirit of black's 88-character limit, we set the limit to 99 characters for all of Spack, because: * 99 is one less than 100, a nice round number, and all lines will fit in a 100-character wide terminal (even when the text editor puts a \ at EOL). * 99 is just past the knee the file size curve for packages, and it means that packages remain readable and not significantly longer than they are now. * It doesn't seem to hurt core -- files in core might change length by a few percent but seem like they'll be mostly the same as before -- just a bit more roomy. - [x] set line length to 99 - [x] remove most exceptions from `.flake8` and add the ones black cares about - [x] add `[tool.black]` to `pyproject.toml` - [x] make `black` run if available in `spack style --fix` Co-Authored-By: Tom Scogland <tscogland@llnl.gov>
A GitHub rebase merge seems to rewrite commits even if it would be a fast-forward, which means that the commit merged from spack#24718 is wrong. - [x] update `.git-blame-ignore-revs` with real commit from `develop`
This adds necessary configuration for flake8 and black to work together. This also sets the line length to 99, per the data here: * spack#24718 (comment) Given the data and the spirit of black's 88-character limit, we set the limit to 99 characters for all of Spack, because: * 99 is one less than 100, a nice round number, and all lines will fit in a 100-character wide terminal (even when the text editor puts a \ at EOL). * 99 is just past the knee the file size curve for packages, and it means that packages remain readable and not significantly longer than they are now. * It doesn't seem to hurt core -- files in core might change length by a few percent but seem like they'll be mostly the same as before -- just a bit more roomy. - [x] set line length to 99 - [x] remove most exceptions from `.flake8` and add the ones black cares about - [x] add `[tool.black]` to `pyproject.toml` - [x] make `black` run if available in `spack style --fix` Co-Authored-By: Tom Scogland <tscogland@llnl.gov>
A GitHub rebase merge seems to rewrite commits even if it would be a fast-forward, which means that the commit merged from spack#24718 is wrong. - [x] update `.git-blame-ignore-revs` with real commit from `develop`
This blackens the
spack
repository, scientifically 😄.We want:
flake8
errors automatically, so as not to burden people with code style.python
ecosystem. i.e., we do not want to hold up anyone's package PR on style -- we want this to be faster than what we're already doing, even without a tool installed.How many columns?
Black defaults to 88 columns, but since we want to have one width for both core and packages, that is too narrow. You can see the effect of blackening packages and core for different column widths here:
Using 88 or fewer columns would add about 100k lines to the code base. We don't want that. Given the data and the spirit of black's 88-character limit, we will use a width of 99 characters because:
See this comment for more details.
How to fix style automatically?
Once this is merged, you can do a few different things to fix Spack's style automatically:
spack style --fix
-- this will automatically bootstrap and runisort
,mypy
,black
, andflake8
in that order, and it will automatically fixisort
andblack
errors.black
fixes mostflake8
errors, butflake8
still does useful checks (e.g., finds unused variables), so we still run it.@spackbot fix style
in a PR comment. Spackbot now knows how to runspack style --fix
, in case it doesn't work in your environment for some reason.black
yourself. Note that you will need to useblack
at version 21 or older, as we still support Python 2.7. Note thatblack
requires Python 3, but versions 21 and before will check 2.7 code. Versions 22 on drop support for 2.7.What else is different?
Because
black
formats them automatically, we no longer allow exceptions for long lines in Spack, except those that contain URLs. The only way you can get a really long line now is if you have a really long string, and you will need to either:Break up multi-line strings with parentheses, e.g.:
or:
Strings next to each other like this are automatically combined into one by Python (like C).
Use multi-line strings, e.g.:
Ignoring the huge reformat in your history
Run this in your Spack repo so that you won't see the gigantic
black
reformat commit when you usegit blame
:git config blame.ignoreRevsFile .git-blame-ignore-revs
Details
.flake8
and add the ones black cares about.[tool.black]
topyproject.toml
.black
run if available inspack style --fix
.black
..git-blame-ignore-revs
file so reformatting does not pollute GitHub blame.spack blame
aware of.git-blame-ignore-revs
.spack
will always bootstrapblack@:21
.spack create
andspack checksum
black-compliant.README.md
.--no-black
,--no-isort
,--no-flake8
,--no-mypy
arguments tospack style
.--tool TOOL
and--skip TOOL
arguments tospack style
so we can be specific.