CoBlack
CoBlack is a Black-compliant formatter/rewrapper for Python comments.
Example code
Before:
def care_for(self, favorite_plant):
self.sing_a_lullaby_to(favorite_plant) # This should help them grow. Note that this comment is too long to fit on one line, given the recommended line length.
favorite_plant.water(100 * mL) # Prevent dehydration.
After:
def care_for(self, favorite_plant):
self.sing_a_lullaby_to(favorite_plant) # This should help them grow. Note that this
# # comment is too long to fit on one line,
# # given the recommended line length.
favorite_plant.water(100 * mL) # Prevent dehydration.
The extra #'s at the beginning of each line are necessary to be Black-compliant:
If they were not there, Black would pull the comments to the start of the line,
destroying the alignment, and making the code look messier.
(Compare to how the naive way of wrapping comments looks).
Installation
$ pip install coblack
(Upgrade an existing installation of CoBlack by adding the --upgrade/-U flag).
Usage
In your terminal:
$ coblack my_file.py
This wraps & fills out multiline comments, and passes the result through black.
The file is edited in-place.
Get info on additional options (such as eg -l to set the line length)
with coblack -h.
IDE integration
For PyCharm, create a new External Tool, as follows:
Then assign a keyboard shortcut to this tool.
This enables you to format your files quickly and often during coding sessions.
In VS Code, you'd create a new Task, in a similar fashion.
Python API
import coblack
coblack.format_file("path/to/my_file.py") # You can also pass a `pathlib.Path`.
Appendix
Naive way of wrapping comments
def care_for(self, favorite_plant):
self.sing_a_lullaby_to(favorite_plant) # This should help them grow. Note that this
# comment is too long to fit on one line, given the recommended line length.
favorite_plant.water(100 * mL) # Prevent dehydration.
Other comment styles
On own line, before code:
def care_for(self, favorite_plant):
# This should help them grow. Note that this comment is too long to fit on one line,
# given the recommended line length.
self.sing_a_lullaby_to(favorite_plant)
# Prevent dehydration.
favorite_plant.water(100 * mL)
On own line, after code:
def care_for(self, favorite_plant):
self.sing_a_lullaby_to(favorite_plant)
# This should help them grow. Note that this comment is too long to fit on one line,
# given the recommended line length.
favorite_plant.water(100 * mL)
# Prevent dehydration.
These styles don't need CoBlack; a vanilla rewrapper like any of the following will do:
- The Wrap to Column plugin for PyCharm;
- The Rewrap extension for VS Code;
- The "Wrap Paragraph at Ruler" command in Sublime Text (
Alt-QorAlt-⌘-Q) ; - The
fill-paragraphcommand in Emacs; or - The
gqoperator in Vim.
Metadata
Release files for coblack 0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| coblack-0.2.tar.gz | 87.7 kB | Without provenance | Details for coblack-0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| coblack-0.2-py3-none-any.whl | Python 3 | none | any | Details for coblack-0.2-py3-none-any.whl |
Total release size: 97.1 kB
Release files / coblack-0.2.tar.gz
| Download URL | coblack-0.2.tar.gz |
|---|---|
| Size | 87.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c29ebec8d1ee9d681904d7262b158211ce6b991a7f2a0c25a181d98da1948315
|
|
BLAKE2b-256 checksum How to use checksums |
90283f1ae434f8fb866a38e71acbf522f3f2893b06e3570887d751b0d19994e2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0.post20200518 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3
|
Release files / coblack-0.2-py3-none-any.whl
| Download URL | coblack-0.2-py3-none-any.whl |
|---|---|
| Size | 9.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c294b902fc7e849719feec747bfa379602128c335e8872f5409f9ee7c96638ff
|
|
BLAKE2b-256 checksum How to use checksums |
df7c799cab316a56269f75991086af58010cd1b11860848a16214056ead8e63c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0.post20200518 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3
|
Security for coblack 0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.