Giter Club home page Giter Club logo

python-fast-autoformat's Introduction

PFA (Python Fast Autoformat)

An autoformatter should be three things:

  • Fast: Run quickly so that you can afford to run the autoformatter on a large code base without ever having to wait for the autoformat to complete.
  • Consistent: Running the autoformatter a second time won't change the output. Code will run the same before and after the autoformatter is run. Trivial whitespace changes will be reverted.
  • Pretty: Output looks nice and preferably follows PEP8.

PFA chooses to be Fast and Consistent, but sacrifices Pretty output in favor of speed.

Installation and Usage

To create the executable file pfa, run

make

Afterwards you can copy it into PATH, say to /usr/bin or ~/bin/.

There are two ways to run the program. If the executable file name does not end in "i", i.e. with

pfa that_python_script.py

then the formatted file will be dumped to standard output. If you make a symlink from pfa to pfai and run the latter like

pfai that_python_script.py scriptus_secundus.py

then all files listed as arguments will be formatted in place.

FAQ

  • Why is PFA written in C? The startup time for the Python interpreter is often longer than it takes to run pfa on a 2000 line file.

  • How fast is it? The other popular Python formatters are yapf and autopep8. Formatting about 120KB of python code in place for the second time in a row with the following commands,

      yapf -i bx.py
      autopep8 -i bx.py
      pfai bx.py
    

    one finds that yapf takes 14.0 seconds; autopep8 takes 1.8 seconds; and pfai completes in 0.020 seconds, less than the time it takes to press Enter.

  • I have a change to contribute. Will it be accepted?: Yes, as long as pfa still runs in O(n) for even pathological input.

python-fast-autoformat's People

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.