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

Documentation

autopyre

autopep8pycodestyle 을 개선한 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