Git Product home page Git Product logo

2023-1-ossp1-cgs-8's Introduction

autopyre

autopep8pycodestyle 을 개선한 Python Code Style Formatter

  • autopyre는 python 코드를 자동으로 PEP8 스타일 가이드에 맞게 포매팅하는 도구입니다.
  • 파이썬 코드 스타일 가이드 PEP8 에 기반한 코드 스타일로 수정해줍니다.
  • 사용자가 스타일 설정이 가능하도록 커스터마이징 기능을 추가해 유연성을 강화했습니다.
  • 또한 PEP8에서 언급하는 클래스명, 함수명에 대한 작명 컨벤션 에 부합하게 구현하였습니다.
$ pip install autopyre
$ pip install --upgrade autopyre

autopyre requires pyrestyle

$ pip install pyrestyle
$ pip install --upgrade pyrestyle
autopyre 사용법

파일 변경 내용을 콘솔로 출력 (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

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

Description:

* [-a -a -a]
PEP8 스타일 가이드에서 권장하는 클래스와 함수의 작명 규칙을
따르지 않을 경우 권장하는 스타일에 맞게 수정합니다.

예시
$ autopyre -a -a -a input.py


* [--alias]
Aliasing 코드 삽입

예시
$ autopyre -a -a -a --alias input.py

Description:

* [--customize]
custom.txt 파일을 수정해서 적용할 수 있습니다.

예시
autopyre --customize input.py
커스터마이징 가능 항목과 필요 조건
커스터마이징 가능 항목 필요 조건
공백 문자 기준 들여쓰기 수준 설정 0보다 큰 양수
닫힌 괄호 위치 스타일 설정 0, 1로 스타일 선택
이항 연산자 줄바꿈 스타일 설정 0, 1로 스타일 선택
한 줄의 최대 길이 설정 0보다 큰 양수
문자열 쿼트 스타일 설정 0, 1로 스타일 선택
select argument 설정 ,를 기준으로 에러 코드 나열
ignore argument 설정 ,를 기준으로 에러 코드 나열
각 항목에 대한 무시 여부 설정 True 시 각 항목 무시 가능

MIT 라이선스를 준수하며 LICENSE 에서 자세한 정보를 확인할 수 있습니다.

2023-1-ossp1-cgs-8's People

Contributors

jun6292 avatar kimwiseong avatar taew00k avatar prefer52 avatar hajieun02 avatar chajaesik01 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.