Less uncompromising Python code formatter
Project description
gray
Less uncompromising Python code formatter.
Gray stands on the shoulders of giants:
- isort - imports sorting and more
- pyupgrade - automatically upgrades syntax for newer versions of Python
- add-trailing-comma
- unify - unify quotes style
Usage
usage:
gray myapp.py
gray myproj/ tests/
gray --log-level debug --formatters isort,unify ~/app
Less uncompromising Python code formatter. Args that start with '--' (eg.
--pool-size) can also be set in a config file (/Users/dizballanze/.gray or
/etc/gray.conf or ./gray.conf). Config file syntax allows: key=value,
flag=true, stuff=[a,b,c] (for details, see syntax at https://goo.gl/R74nmi).
If an arg is specified in more than one place, then commandline values
override config file values which override defaults.
positional arguments:
paths Paths to format (default: (PosixPath('.'),))
optional arguments:
-h, --help show this help message and exit
--pool-size POOL_SIZE
process pool size (default: 8)
--do-not-detect-venv Don't try to detect virtualenv (default: False)
Logging options:
--log-level {debug,info,warning,error,fatal}
--log-format {stream,color,json,syslog}
Formatters options:
-f FORMATTERS, --formatters FORMATTERS
Enabled formatters separated by comma (default: add-
trailing-comma,isort,pyupgrade,unify)
--min-python-version MIN_PYTHON_VERSION
Minimum python version to support (default: (3, 7))
pyupgrade options:
--pyupgrade-keep-percent-format
Do not upgrade percent formatted strings to f-strings
(default: False)
unify options:
--unify-quote UNIFY_QUOTE
preferred quote (default: ")
isort options:
--isort-line-length ISORT_LINE_LENGTH
isort section (default: 80)
--isort-virtual-env ISORT_VIRTUAL_ENV
virtual env path (default:
/Users/dizballanze/apps/gray/env)
--isort-include-trailing-comma ISORT_INCLUDE_TRAILING_COMMA
include a trailing comma on multi line imports
(default: 1)
--isort-lines-after-imports ISORT_LINES_AFTER_IMPORTS
empty lines after imports (default: 2)
Git Hook
You can setup gray formatting before each commit with pre-commit git hook.
Add following file to .git/hooks/pre-commit
and make it executable with
chmod +x .git/hooks/pre-commit
.
#!/usr/bin/env python
from gray.hooks import git_pre_commit
exit(git_pre_commit(stop_on_modify=True))
If stop_on_modify
argument is True
, hook will prevent commit if there are
any unstaged changes in files you about to commit.
Otherwise, any unstaged changes in this files will be added to the index by the hook.
Config file
Gray is looking for config file in ./gray.conf
, /etc/gray.conf
or ~/.gray
.
Example of grayconf:
formatters = add-trailing-comma,isort,unify
min-python-version = 3.5
Features
- TODO
History
0.4.0
- Minimum python version option
- Pyupgrade options
- Detecting and skipping virtualenv
0.3.0
- Multiprocessing support (by @mosquito)
0.2.0
- Pre-commit hook
- Some formating options
0.1.0 (2020-04-06)
- First release on PyPI.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file gray-0.4.2.tar.gz
.
File metadata
- Download URL: gray-0.4.2.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26359c906b69ec067ab88513496b18a27ae53e7dca6b1cd8ba20bb97ca89a895 |
|
MD5 | 3cef2ef1e3f4c9af71371e1f626c055f |
|
BLAKE2b-256 | 46f963f319083f6cdb088d04ae461f4d421e08085248e9861831d149d20ab05d |
File details
Details for the file gray-0.4.2-py2.py3-none-any.whl
.
File metadata
- Download URL: gray-0.4.2-py2.py3-none-any.whl
- Upload date:
- Size: 11.5 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | df966eb8f1c7c751a2cbd34705adf2c41d1725e81b8969181682fadb3e9d7af0 |
|
MD5 | 5cac18444699be4ab9d4ae4c43b73c68 |
|
BLAKE2b-256 | 0fd658bce6fa1a284bef829c33303ab8b1c66a7f3267dc1211c1458fdf13a07d |