vscode에서 파이썬 코드 스타일 설정

우수민·2021년 6월 14일
0

잡다한 공부

목록 보기
4/13

<파이썬 코드 스타일>

  1. Linter : flake8
  2. Format : black

1. flake8 설정

  1. ctrl + shift + p 를 눌러서 Python: Select Linter 선택
  2. flake8 선택
  3. 이후 vscode내에서 .vscode/settings.json 파일이 생성되면서 아래의 내용이 추가된다.
{
    "python.linting.flake8Enabled": true,
    "python.linting.enabled": true
}  

2. Black 설정

  1. black 설치
pip install black
  1. 1번의 생성된 .vscode/settings.json 내부에 두개의 값을 추가 시켜준다.
"editor.formatOnSave": true,
"python.formatting.provider": "black"
  • 위와 합치면 4개가 설정이 된다.
{
    "python.linting.flake8Enabled": true,
    "python.linting.enabled": true,
    "editor.formatOnSave": true,
    "python.formatting.provider": "black",
}
  1. root 디렉토리에 pyproject.toml 파일을 추가시켜준다.
[tool.black]
line-length = 112
include = '\.pyi?$'
exclude = '''
/(
    \.git
  | \.hg
  | \.mypy_cache
  | \.tox
  | \.venv
  | _build
  | buck-out
  | build
  | dist
)/
'''

참고 :
1. https://www.daleseo.com/python-black/
2. https://cereblanco.medium.com/setup-black-and-isort-in-vscode-514804590bf9

profile
데이터 분석하고 있습니다

0개의 댓글