[Developer Experience] Implement black as code formatter #7125
Replies: 8 comments 10 replies
-
I'm yet to ever use black. I do see it used a lot though in OSS. Typically at work we've only ever been in fairly small teams so it's easy to get everyone to follow the same kind of structure. I can see the benefit of it on projects like this though. Even if it might completely destroy my preferred coding styles 😆 We could also put black and flake8 into pre-commit hooks so that they're being ran as people work rather than just when things hit github actions. |
Beta Was this translation helpful? Give feedback.
-
For anyone wanting to explore what this would provide, for django-cms or any other project, I've been looking into hooks lately. Starting with... https://pre-commit.com/ There's a python package you can install, Then create a file in the root of your project called To simply run black populate that file with
However you could run isort, flake8, black and various other helpful tools to keep the code clean & tidy. I'm currently investigating this pre-commit setup, which as of yet, doesn't run black, but does run other useful tools;
|
Beta Was this translation helpful? Give feedback.
-
My biggest issue with installing code formatters on existing projects is that the entire codebase is changed in one commit and tools such as Blame become useless to track changes and help bugfix. This will also make porting changes to v4 more difficult so of course I will complain. :-) Haha. I see a place for tools like this on new projects. If there was a way to force new changes to respect the rules that would help as it is implemented on each change and won't affect the code change history. |
Beta Was this translation helpful? Give feedback.
-
Alright, I've just tried to take a look at black and understand how you can make it work for a project... but you can't. It seems you cannot configure it beyond some basics like line length. Giving it a run on django-bleach to see how it's code looks and I've gone off it already. It's ruined the consistency of my code. I'd rather we didn't use this package and instead just had flake8 running how we want as that will keep code formatted well, while allowing a little freedom. |
Beta Was this translation helpful? Give feedback.
-
@marksweb made an interesting point today in the TC meeting:
|
Beta Was this translation helpful? Give feedback.
-
I really like the idea of running either black or blue. The drawback of having it kinda of messing with the git history is really a pain, but I think that we can overcome this problem by setting up it to be run in some parts of the code, like piece by piece instead of the whole project at once. This way we can iterate over it in a better way. There's also some ways where we can integrate it in our CI process (however it will need some more work to be done. Just would love to hear what other folks think about it. |
Beta Was this translation helpful? Give feedback.
-
As mentioned in our Friday meetings, I disagree with some settings used in black. Now that the Django project uses black, they reduced the maximum line length from 119 to 88. This in my opinion Something else, but less important is quoting. Since Python does not distinguish between single and double I fully agree that some parts of the code shall be reformatted, for instance the way we declare models and forms. |
Beta Was this translation helpful? Give feedback.
-
Just found out that conversation and thinking about raising a new discussion to use |
Beta Was this translation helpful? Give feedback.
-
To ensure the code looks consistent across all the files and remove all style related arguments from the code, I propose that we move to black as our official code formatter. Once decided, we also release instructions on how to configure it and even an example to add it as a pre-commit hook.
A lot of python projects and libraries have moved to black for formatting, and I think we should join the wagon too. I am curious to know what everyone thinks about it?
Beta Was this translation helpful? Give feedback.
All reactions