반응형
[2022/11/10] First Start.
소나무 기운 , 전자제품 개발/생산
vscode에서 black formatter 사용하기 (python)
black formatter를 지원하는 VSCode 확장입니다. 현재의 버전은 22.10.0입니다.
* 이 확장은 python 3.7이상 지원합니다.* 번들 black은 설치된 black가 없는 경우에만 사용됩니다.* 지원되는 최소 버젼은 22.3.0dl입니다.
설치 방법
VSCode의 Extension에서 "black formatter"로 검색합니다.
Git hub 위치
https://github.com/microsoft/vscode-black-formatter
사용법
VSCode에서 한번의 설치로 python 파일을 위한 "Black Formatter"를 사용할 수 있습니다.기본 formatter를 "Black Formatter"로 바꿔주세요.(extension id : ms-python.black-formatter)python 문서에 마우스를 올리고 오른버튼을 눌러 "Format Document Wit..."를 선택하면 formatting됩니다.아니면 다음을 추가할 수 있습니다.
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
}
그리고 이렇게 설정되어 있다면 다음과 같이 바꾸세요.
"python.formatting.provider": "none"
저장시 자동 Format하기
아래와 같이 설정하면 저장시 자동 Format하도록 설정할 수 있습니다.
"python.formatting.provider": "none"
설정
SettingsDefaultDescription
black-formatter.args | [] | Custom arguments passed to black. E.g "black-formatter.args" = ["--config", "<file>"] |
black-formatter.trace | error | Sets the tracing level for the extension. |
black-formatter.path | [] | Setting to provide custom black executable. This will slow down formatting, since we will have to run black executable every time or file save or open. Example 1: ["~/global_env/black"] Example 2: ["conda", "run", "-n", "lint_env", "python", "-m", "black"] |
black-formatter.interpreter | [] | Path to a python interpreter to use to run the linter server. |
black-formatter.importStrategy | useBundled | Setting to choose where to load black from. useBundled picks black bundled with the extension. fromEnvironment uses black available in the environment. |
black-formatter.showNotification | off | Setting to control when a notification is shown. |
동작 상태 확인하기
formatter를 사용하기 전과 후를 비교해 보시요.
마무리
참고문헌
틀린 부분이나 질문은 댓글 달아주세요.
즐거운 하루 보내세요. 감사합니다.
반응형
'Tips, Infomation > Coding Editor' 카테고리의 다른 글
VSCode 주석 단축키 Ctrl + / 동작 안될때 처리. (윈도우 11) (0) | 2023.06.28 |
---|---|
Insert Markdown Document Image (마크다운 문서에 이미지 넣기) (0) | 2023.02.17 |
How to Create a Markdown(md) Table (0) | 2022.03.17 |
VSCode 파일이름 옆 숫자 의미 (2) | 2022.02.20 |
[VSCode] How to change Menu font size in VS Code (0) | 2022.01.14 |
댓글