-
Notifications
You must be signed in to change notification settings - Fork 193
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
Use black for formatting #283
Conversation
b887ea5
to
e35fcbd
Compare
Thanks for this pull request. I'm fine with using black for formatting, we did the same thing already in FuseSoC (but we'll need to get buy-in from @olofk as well). But I have several comments.
And please remember to describe why you're making changes in the commit messages and PR descriptions. For example, it's obvious from the commit itself that you set the line length to 120 characters. But nowhere is a description why that change is made. |
The main motivation for using black instead of any other Python formatter is precisely that it is opinionated, so there is almost no room for discusson. That's why we use it in other projects, such as VUnit or GHDL. However, black comes with it's own caveats. The main problem with using black is that the output is not deterministic. Changing the line-width from x to y and then back to x will not produce the same result as the initial code. That prevents contributors from using a different local setup that the upstream. At the same time, the default line-length (88) was set arbitrarily (without research), and it is kept mainly for historic/compatibility reasons. Since we haven't used punch cards for several decades, I believe we can use a line-length which better matches the devices we use for editing in the XXI century. 100-120 seems sensible, as it allows to have two files side-by-side in a 1920 pixel wide screen. In GHDL and VUnit, we found that using 120 instead of 88 made the code more readable. I think that 100, 110 or 115 might we equally acceptable. I don't have any strong preference above 95.
In this case, it's arbitrary. So, I'm good with you deciding which length to use, or whether to stick with 88.
Do you mean adding a
There is no "Developer's Guide" section in Edalize's docs. Shall I:
?
It seems that most PRs except #271 were not updated in a while, so they might be hit by several conflicts regardless of using black. Moreover, they can rebase on top of the PyProject commit, then run black on their branch, last merge. That will reduce the conflicts to the legit ones. Anyway, I'm good with keeping this PR on hold for some weeks/months, until a better time for introducing these changes. |
Let's just keep the default. It's what FuseSoC uses (which is more closely related to edalize than vunit or GHDL), and it's a good example of the "no discussion, just the default" rule.
Yes. You can also find the related CI config in FuseSoC. On documentation: whatever you find most appropriate to point developers to. I certainly wouldn't mind better developer docs in edalize, similar to what we have in FuseSoC (or even better!) But that's clearly beyond the scope of this PR, so two or three lines in https://github.com/olofk/edalize/blob/master/tests/README.rst or the main README would probably be the minimum. |
@imphil, I removed the black settings and run it with the default line-length. I added |
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.
Thanks, we're getting there!
In addition to the comments in the code I'd encourage you to structure your commits in a way that every commit is a meaningful, standalone unit of work, and less of a micro-commit where the commit message roughly matches what you typed in the code. When reviewing code, I want to look at a commit, read the commit message to understand why a change was made, and then see the related changes in the code. If a PR has 11 commits which are all effectively mechanical (e.g. "move file from A to B"), the big picture gets lost and reviews get harder.
How about a series of commits like this?
- Restructure documentation to be easier to navigate
- Use black through pre-commit, and document it
- Reformat the whole source tree with black
- Enforce pre-commit in CI
Do you approve the six commits that belong to this task? Please, confirm and I will squash. Having smaller commits is defensive, in case the maintainer (you here) wants to remove one of them (such as the line-length setting).
I don't understand the purpose of the additional Lint workflow. Is that expected to just check (and fail)? Or does it run black and commit the result? In the latter, is it to be used in master only? Moreover, that Action is in maintenance mode. Shall I use the recommended replacement instead? |
You don't need to make it a separate workflow, but use pre-commit to run black instead of running it manually. That's what the code example that I linked to does.
Whatever approach you prefer. |
59954ec
to
35c258e
Compare
Thanks for working on this. It looks great to me. As @imphil mentioned, it will wreak havoc on all outstanding PRs but I think we might just need to bite the bullet. Let me just quickly go through them to see if there are any particular ones we want to merge first |
Ok, done. I merged a few PRs and the rest will have to wait. If you can just rebase and rerun black to get rid of the conflicts, I'm fine with pulling this in now |
Sorry. I decided to merge #274 as well |
* [CI] Add job 'Format' * add dev-requirements.txt * add .pre-commit-config.yaml
pre-commit * Add section "Edalize Developer's Guide" * Reduce hierarchy complexity * [Tests/Readme] reduce hierarchy * Remove ref to empty Search Page * Make 'Indices and tables' a toctree * Make "Developer's Guide" a toctree
@olofk, done. |
Muchas gracias! Picked and pushed |
This PR uses psf/black: the uncompromising Python code formatter, for formatting Python sources. The line-length is set to 120 characters.
A CI job is added for checking that future contributions are formatted accordingly.