공식
https://black.readthedocs.io/en/stable/integrations/editors.html
Editor integration — Black 21.5b1 documentation
Wing IDE Wing supports black via the OS Commands tool, as explained in the Wing documentation on pep8 formatting. The detailed procedure is: Install black. Make sure it runs from the command line, e.g. In Wing IDE, activate the OS Commands panel and define
black.readthedocs.io
PyCharm/IntelliJ IDEA 적용
1. 설치
pip install black
2. black 설치된 위치 찾기
$ which black
/usr/local/bin/black # possible location
3. IDE의 설정
PyCharm -> Preferences -> Tools -> External Tools 에서 + 버튼 눌러 아래 항목 작성 후 저장
Name: Black
Description: Black is the uncompromising Python code formatter.
Program: #which black로 찾은 위치
Arguments: "$FilePath$"
4. 저장할때 자동 포맷팅 적용
file watcher 플러그인 다운
https://plugins.jetbrains.com/plugin/7177-file-watchers
File Watchers - Plugins | JetBrains
Allows executing tasks triggered by file modifications.
plugins.jetbrains.com
Preferences or Settings -> Tools -> File Watchers + 눌러 아래 항목 작성 후 저장
Name: Black
File type: Python
Scope: Project Files
Program: <install_location_from_step_2>
Arguments: $FilePath$
Output paths to refresh: $FilePath$
Working directory: $ProjectFileDir$
In Advanced Options 에서 아래 항목 체크 해제
- Uncheck “Auto-save edited files to trigger the watcher”
- Uncheck “Trigger the watcher on external changes”
'Study > Django' 카테고리의 다른 글
[Django] field lookup (0) | 2021.05.25 |
---|---|
[Django] decorator (0) | 2021.05.25 |
[Django] 환경 변수 분리하기 django-environ (0) | 2021.05.18 |
[Django] Views, Generic Views, Viewset (0) | 2021.05.11 |
[Django] settings.py - cors, static path (0) | 2021.05.11 |