https://github.com/myint/pyformat
Formats Python code to follow a consistent style
https://github.com/myint/pyformat
formatter python
Last synced: 7 months ago
JSON representation
Formats Python code to follow a consistent style
- Host: GitHub
- URL: https://github.com/myint/pyformat
- Owner: myint
- Created: 2013-03-24T21:45:30.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2024-01-01T00:20:53.000Z (almost 2 years ago)
- Last Synced: 2025-04-02T13:01:52.572Z (7 months ago)
- Topics: formatter, python
- Language: Python
- Homepage: https://pypi.python.org/pypi/pyformat
- Size: 79.1 KB
- Stars: 94
- Watchers: 7
- Forks: 10
- Open Issues: 7
-
Metadata Files:
- Readme: README.rst
- Authors: AUTHORS.rst
Awesome Lists containing this project
- awesome-python-code-formatters - pyformat
- starred-awesome - pyformat - Formats Python code to follow a consistent style (Python)
README
========
pyformat
========
.. image:: https://travis-ci.org/myint/pyformat.svg?branch=master
:target: https://travis-ci.org/myint/pyformat
:alt: Build status
*pyformat* formats Python code to follow a consistent style.
Features
========
- Formats code to follow the PEP 8 style guide (using autopep8_).
- Removes unused imports (using autoflake_).
- Formats docstrings to follow PEP 257 (using docformatter_).
- Makes strings all use the same type of quote where possible (using unify_).
Installation
============
From pip::
$ pip install --upgrade pyformat
Example
=======
After running::
$ pyformat --in-place example.py
This code:
.. code-block:: python
def launch_rocket ():
"""Launch
the
rocket. Go colonize space."""
def factorial(x):
'''
Return x factorial.
This uses math.factorial.
'''
import math
import re
import os
return math.factorial( x );
def print_factorial(x):
"""Print x factorial"""
print( factorial(x) )
def main():
"""Main
function"""
print_factorial(5)
if factorial(10):
launch_rocket()
Gets formatted into this:
.. code-block:: python
def launch_rocket():
"""Launch the rocket.
Go colonize space.
"""
def factorial(x):
"""Return x factorial.
This uses math.factorial.
"""
import math
return math.factorial(x)
def print_factorial(x):
"""Print x factorial."""
print(factorial(x))
def main():
"""Main function."""
print_factorial(5)
if factorial(10):
launch_rocket()
.. _autoflake: https://github.com/myint/autoflake
.. _autopep8: https://github.com/hhatto/autopep8
.. _docformatter: https://github.com/myint/docformatter
.. _unify: https://github.com/myint/unify