Skip to main content

Less uncompromising Python code formatter

Project description

gray

Less uncompromising Python code formatter.

Gray stands on the shoulders of giants:

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.
--log-level) 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

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)

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.

Features

  • TODO

History

0.2.0

  • Pre-commit hook
  • Some formating options

0.1.0 (2020-04-06)

  • First release on PyPI.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gray-0.2.1.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

gray-0.2.1-py2.py3-none-any.whl (10.1 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file gray-0.2.1.tar.gz.

File metadata

  • Download URL: gray-0.2.1.tar.gz
  • Upload date:
  • Size: 7.0 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

Hashes for gray-0.2.1.tar.gz
Algorithm Hash digest
SHA256 6288afbb06740bad529e48c2d993f0ff84d7707f21fb731aa83512d1fcb8d86c
MD5 ad2ee7a149f9ec0c679d45099990ddf1
BLAKE2b-256 ca41504ee2757481518d2fa8257a92879b774ef8a1200fb778984bf53152e72f

See more details on using hashes here.

File details

Details for the file gray-0.2.1-py2.py3-none-any.whl.

File metadata

  • Download URL: gray-0.2.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 10.1 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

Hashes for gray-0.2.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 1e9e9544a9b5198de302e517811e1fea2293ed47fd1f798b6d7724cb3cd13e36
MD5 66809dda447219909c1a7368ea2c86ad
BLAKE2b-256 4c9bc97755b803349f1aae83f99af543a58ca7c85004f2d98e3b95ba4474410d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page