GithubHelp home page GithubHelp logo

auto-pep8-commit's Introduction

Auto PEP8 Commit

What

This repo is a simple Python script, which does:

  • Run pycodestyle on your source code
  • Group violations by Error Code
  • Sort Error Code by violation count, smaller first
  • Loop through each Error Code
  • Run autopep8 for that Error Code
  • Fix each violation in place
  • Commit each affected file to git

Why

One day, your team decide to follow PEP8 code style for Python. You run pycodestyle, and discover thousands of errors. It's not possible to do it manually, in limited time frame.

An example in my project:

...
605   E402 module level import not at top of file
606   E226 missing whitespace around arithmetic operator
706   E122 continuation line missing indentation or outdented
849   E203 whitespace before ':'
916   F401 'time' imported but unused
1038  E127 continuation line over-indented for visual indent
1171  E231 missing whitespace after ','
1258  E221 multiple spaces before operator
1564  E251 unexpected spaces around keyword / parameter equals
1759  E302 expected 2 blank lines, found 1
2099  F405 'normalise_int32' may be undefined, or defined from star imports: samba.common
12083 W191 indentation contains tabs
12448 E501 line too long (92 > 79 characters)
...

You decide to automate it with tools like autopep8. To avoid making huge commit, you will format files by each Error Code. (Each one still need a human double check or adjustment) And you would like to start from Error Code with smaller violation count. Thus you don't get stuck in a monster one, and make progress quickly.

At last, if some of the Error Code is too much job to fix, you can choose to ignore it in your pycodestyle config.

As you can see, this whole process can be automated with a script.

How

The script used the subprocess.run method, which is introduced in Python 3.5.

Since this script will commit to your git, you'd better create a branch first for it to work on.

Also, it will respect pycodestyle config file in your project.

cd /path/to/code
/path/to/auto-pep8-commit.py

or:

/path/to/auto-pep8-commit.py /path/to/code

auto-pep8-commit's People

Contributors

catalyst-joe-guo avatar

Watchers

 avatar  avatar  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.