formatters-python

Format Python code using autopep8, black, isort, or yapf (or all)


Keywords
apm, atom, autopep8, beautifier, beautify, black, format, formatter, formatters, isort, prettify, pretty, python, yapf
License
MIT
Install
apm install formatters-python@1.0.1

Documentation

Python Formatters for Atom Editor

apm apm apm badge

Supports autopep8, black, isort, yapf for formatting Python code.

Features

  • Format-in-buffer/Format-on-save using any of these 4 formatters, in any combination provided in settings
  • Can specify command line arguments or specify local or global config files to look for
  • Quick toggle for format-on-save along with format order info in status bar
  • Show busy signal while formatting (if installed)

Usage

  • Make sure you have installed the required formatters.

    Eg. If you want to use isort & black, run pip install isort black.

  • After installing in system/pyenv/venv/conda, run which <formatter> & add the binary path to package settings.

    Eg. Running which black gives /usr/local/bin/black. Then add this path in package settings in the "black" section.

  • Define format order for :format command and/or save order for auto-format on save, if required.

If the path for any formatter is not provided, it will not be used.

Configuration

Any of the formatters can be configured in 4 ways:

  • You can provide command line arguments which are always passed.
  • You can provide a list of local config file names which will be explicitly passed to the formatter. Files will be looked for in parent directories in the repo (i.e. until a ".git" folder is found).
  • You can provide the path of a global file which will be explicitly passed to the formatter, if none of the specified local config files are found.
  • Don't specify any of them & let the formatter auto determine the config settings to use.

Please note that command line arguments may or may not override the config files, explicitly passed or otherwise. Please consult formatter documentation for the exact behaviour.

Commands

  • formatters-python:autopep8
  • formatters-python:black
  • formatters-python:isort
  • formatters-python:yapf
  • formatters-python:format
  • formatters-python:toggle-format-on-save

Thanks

Influenced by atom-python-black, prettier-atom.