pyrestyle

Python style guide checker and This project based on pycodestyle


Keywords
pyrestyle, pep8, PEP, 8, PEP-8
License
Saxpath
Install
pip install pyrestyle==0.0.8

Documentation

autopyre

autopep8 ๊ณผ pycodestyle ์„ ๊ฐœ์„ ํ•œ Python Code Style Formatter

  • autopyre๋Š” python ์ฝ”๋“œ๋ฅผ ์ž๋™์œผ๋กœ PEP8 ์Šคํƒ€์ผ ๊ฐ€์ด๋“œ์— ๋งž๊ฒŒ ํฌ๋งคํŒ…ํ•˜๋Š” ๋„๊ตฌ์ž…๋‹ˆ๋‹ค.
  • ํŒŒ์ด์ฌ ์ฝ”๋“œ ์Šคํƒ€์ผ ๊ฐ€์ด๋“œ PEP8 ์— ๊ธฐ๋ฐ˜ํ•œ ์ฝ”๋“œ ์Šคํƒ€์ผ๋กœ ์ˆ˜์ •ํ•ด์ค๋‹ˆ๋‹ค.
  • ์‚ฌ์šฉ์ž๊ฐ€ ์Šคํƒ€์ผ ์„ค์ •์ด ๊ฐ€๋Šฅํ•˜๋„๋ก ์ปค์Šคํ„ฐ๋งˆ์ด์ง• ๊ธฐ๋Šฅ์„ ์ถ”๊ฐ€ํ•ด ์œ ์—ฐ์„ฑ์„ ๊ฐ•ํ™”ํ–ˆ์Šต๋‹ˆ๋‹ค.
  • ๋˜ํ•œ PEP8์—์„œ ์–ธ๊ธ‰ํ•˜๋Š” ํด๋ž˜์Šค๋ช…, ํ•จ์ˆ˜๋ช…์— ๋Œ€ํ•œ ์ž‘๋ช… ์ปจ๋ฒค์…˜ ์— ๋ถ€ํ•ฉํ•˜๊ฒŒ ๊ตฌํ˜„ํ•˜์˜€์Šต๋‹ˆ๋‹ค.

Installation

$ pip install autopyre
$ pip install --upgrade autopyre

Requirements

autopyre requires pyrestyle

$ pip install pyrestyle
$ pip install --upgrade pyrestyle

Usage

ํŒŒ์ผ ๋ณ€๊ฒฝ ๋‚ด์šฉ์„ ์ฝ˜์†”๋กœ ์ถœ๋ ฅ (default):

$ autopyre -a -a -a <filename>

ํŒŒ์ผ ๋ณ€๊ฒฝ ๋‚ด์šฉ์„ ํŒŒ์ผ์— ๋ฎ์–ด์“ฐ๊ธฐ (aggressive level 3):

$ autopyre --in-place -a -a -a <filename>

autopyre ์‹คํ–‰ ์ „ ์ฝ”๋“œ (์ฝ”๋“œ์˜ ์˜๋ฏธ X, ํฌ๋งคํŒ…์— ์ง‘์ค‘)

import math, sys;

def example1():
    ####This is a long comment. This should be wrapped to fit within 72 characters.
    some_tuple=(   1,2, 3,'a'  );
    some_variable={'long':'Long code lines should be wrapped within 79 characters.',
    'other':[math.pi, 100,200,300,9876543210,'This is a long string that goes on'],
    'more':{'inner':'This whole logical line should be wrapped.',some_tuple:[1,
    20,300,40000,5,6000000]}}
    return (some_tuple, some_variable)
def ExampleTwo(): # inline comment
    return {'has_key() is deprecated':True}.has_key({'f':2}.has_key(''));
