-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Don't exclude migrations from black #2138
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
base: main
Are you sure you want to change the base?
Conversation
I don't feel very strongly against or in support of this. I personally love black, but the only rationale I can think of excluding migrations is that it increases the migration file sizes a lot in attempt to make it more readable, and I am not sure that's necessary. I feel the number of migrations can become a lot, and with bigger file sizes, that don't need to be very readable, this may take more time in things like git cloning, etc.? Though maybe realistically not so much, hence I don't have a strong personal opinion against this PR. |
I wouldn't format migration files. They rarely need reading and when they do, the long lines tend to be beneficial because you can [more] easily see all the field names in a model without the distraction of the attributes, for example. |
So Django's auto formatter for generated files will pick it up > Python files created by startproject, startapp, optimizemigration, makemigrations, and squashmigrations are now formatted using the black command if it is present on your PATH. https://docs.djangoproject.com/en/5.2/releases/4.1/
998b568
to
53db658
Compare
@SaptakS I checked the before-and-after total file sizes. The difference is 12 KB. For comparison, As an additional data point, this is GrandPerspective output for the project folder: ![]() A single file in the .git folder is ~2000x bigger than the size difference created by the formatting. @marksweb Thanks for the input. I don't personally disagree with your points, but I also don't strongly agree with them. Both points you mentioned are subjective, and the second one depends on personal taste, your IDE config, etc. As a tool, black's philosophy is
That approach aims to remove the need for this type of "how do we format things" questions and apply a consistent styling without requiring one to think about which rules to use or where to apply them. And again, Django's default is to format the generated files. For the sake of compliance with both tools' approaches and to avoid falling into the trap of bikeshedding, I think it's better to proceed with a minimal amount of customization. |
This point does make me more inclined to accepting this PR. |
The exclusion of migration files from black was presented in #1198
I suppose this was considered a sane default, and I couldn't find any discussion about that exclusion in the PR. Considering that migration files are code, they are already revisioned and formatting them is Django's default behaviour; not excluding them makes feels more natural.
Relates to: