pretty code forever in 2023? #921
Replies: 7 comments 19 replies
-
There's another tool worth a mention: It's a service you can hook up to your Github repo, and it helps identify potential issues. It can fix a bunch of code quality issues, automatically creating PRs. One of the many things it can do is to automatically Black any incoming submissions. I've been playing around with it in another repo, its very comprehensive. And free for open source projects. I suspect it would need time and effort commitment from the repo Admin, so may not be good for this project right now |
Beta Was this translation helpful? Give feedback.
-
I support this idea; it saves me having to periodically Black everything (it's not really practical for someone else to do it, since it produces an enormous diff list and I can't really properly check it - although I trust you guys, there is always a danger someone could steal your credentials and drop a dodgy change into a massive Black refactoring). |
Beta Was this translation helpful? Give feedback.
-
There is already a pre-commit-config.yml with a black hook. This means when someone makes a commit, black should be run (if they ran Then, if a file is not blacked when it is submitted as a PR, a Github action should fail the PR until it's fixed. Is it not working? FWIW there is also darker which applies Black to only the parts that have changed. This makes the diffs in PRs smaller since whole files being formatted are limited to only the parts being changed. |
Beta Was this translation helpful? Give feedback.
-
There does seem to be an issue getting my local black, and the github black to agree. If this can't be fixed: Now I'm running black on everything locally, as every other commit has to be a PR, if @ehiggs is correct and we can force commits to be blacked, then wouldn't that be okay? And we turn off the constant lint errors that will appear every time I commit? |
Beta Was this translation helpful? Give feedback.
-
Below is a copy my comment from PR 927. For context, I said I had mixed feeling about black. @bug-or-feature asked about my concerns. The following was my response. ========== Well, to put it briefly, I think it's going to annoy me. It increases friction for pull requests, so I'll be marginally less likely to do them. I've been writing software for a long time, and I've always placed a high value on code that is clean, easy to understand, and well-formatted. Suggestions are great. I find the PEP 8 style warnings in PyCharm very useful. But it feels slightly insulting to have software critiquing my code style to the extent that commits or PRs will be rejected because of a trivial disagreement about style. I will admit that my opinion is more or less "rules for thee, but not for me", so take it with a grain of salt. |
Beta Was this translation helpful? Give feedback.
-
@tgibson11 would definitely not want to discourage anyone from contributing. Was it not an option for you to use the local git hook, or the IDE auto save thing? @robcarver17 there are git server side hooks, which can be configured to do the work 'on the way in'. But unfortunately they're not supported on GitHub. |
Beta Was this translation helpful? Give feedback.
-
And yet:
|
Beta Was this translation helpful? Give feedback.
-
Happy new year all. I can't remember who it was last year whose Santa wish was for the code to be Blacked. But when their wish was granted I remember feeling like I'd received a nice late Christmas present too.
One year on, and the code needs another clean; currently around 200 files would be changed. But maybe this time we can make it stay pretty forever? I've been looking into potential solutions.
Ad hoc
We could just do an occasional Black run over the codebase. Every week? Or month? It's not ideal though; automated would be better
GitHub action
We could setup a GitHub action that runs on every push or pull request. This would fail the build if the submitted code was not already Blacked. So, a bit like if someone submits a code change that causes a unit test to fail. This would be good for PRs -@robcarver17 could reject the PR until fixed. But, not so good for your own changes Rob, at least not when you commit direct onto the master branch. The dirty code would still be in the repo, and it would take another commit to make it clean again. Annoying
What we really wanto is a way to make sure no dirty code ever gets into the repo. Some ideas:
Black as a server
Black can be installed locally as a mini HTTP server. You can then configure
PyCharm (and other IDEs and editors) to automatically run Black over your code
as you save it. Steps here.To use Black like this would require another project config file at the top level,
pyproject.toml
, to configure files to be ignored etc. I don't think it can be done insetup.py
Git hook
On commit (to your local repo), git can be configured to run black over the changed code. Requires an extra dependency on pre-commit, but for your local environment only, not the project itself. Steps here
@robcarver17 what do you think? I'm happy to drive this if you approve. Maybe read this for a potential argument against
Beta Was this translation helpful? Give feedback.
All reactions