class example_three(   object ):    # inline comment2
    def __init__    ( self, bar ):
        #Comments should have a space after the hash.
        if bar : bar+=1;  bar=bar* bar   ; return bar   # ์ธ๋ผ์ธ ์ฃผ์„
        else:
                some_string = '''
                ์—ฌ๋Ÿฌ ์ค„ ๋ฌธ์ž์—ด
                double quote ๋ณ€ํ™˜'''
        return (sys.path, some_string)

autopyre ์‹คํ–‰ ํ›„ ์ฝ”๋“œ

$ autopyre -a -a -a test_all.py
import math
import sys

def example1():
    # This is a long comment. This should be wrapped to fit within 72
    # characters.
    some_tuple = (1, 2, 3, "a")
    some_variable = {
        "long": "Long code lines should be wrapped within 79 characters.",
        "other": [
            math.pi,
            100,
            200,
            300,
            9876543210,
            "This is a long string that goes on"],
        "more": {
            "inner": "This whole logical line should be wrapped.",
            some_tuple: [
                1,
                20,
                300,
                40000,
                5,
                6000000]}}
    return (some_tuple, some_variable)


# inline comment
def example_two():
    return {"has_key() is deprecated": True}.has_key({"f": 2}.has_key(""))


# inline comment2
class ExampleThree(object):
    def __init__(self, bar):
        # Comments should have a space after the hash.
        if bar:
            bar += 1
            bar = bar * bar
            # ์ธ๋ผ์ธ ์ฃผ์„
            return bar
        else:
            some_string = """
                ์—ฌ๋Ÿฌ ์ค„ ๋ฌธ์ž์—ด
                double quote ๋ณ€ํ™˜"""
        return (sys.path, some_string)

Options:

usage: autopyre [--customize] [-a -a -a] [โ€”-alias]
                [--aggressive --aggressive --aggressive]
                [-a -a -a --in-place]
                [-a -a -a --alias --in-place]
                [-d] [--diff] [-i] [--in-place]


Automatically formats Python code to conform to the PEP 8 style guide.

positional arguments:
  files                 files to format or '-' for standard in

optional arguments:
  -i, --in-place        make changes to files in place
  -a, --aggressive      enable non-whitespace changes; multiple -a result in
                        more aggressive changes
  -d, --diff            show difference before formatting and after formatting
  --experimental        enable experimental fixes
  --customize           customzie formatting style with modifying custom.txt file

Features

autopyre fixes the following issues reported by pyrestyle:

E267 - Remove inline comment and add block comment
W705 - Modify class name to capwords case
W706 - Modify class name to capwords case and add aliasing code
W707 - Modify function name to snake case
W708 - Modify function name to snake case and add aliasing code
w744 - Modify single quote to double quote
w745 - Modify triple single quote to triple double quote

Naming Convention

Description:

* [-a -a -a]
PEP8 ์Šคํƒ€์ผ ๊ฐ€์ด๋“œ์—์„œ ๊ถŒ์žฅํ•˜๋Š” ํด๋ž˜์Šค์™€ ํ•จ์ˆ˜์˜ ์ž‘๋ช… ๊ทœ์น™์„
๋”ฐ๋ฅด์ง€ ์•Š์„ ๊ฒฝ์šฐ ๊ถŒ์žฅํ•˜๋Š” ์Šคํƒ€์ผ์— ๋งž๊ฒŒ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค.

์˜ˆ์‹œ
$ autopyre -a -a -a input.py


* [--alias]
Aliasing ์ฝ”๋“œ ์‚ฝ์ž…

์˜ˆ์‹œ
$ autopyre -a -a -a --alias input.py

Customize

Description:

* [--customize]
custom.txt ํŒŒ์ผ์„ ์ˆ˜์ •ํ•ด์„œ ์ ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์˜ˆ์‹œ
autopyre --customize input.py

License

MIT ๋ผ์ด์„ ์Šค๋ฅผ ์ค€์ˆ˜ํ•˜๋ฉฐ LICENSE ์—์„œ ์ž์„ธํ•œ ์ •๋ณด๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Contacts

Links