Skip to main content

automatic code formatter for python following pep8 using baron FST, like gofmt

Project description

PyFmt

Pyfmt is an autoformatting source code tool for python, in more or less the same spirit than gofmt. It follows the pep8 and uses Baron to do its work in one pass.

``Pyfmt`` is in its early stage of developpement, it already do a good job at formatting most of python code but it doesn’t handle yet splitting a too long line and might end up putting back into one line a line that you have split. But it should be fine for ~80% of the cases.

Feedback is very welcome.

You can see it in action here.

Installation

PyFmt can be installed using $ pip install pyfmt

Usage

pyfmt file.py  # output to standard output
pyfmt -i file.py  # replace the content of the file, like -i of sed

From python:

from pyfmt import format_code

format_code(source_code)

Community

You can reach us on irc.freenode.net#baron

Tests

You can run the tests using $ py.test test_pyfmt.py

Operations

Things that pyfmt do (if it’s not already done in the code):

  • render ALL nodes of the python language according to the pep8

  • if a datastructure is indented, keep the indentation and indent it according to the pep8

  • put 2 spaces before comments after code, put a space after the “#” of the comment (don’t do for shebang)

  • split compound statements written on one line on two lines (example: if a: pass -> if a:\n pass”, same for every other statements that wait for a block of code)

  • replace stuff by repr(stuff)

  • split multiple import across multiple lines

  • replace tabs with space

  • correctly indent the whole file using 4 spaces

  • convert windows '\r\n’ to '\n'

  • if not present, put two blank lines around functions or class definitions at the root level of the file

  • if not present, put one blank line around method definition in a class

  • replace <> with !=

Things that pyfmt don’t do or don’t do yet and that can be annoying:

  • properly formatting the content of a “from x import (lot of stuff)”

  • properly splitting too long lines, it may ends up putting back on one line a splited line

  • removing extra blank lines

Changelog

0.1 (2014-09-07)

  • Init

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

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

Source Distribution

pyfmt-0.1.tar.gz (6.7 kB view details)

Uploaded Source

Built Distributions

pyfmt-0.1-py2.py3-none-any.whl (8.9 kB view details)

Uploaded Python 2 Python 3

pyfmt-0.1-py2.7.egg (6.4 kB view details)

Uploaded Source

File details

Details for the file pyfmt-0.1.tar.gz.

File metadata

  • Download URL: pyfmt-0.1.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pyfmt-0.1.tar.gz
Algorithm Hash digest
SHA256 c67708e6c3117af9cd4756d4fa75493e9e827d8efa176291a79467ffd0f9b4ec
MD5 13cd71ab5bbef3994a1ece1b6e1346a0
BLAKE2b-256 5e79c088f551dbc968f5c89ff9409efac84354a7ff7a42b96ca4d4ef3b63faed

See more details on using hashes here.

File details

Details for the file pyfmt-0.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for pyfmt-0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 de35a46a688fb831d3e9370f85876614d4f4adf2349c768387c039ec2618fa1d
MD5 c35baaffecc4b5f919fd915611c2e933
BLAKE2b-256 03c2c71be43b8740d342519c037504f37ae268413e03864384e68e03ae1c54b8

See more details on using hashes here.

File details

Details for the file pyfmt-0.1-py2.7.egg.

File metadata

  • Download URL: pyfmt-0.1-py2.7.egg
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pyfmt-0.1-py2.7.egg
Algorithm Hash digest
SHA256 5015b2724c783ca8b35cdbce8a239cbb9a4fdc74aee84e0f82255fcdb95d5a70
MD5 c6e94d10808baf80eb64369802a80a5d
BLAKE2b-256 da2f3a4af5b4b0a0399ec7311ae50686902ad45435b815d407de3378bd02f140

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