Target person ☆ People who use Python with PyCharm but do not use automatic formatting ☆ People who use Python but do not use code check tools
By using automatic formatting and code check tools It will improve the quality of the code, so let's set it!
And this time every Python engineer would have used it once I would like to share the recommended settings with PyCharm in the IDE!
To format the code when saving the file
Install the File Watchers
plugin.
Open in the order of Preferences> Plugin
.
Search for File Watchers
from Marketplace
and install.
You need to reboot after installation.
autopep8 It automatically formats your Python code in a PEP8 compliant format.
Installation
pip install autopep8
Select Preferences> Tools> File Watchers
.
Press the + button.
Name: The name you want to set (autopep8)
File type: Python
Scope: Current File
Program: /$PyInterpreterDirectory$/flake8
Arguments: --in-place --aggressive --aggressive $FilePath$
Apply with APPLY from OK!
flake8
Python code check tool
Installation
pip install flake8
Select Preferences> Tools> File Watchers
.
Press the + button.
Name: The name you want to set (flake8)
File type: Python
Scope: Current File
Program: /$PyInterpreterDirectory$/flake8
Arguments: --max-line-length 99 $FilePath$
Apply with APPLY from OK!
Black A more restrictive formatting tool than PEP8
Name: Name you want to set (Black)
File type: Python
Scope: Current File
Program: /$PyInterpreterDirectory$/black
Arguments: $FilePath$
flake8-isort A tool that checks the import order of files
Name: The name you want to set (isort)
File type: Python
Scope: Current File
Program: /$PyInterpreterDirectory$/isort
Arguments: $FilePath$
.editorconfig A tool that keeps your code consistent in any editor.
Create .editorconfig
directly under the project.
.editorconfig
# http://editorconfig.org
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
[*.{py,rst,ini}]
indent_style = space
indent_size = 4
[*.py]
line_length = 88
known_first_party = django,config
multi_line_output = 3
default_section = THIRDPARTY
recursive = true
skip = venv/
skip_glob = **/migrations/*.py
include_trailing_comma = true
force_grid_wrap = 0
use_parentheses = true
[*.{html,css,scss,json,yml}]
indent_style = space
indent_size = 2
[*.md]
trim_trailing_whitespace = false
[Makefile]
indent_style = tab
[nginx.conf]
indent_style = space
indent_size = 2
Recommended Posts