The first stable version of `Black` has been released, see
[https://github.com/psf/black/releases/tag/22.1.0 22.1.0].
I assigned it to myself, but we will be working on this with Carlton and
the Ops Team.
See [https://github.com/django/deps/blob/main/accepted/0008-black.rst
#reference-implementation implementation].
--
Ticket URL: <https://code.djangoproject.com/ticket/33476>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Comment (by Carlton Gibson <carlton@…>):
In [changeset:"ca88caa1031c0de545d82de8d90dcae0e03651fb" ca88caa1]:
{{{
#!CommitTicketReference repository=""
revision="ca88caa1031c0de545d82de8d90dcae0e03651fb"
Refs #33476 -- Used vertical hanging indentation for format lists with
inline comments.
Lists with multiple values and comments per-line are reformatted
by Black to multiple lines with a single comment. For example:
DATE_INPUT_FORMATS =
"%Y-%m-%d", "%m/%d/%Y", "%m/%d/%y", # '2006-10-25', '10/25/2006',
'10/25/06'
]
is reformatted to the:
DATE_INPUT_FORMATS =
"%Y-%m-%d",
"%m/%d/%Y",
"%m/%d/%y", # '2006-10-25', '10/25/2006', '10/25/06'
]
This reformats affected entries to multiple lines with corresponding
comments.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33476#comment:1>
Comment (by Carlton Gibson <carlton.gibson@…>):
In [changeset:"0c06819caae202f1a7aa96d2da2affb2400fef10" 0c06819c]:
{{{
#!CommitTicketReference repository=""
revision="0c06819caae202f1a7aa96d2da2affb2400fef10"
[4.0.x] Refs #33476 -- Used vertical hanging indentation for format lists
with inline comments.
Lists with multiple values and comments per-line are reformatted
by Black to multiple lines with a single comment. For example:
DATE_INPUT_FORMATS =
"%Y-%m-%d", "%m/%d/%Y", "%m/%d/%y", # '2006-10-25', '10/25/2006',
'10/25/06'
]
is reformatted to the:
DATE_INPUT_FORMATS =
"%Y-%m-%d",
"%m/%d/%Y",
"%m/%d/%y", # '2006-10-25', '10/25/2006', '10/25/06'
]
This reformats affected entries to multiple lines with corresponding
comments.
Backport of ca88caa1031c0de545d82de8d90dcae0e03651fb from main
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33476#comment:2>
Comment (by Nikita Marchant):
The DEP also
[https://github.com/django/deps/blob/main/accepted/0008-black.rst#specification
mentions that] "All code Django generates will also be Black-formatted
(startproject, migrations, inspectdb, etc.)" but there is nothing in the
"Reference Implementation" part that specifies how to do this.
There is a [https://groups.google.com/g/django-
developers/c/AECpvCTtK_4/m/6iL3eIUCBAAJ mention on the mailing-list] of
maybe using django-migrations-formatter. Would upstreaming the feature be
a welcome contribution (the license - BSD - matches) for this ticket ?
Also, would reformatting files in `django/conf/project_template/` and
`django/conf/app_template/` (by hand, they are not all valid python) to
follow Black style be a welcome contribution ? (Note that this can not
guarantee that the generated files will be Black formatted, especially
when templates variables are very long and Black would want to wrap lines)
--
Ticket URL: <https://code.djangoproject.com/ticket/33476#comment:3>
Comment (by Mariusz Felisiak):
Replying to [comment:3 Nikita Marchant]:
> The DEP also
[https://github.com/django/deps/blob/main/accepted/0008-black.rst#specification
mentions that] "All code Django generates will also be Black-formatted
(startproject, migrations, inspectdb, etc.)" but there is nothing in the
"Reference Implementation" part that specifies how to do this.
>
> There is a [https://groups.google.com/g/django-
developers/c/AECpvCTtK_4/m/6iL3eIUCBAAJ mention on the mailing-list] of
maybe using django-migrations-formatter. Would upstreaming the feature be
a welcome contribution (the license - BSD - matches) for this ticket ?
>
> Also, would reformatting files in `django/conf/project_template/` and
`django/conf/app_template/` (by hand, they are not all valid python) to
follow Black style be a welcome contribution ? (Note that this can not
guarantee that the generated files will be Black formatted, especially
when templates variables are very long and Black would want to wrap lines)
As far as I'm aware, we'd like to use a different approach, i.e. run
`black` on generated files but only when it's installed.
--
Ticket URL: <https://code.djangoproject.com/ticket/33476#comment:4>
Comment (by GitHub <noreply@…>):
In [changeset:"c5cd8783825b5f6384417dac5f3889b4210b7d08" c5cd8783]:
{{{
#!CommitTicketReference repository=""
revision="c5cd8783825b5f6384417dac5f3889b4210b7d08"
Refs #33476 -- Refactored problematic code before reformatting by Black.
In these cases Black produces unexpected results, e.g.
def make_random_password(
self,
length=10,
allowed_chars='abcdefghjkmnpqrstuvwxyz' 'ABCDEFGHJKLMNPQRSTUVWXYZ'
'23456789',
):
or
cursor.execute("""
SELECT ...
""",
[table name],
)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33476#comment:5>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"d55a1e5809b424907528af42bfdfc2991ef11651" d55a1e5]:
{{{
#!CommitTicketReference repository=""
revision="d55a1e5809b424907528af42bfdfc2991ef11651"
[4.0.x] Refs #33476 -- Refactored problematic code before reformatting by
Black.
In these cases Black produces unexpected results, e.g.
def make_random_password(
self,
length=10,
allowed_chars='abcdefghjkmnpqrstuvwxyz' 'ABCDEFGHJKLMNPQRSTUVWXYZ'
'23456789',
):
or
cursor.execute("""
SELECT ...
""",
[table name],
)
Backport of c5cd8783825b5f6384417dac5f3889b4210b7d08 from main.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33476#comment:6>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"ba94488196a74e312177ef2621fbd427956836ef" ba94488]:
{{{
#!CommitTicketReference repository=""
revision="ba94488196a74e312177ef2621fbd427956836ef"
Refs #33476 -- Adjusted docs and config files for Black.
Co-authored-by: Mariusz Felisiak <felisiak...@gmail.com>
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33476#comment:7>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"cf5e61cf6c721121abf7347baff3d41a0ad3c23e" cf5e61cf]:
{{{
#!CommitTicketReference repository=""
revision="cf5e61cf6c721121abf7347baff3d41a0ad3c23e"
Refs #33476 -- Added GitHub action to run black linter.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33476#comment:8>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"7119f40c9881666b6f9b5cf7df09ee1d21cc8344" 7119f40c]:
{{{
#!CommitTicketReference repository=""
revision="7119f40c9881666b6f9b5cf7df09ee1d21cc8344"
Refs #33476 -- Refactored code to strictly match 88 characters line
length.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33476#comment:11>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"f68fa8b45dfac545cfc4111d4e52804c86db68d3" f68fa8b]:
{{{
#!CommitTicketReference repository=""
revision="f68fa8b45dfac545cfc4111d4e52804c86db68d3"
Refs #33476 -- Changed quotation marks in
DebugViewTests.test_template_exceptions().
This prevents a failure after reformatting the code with Black.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33476#comment:9>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"9c19aff7c7561e3a82978a272ecdaad40dda5c00" 9c19aff7]:
{{{
#!CommitTicketReference repository=""
revision="9c19aff7c7561e3a82978a272ecdaad40dda5c00"
Refs #33476 -- Reformatted code with Black.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33476#comment:10>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"b9fee0f849a88091fb0615dd433b9e54f05b32c5" b9fee0f8]:
{{{
#!CommitTicketReference repository=""
revision="b9fee0f849a88091fb0615dd433b9e54f05b32c5"
Refs #33476 -- Ignored formatting changes in git blame.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33476#comment:12>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"9a7755fa2dde3434e7f0778e8641bac919be0649" 9a7755f]:
{{{
#!CommitTicketReference repository=""
revision="9a7755fa2dde3434e7f0778e8641bac919be0649"
[4.0.x] Refs #33476 -- Adjusted docs and config files for Black.
Co-authored-by: Mariusz Felisiak <felisiak...@gmail.com>
Backport of ba94488196a74e312177ef2621fbd427956836ef from main
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33476#comment:13>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"e73ce08888e6f34d3f050377cfd2fbb733be94a9" e73ce088]:
{{{
#!CommitTicketReference repository=""
revision="e73ce08888e6f34d3f050377cfd2fbb733be94a9"
[4.0.x] Refs #33476 -- Changed quotation marks in
DebugViewTests.test_template_exceptions().
This prevents a failure after reformatting the code with Black.
Backport of f68fa8b45dfac545cfc4111d4e52804c86db68d3 from main
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33476#comment:15>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"6a682b38e75d4c975b4c4493565a59f1bc14397c" 6a682b3]:
{{{
#!CommitTicketReference repository=""
revision="6a682b38e75d4c975b4c4493565a59f1bc14397c"
[4.0.x] Refs #33476 -- Reformatted code with Black.
Backport of 9c19aff7c7561e3a82978a272ecdaad40dda5c00 from main.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33476#comment:16>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"3278c31fa59b41d03aea167f4cf85f4ddf7f848d" 3278c31f]:
{{{
#!CommitTicketReference repository=""
revision="3278c31fa59b41d03aea167f4cf85f4ddf7f848d"
[4.0.x] Refs #33476 -- Refactored code to strictly match 88 characters
line length.
Backport of 7119f40c9881666b6f9b5cf7df09ee1d21cc8344 from main.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33476#comment:17>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"224c64a7338b9fa623fe24d49375a9f4afe02cf3" 224c64a]:
{{{
#!CommitTicketReference repository=""
revision="224c64a7338b9fa623fe24d49375a9f4afe02cf3"
[4.0.x] Refs #33476 -- Added GitHub action to run black linter.
Backport of cf5e61cf6c721121abf7347baff3d41a0ad3c23e from main
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33476#comment:14>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"f2d3e1fc8c1dc474683aceca0634dab7113a5fbf" f2d3e1fc]:
{{{
#!CommitTicketReference repository=""
revision="f2d3e1fc8c1dc474683aceca0634dab7113a5fbf"
[4.0.x] Refs #33476 -- Ignored formatting changes in git blame.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33476#comment:18>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"d113b5a837f726d1c638d76c4e88445e6cd59fd5" d113b5a]:
{{{
#!CommitTicketReference repository=""
revision="d113b5a837f726d1c638d76c4e88445e6cd59fd5"
Refs #33476 -- Made management commands use black.
Run black on generated files, if it is available on PATH.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33476#comment:19>
* status: assigned => closed
* resolution: => fixed
--
Ticket URL: <https://code.djangoproject.com/ticket/33476#comment:20>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"fe3518d25edd69b782339729080b0295a8a33952" fe3518d2]:
{{{
#!CommitTicketReference repository=""
revision="fe3518d25edd69b782339729080b0295a8a33952"
Refs #33476 -- Mentioned black in docs about pre-commit checks.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33476#comment:21>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"be4a106930e27fe6d8f172b7283e064bb07c33b5" be4a1069]:
{{{
#!CommitTicketReference repository=""
revision="be4a106930e27fe6d8f172b7283e064bb07c33b5"
[4.0.x] Refs #33476 -- Mentioned black in docs about pre-commit checks.
Backport of fe3518d25edd69b782339729080b0295a8a33952 from main
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33476#comment:22>
Comment (by GitHub <noreply@…>):
In [changeset:"d11944be3466ce8e874474949134811ed6e90e92" d11944be]:
{{{
#!CommitTicketReference repository=""
revision="d11944be3466ce8e874474949134811ed6e90e92"
Refs #33476 -- Added warning to optimizemigration/squashmigrations
commands when black cannot be applied.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33476#comment:23>
Comment (by Carlton Gibson <carlton@…>):
In [changeset:"b1005c0e4029c23f4e718ce0a7afdfa926c095de" b1005c0]:
{{{
#!CommitTicketReference repository=""
revision="b1005c0e4029c23f4e718ce0a7afdfa926c095de"
Refs #33476 -- Prevented formatting of .py-tpl files with black by pre-
commit.
When using `pre-commit run --all-files`, files explicitly passed to
black are processed even if they don't match the `include` configuration
option. For some reason, (only) one of the `*.py-tpl` files is picked up
by pre-commit. We can avoid this by explicitly excluding certain
patterns of files for the black hook in the pre-commit configuration.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33476#comment:25>
Comment (by Carlton Gibson <carlton@…>):
In [changeset:"fa948980341b43e76140ac78dcff30bf0bd65369" fa948980]:
{{{
#!CommitTicketReference repository=""
revision="fa948980341b43e76140ac78dcff30bf0bd65369"
Refs #33476 -- Used black's force-exclude instead of extend-exclude.
When using `pre-commit run --all-files`, because the filename is passed
explicitly, the file referred to in `extend-exclude` is not properly
excluded. Use `force-exclude` instead to say we really mean it.
See https://github.com/psf/black/issues/438.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33476#comment:24>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"097e3a70c1481ee7b042b2edd91b2be86fb7b5b6" 097e3a7]:
{{{
#!CommitTicketReference repository=""
revision="097e3a70c1481ee7b042b2edd91b2be86fb7b5b6"
Refs #33476 -- Applied Black's 2023 stable style.
Black 23.1.0 is released which, as the first release of the year,
introduces the 2023 stable style. This incorporates most of last year's
preview style.
https://github.com/psf/black/releases/tag/23.1.0
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33476#comment:26>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"80aae8343939e849100db87b1c9615f32b38ea0b" 80aae834]:
{{{
#!CommitTicketReference repository=""
revision="80aae8343939e849100db87b1c9615f32b38ea0b"
[4.2.x] Refs #33476 -- Applied Black's 2023 stable style.
Black 23.1.0 is released which, as the first release of the year,
introduces the 2023 stable style. This incorporates most of last year's
preview style.
https://github.com/psf/black/releases/tag/23.1.0
Backport of 097e3a70c1481ee7b042b2edd91b2be86fb7b5b6 from main
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33476#comment:27>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"a637d0bd22665edfe7af40b4da3297462ec3c9cf" a637d0bd]:
{{{
#!CommitTicketReference repository=""
revision="a637d0bd22665edfe7af40b4da3297462ec3c9cf"
[4.1.x] Refs #33476 -- Applied Black's 2023 stable style.
Black 23.1.0 is released which, as the first release of the year,
introduces the 2023 stable style. This incorporates most of last year's
preview style.
https://github.com/psf/black/releases/tag/23.1.0
Backport of 097e3a70c1481ee7b042b2edd91b2be86fb7b5b6 from main.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33476#comment:28>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"e565a5cd187197a6349e55d7a4c68a9e12e2fd20" e565a5cd]:
{{{
#!CommitTicketReference repository=""
revision="e565a5cd187197a6349e55d7a4c68a9e12e2fd20"
[4.0.x] Refs #33476 -- Applied Black's 2023 stable style.
Black 23.1.0 is released which, as the first release of the year,
introduces the 2023 stable style. This incorporates most of last year's
preview style.
https://github.com/psf/black/releases/tag/23.1.0
Backport of 097e3a70c1481ee7b042b2edd91b2be86fb7b5b6 from main.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33476#comment:29>