StraitJacket: Another Uncompromising Code Formatter for Python
StraitJacket is a wrapper around black which implements post processing to perform automatic code alignment.
Project/Repo:
Code Quality/CI:
| Name | role | since | until |
|---|---|---|---|
| Manuel Barkhau (mbarkhau@gmail.com) | author/maintainer | 2018-10 | - |
Alignment
Example of automatic alignment.
class TokenType(enum.Enum): # class TokenType(enum.Enum):
INDENT = 0 # INDENT = 0
SEPARATOR = 1 # SEPARATOR = 1
CODE = 2 # CODE = 2
Indent = str # Indent = str
RowIndex = int # RowIndex = int
ColIndex = int # ColIndex = int
OffsetWidth = int # OffsetWidth = int
TokenTable = typ.List[TokenRow] # TokenTable = typ.List[TokenRow]
Usage
Usage is exactly the same as for black, except that the command is named sjfmt.
$ pip install straitjacket
$ sjfmt --help
Usage: sjfmt [OPTIONS] [SRC]...
Another uncompromising code formatter.
Options:
-l, --line-length INTEGER How many characters per line to allow.
[default: 88]
--py36 Allow using Python 3.6-only syntax on all
Editor/Tooling Integration
Plugins for your editor usually support setting a custom path to black. You can simply point to sjfmt instead.
Unix
$ which sjfmt
/home/user/miniconda3/envs/py36/bin/sjfmt
$ which sjfmtd
/home/user/miniconda3/envs/py36/bin/sjfmtd
Windows
C:\Users\Username>where sjfmt
C:\Python37\Scripts\sjfmt.exe
or
PS C:\Users\Username> (gcm sjfmt).Path
C:\Python37\Scripts\sjfmt.exe
sublack:
{
"black_command": "C:/Python37/Scripts/sjfmt.exe",
"black_line_length": 100,
// ...
}
Document formatting can be triggered with Ctrl+Alt+F.
vscode python extension
{
"python.formatting.provider": "black",
"python.formatting.blackPath": "C:\\Python37\\Scripts\\sjfmt.exe",
"python.formatting.blackArgs": [
"--line-length", "100",
"--py36",
"--skip-string-normalization"
],
}
Document formatting can be triggered with Shift+Alt+F.
BlackPycharm
Install the plugin black-pycharm, which can be found in
Settings > Plugins > Brows Repositories. You may have to
restart PyCharm for the plugin to load.
To configure the path, go to Settings > Tools > BlackPycharm Configuration and set Path to Black executable to the location
of the sjfmt binary.
You can reformat your code using Ctrl + Shift + A to access the
Find Action panel. The name of the action to format your code
is Reformat code (BLACK). You may want to rebind this action,
at least in my setup the default binding didn't seem to work.
Flake8
By the nature of this plugin, certain flake8 codes will be
violated. This is an excerpt from what you might put in your
setup.cfg to ignore these:
[flake8]
ignore =
# No whitespace after paren open "("
E201
# No whitespace before paren ")"
E202
# Whitespace before ":"
E203
# Multiple spaces before operator
E221
# Multiple spaces after operand
E222
# Multiple spaces after ':'
E241
# Multiple spaces before keyword
E272
# Spaces around keyword/parameter equals
E251
Changelog for straitjacket
v202206.1026
- Update pinned black==21.12b0
Unfortunately we depend on the ability to monkey-patch
black.format_str. Due to mypyc compilation, this no longer
works, starting with black==22.1.0.
v202206.1025
- Update pinned black==22.3.0
v202202.1024
- Update pinned black==21.12b0
v202112.1023
- Update pinned black>=21.12b0
v202109.1022
- Update pinned black to 21.9b0
v202109.1021
- Update pinned black to 21.8b0
v202107.1020
- Update pinned black to 21.7b0
v202106.1019
- Remove vendored black (monkey patch instead)
- Update pinned black to 21.6b0
v202104.1018
- Update vendored black to 21.4b2
v202104.1017
- Update vendored black to 21.4b1
v202008.1016
- Bugfix: Bad path handling at root level.
v202008.1015
- Update vendored black to 20.8b1
v202008.1014
- Vendor black from master
- Fix issue with multiprocessing/fork on MacOS
v201910.0011-beta
- Update for release of black==19.10b0
v201904.0010-beta
- Update for release of black==19.3b0
v201812.0007-alpha
- TLDR: more bugfixes and updated documentation
v201812.0006-alpha
TLDR: no major changes, just bug fixes.
- Fixed #1: Disable right alignment of numbers when not preceded by a number.
- Fixed #3: Disable alignment when preceded by a multiline string.
- Fixed #4: Excessive whitespace in non aligned context.
- Fixed #8: Double and single quotes around strings not consistent
v201810.0004-alpha
- Initial release
Release files for straitjacket 202206.1026
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| straitjacket-202206.1026.tar.gz | 20.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| straitjacket-202206.1026-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 100.4 kB
Release files / straitjacket-202206.1026.tar.gz
| Download URL | straitjacket-202206.1026.tar.gz |
|---|---|
| Size | 20.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
36100096a1c3fb88bd5404de17049d2cb5f42d2ad72c48d28d159d74963c6216
|
|
BLAKE2b-256 checksum How to use checksums |
b76b85f6508ba8bff1a0b2801add5cb1c5f7ba97977f7acfd74dfd1c53e69b07
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.2
|
Release files / straitjacket-202206.1026-py3-none-any.whl
| Download URL | straitjacket-202206.1026-py3-none-any.whl |
|---|---|
| Size | 80.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
407dfa4169d674089e671eedd3f267f6435127b686ce7284aa5060d1dc1320c8
|
|
BLAKE2b-256 checksum How to use checksums |
9d6caf8893895a4ccaa2409851fc36a57cfa065953f2556f5fa14b5eac7f207b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.2
|