Skip to content

Python のソースコードをチェック / 修正するツール群

Python のコードチェックツールについてメモしておきます。

autopep8

autopep8pycodestyle を利用してソースコードの確認 / 修正を行うツールです。

1
python -m pip install autopep8

ファイル名を指定して実行すると PEP8 に準拠してソースコードをチェックします。 標準出力へ確認結果を出力しますが、ファイルは上書きしません。

1
autopep8 sample.py

確認結果を diff 形式で表示するには -d (または --diff) オプションを指定します。

1
autopep8 --diff sample.py

ファイルを上書きするには -i (または --in-place) オプションを指定します。

1
autopep8 -i sample.py

ディレクトリを再帰的に検索して処理するには -r (または --recursive) オプションを指定します。 -r は単体で指定することが出来ず、-i (上書き) または -d (差分表示) と組み合わせ指定する必要があります。 以下は「現在のディレクトリ配下を再帰検索し、発見したファイルを上書きする」実行例です。

1
autopep8 -ri .

black

black は PEP8 に強く準拠してコードの確認 / 修正を行うツールです。 公式ドキュメントで確認したわけではありませんが .venv ディレクトリは処理から除外するものの、他の隠しディレクトリは処理対象にしているように見えました。 尚、flake8 は確認だけを実行し、修正 (ファイルの上書き) は実行しないようです。 インストールします。

1
python -m pip install black

ファイル名を指定して実行すると、指定されたファイルの内容を PEP8 に準拠して修正し、上書きします。

1
black sample.py

ディレクトリを指定すると再帰的に検索して処理を行います。 但し上述の通り、.venv ディレクトリだけは除外しているように見えました。

1
black .

flake8

Flake8 もコードの確認 / 修正を行うツールです。 インストールします。

1
python -m pip install flake8

ファイル名だけを指定すると上書きはせずに確認のみ、実行します。

1
flake8 sample.py

ディレクトリを指定すると再帰的に対象を検索します。 但し、この際に隠しディレクトリや .venv ディレクトリも対象としてしまうようです。 下記は現在のディレクトリ配下を再帰的に確認する実行例です。

1
flake8 .

isort

isort は PEP8 に準拠して import 文の順序を修正してくれるツールです。 ドキュメントで確認したわけでは無いのですが、実際の動作を確認した限り、isort は再帰的に動作させても隠しディレクトリは処理対象外にしているようですので venv 環境を .venv のように隠しディレクトリとして作成している場合は処理対象外になっていました。

インストールします。

1
python -m pip install isort

-c (--check-only) オプションを指定するとファイルは書き換えず、チェックだけを実行します。

1
2
# isort -c sample.py
ERROR: /root/sample/sample1.py Imports are incorrectly sorted and/or formatted.

ファイル名を指定すると import 文の順序を修正し、ファイルを上書きします。

1
isort sample1.py

パスを指定されると、そのパス配下を再帰的に検索して処理対象にします。 以前は -rc というオプションが必要でしたが、isort 5.0 以降はオプションが不要になりました。 むしろ -rc オプションを指定すると警告が表示されます (実行は可能です)。

1
isort .

--diff (または --df) オプションを指定すると修正前後の差分を表示します。 このオプションが指定された場合は ファイルは上書きせず 差分の出力だけを行います。

1
isort --diff isort-sample.py

参考

autopep8 のヘルプ

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# autopep8 --help
usage: autopep8 [-h] [--version] [-v] [-d] [-i] [--global-config filename] [--ignore-local-config] [-r] [-j n]
                [-p n] [-a] [--experimental] [--exclude globs] [--list-fixes] [--ignore errors] [--select errors]
                [--max-line-length n] [--line-range line line] [--hang-closing] [--exit-code]
                [files ...]

Automatically formats Python code to conform to the PEP 8 style guide.

positional arguments:
  files                 files to format or '-' for standard in

optional arguments:
  -h, --help            show this help message and exit
  --version             show program's version number and exit
  -v, --verbose         print verbose messages; multiple -v result in more verbose messages
  -d, --diff            print the diff for the fixed source
  -i, --in-place        make changes to files in place
  --global-config filename
                        path to a global pep8 config file; if this file does not exist then this is ignored
                        (default: /root/.config/pep8)
  --ignore-local-config
                        don't look for and apply local config files; if not passed, defaults are updated with any
                        config files in the project's root directory
  -r, --recursive       run recursively over directories; must be used with --in-place or --diff
  -j n, --jobs n        number of parallel jobs; match CPU count if value is less than 1
  -p n, --pep8-passes n
                        maximum number of additional pep8 passes (default: infinite)
  -a, --aggressive      enable non-whitespace changes; multiple -a result in more aggressive changes
  --experimental        enable experimental fixes
  --exclude globs       exclude file/directory names that match these comma-separated globs
  --list-fixes          list codes for fixes; used by --ignore and --select
  --ignore errors       do not fix these errors/warnings (default: E226,E24,W50,W690)
  --select errors       fix only these errors/warnings (e.g. E4,W)
  --max-line-length n   set maximum allowed line length (default: 79)
  --line-range line line, --range line line
                        only fix errors found within this inclusive range of line numbers (e.g. 1 99); line numbers
                        are indexed at 1
  --hang-closing        hang-closing option passed to pycodestyle
  --exit-code           change to behavior of exit code. default behavior of return value, 0 is no differences, 1 is
                        error exit. return 2 when add this option. 2 is exists differences.

black のヘルプ

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# black --help
Usage: black [OPTIONS] SRC ...

  The uncompromising code formatter.

Options:
  -c, --code TEXT                 Format the code passed in as a string.
  -l, --line-length INTEGER       How many characters per line to allow.
                                  [default: 88]
  -t, --target-version [py27|py33|py34|py35|py36|py37|py38|py39|py310]
                                  Python versions that should be supported by
                                  Black's output. [default: per-file auto-
                                  detection]
  --pyi                           Format all input files like typing stubs
                                  regardless of file extension (useful when
                                  piping source on standard input).
  --ipynb                         Format all input files like Jupyter
                                  Notebooks regardless of file extension
                                  (useful when piping source on standard
                                  input).
  -S, --skip-string-normalization
                                  Don't normalize string quotes or prefixes.
  -C, --skip-magic-trailing-comma
                                  Don't use trailing commas as a reason to
                                  split lines.
  --check                         Don't write the files back, just return the
                                  status. Return code 0 means nothing would
                                  change. Return code 1 means some files would
                                  be reformatted. Return code 123 means there
                                  was an internal error.
  --diff                          Don't write the files back, just output a
                                  diff for each file on stdout.
  --color / --no-color            Show colored diff. Only applies when
                                  `--diff` is given.
  --fast / --safe                 If --fast given, skip temporary sanity
                                  checks. [default: --safe]
  --required-version TEXT         Require a specific version of Black to be
                                  running (useful for unifying results across
                                  many environments e.g. with a pyproject.toml
                                  file).
  --include TEXT                  A regular expression that matches files and
                                  directories that should be included on
                                  recursive searches. An empty value means all
                                  files are included regardless of the name.
                                  Use forward slashes for directories on all
                                  platforms (Windows, too). Exclusions are
                                  calculated first, inclusions later.
                                  [default: (\.pyi?|\.ipynb)$]
  --exclude TEXT                  A regular expression that matches files and
                                  directories that should be excluded on
                                  recursive searches. An empty value means no
                                  paths are excluded. Use forward slashes for
                                  directories on all platforms (Windows, too).
                                  Exclusions are calculated first, inclusions
                                  later. [default: /(\.direnv|\.eggs|\.git|\.h
                                  g|\.mypy_cache|\.nox|\.tox|\.venv|venv|\.svn
                                  |_build|buck-out|build|dist)/]
  --extend-exclude TEXT           Like --exclude, but adds additional files
                                  and directories on top of the excluded ones.
                                  (Useful if you simply want to add to the
                                  default)
  --force-exclude TEXT            Like --exclude, but files and directories
                                  matching this regex will be excluded even
                                  when they are passed explicitly as
                                  arguments.
  --stdin-filename TEXT           The name of the file when passing it through
                                  stdin. Useful to make sure Black will
                                  respect --force-exclude option on some
                                  editors that rely on using stdin.
  -W, --workers INTEGER RANGE     Number of parallel workers  [default: 2;
                                  x>=1]
  -q, --quiet                     Don't emit non-error messages to stderr.
                                  Errors are still emitted; silence those with
                                  2>/dev/null.
  -v, --verbose                   Also emit messages to stderr about files
                                  that were not changed or were ignored due to
                                  exclusion patterns.
  --version                       Show the version and exit.
  --config FILE                   Read configuration from FILE path.
  -h, --help                      Show this message and exit.

flake8 のヘルプ

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# flake8 --help
usage: flake8 [options] file file ...

positional arguments:
  filename

optional arguments:
  -h, --help            show this help message and exit
  -v, --verbose         Print more information about what is happening in flake8. This option is repeatable and will
                        increase verbosity each time it is repeated.
  --output-file OUTPUT_FILE
                        Redirect report to a file.
  --append-config APPEND_CONFIG
                        Provide extra config files to parse in addition to the files found by Flake8 by default.
                        These files are the last ones read and so they take the highest precedence when multiple
                        files provide the same option.
  --config CONFIG       Path to the config file that will be the authoritative config source. This will cause Flake8
                        to ignore all other configuration files.
  --isolated            Ignore all configuration files.
  --version             show program's version number and exit
  -q, --quiet           Report only file names, or nothing. This option is repeatable.
  --count               Print total number of errors and warnings to standard error and set the exit code to 1 if
                        total is not empty.
  --diff                Report changes only within line number ranges in the unified diff provided on standard in by
                        the user.
  --exclude patterns    Comma-separated list of files or directories to exclude. (Default: ['.svn', 'CVS', '.bzr',
                        '.hg', '.git', '__pycache__', '.tox', '.eggs', '*.egg'])
  --extend-exclude patterns
                        Comma-separated list of files or directories to add to the list of excluded ones.
  --filename patterns   Only check for filenames matching the patterns in this comma-separated list. (Default:
                        ['*.py'])
  --stdin-display-name STDIN_DISPLAY_NAME
                        The name used when reporting errors from code passed via stdin. This is useful for editors
                        piping the file contents to flake8. (Default: stdin)
  --format format       Format errors according to the chosen formatter.
  --hang-closing        Hang closing bracket instead of matching indentation of opening bracket's line.
  --ignore errors       Comma-separated list of errors and warnings to ignore (or skip). For example,
                        ``--ignore=E4,E51,W234``. (Default: ['E123', 'W503', 'E121', 'E226', 'W504', 'E704', 'E24',
                        'E126'])
  --extend-ignore errors
                        Comma-separated list of errors and warnings to add to the list of ignored ones. For example,
                        ``--extend-ignore=E4,E51,W234``.
  --per-file-ignores PER_FILE_IGNORES
                        A pairing of filenames and violation codes that defines which violations to ignore in a
                        particular file. The filenames can be specified in a manner similar to the ``--exclude``
                        option and the violations work similarly to the ``--ignore`` and ``--select`` options.
  --max-line-length n   Maximum allowed line length for the entirety of this run. (Default: 79)
  --max-doc-length n    Maximum allowed doc line length for the entirety of this run. (Default: None)
  --indent-size n       Number of spaces used for indentation (Default: 4)
  --select errors       Comma-separated list of errors and warnings to enable. For example,
                        ``--select=E4,E51,W234``. (Default: ['E', 'F', 'W', 'C90'])
  --extend-select errors
                        Comma-separated list of errors and warnings to add to the list of selected ones. For
                        example, ``--extend-select=E4,E51,W234``.
  --disable-noqa        Disable the effect of "# noqa". This will report errors on lines with "# noqa" at the end.
  --show-source         Show the source generate each error or warning.
  --no-show-source      Negate --show-source
  --statistics          Count errors and warnings.
  --enable-extensions ENABLE_EXTENSIONS
                        Enable plugins and extensions that are otherwise disabled by default
  --exit-zero           Exit with status code "0" even if there are errors.
  -j JOBS, --jobs JOBS  Number of subprocesses to use to run checks in parallel. This is ignored on Windows. The
                        default, "auto", will auto-detect the number of processors available to use. (Default: auto)
  --tee                 Write to stdout and output-file.
  --benchmark           Print benchmark information about this run of Flake8
  --bug-report          Print information necessary when preparing a bug report

mccabe:
  --max-complexity MAX_COMPLEXITY
                        McCabe complexity threshold

pyflakes:
  --builtins BUILTINS   define more built-ins, comma separated
  --doctests            also check syntax of the doctests
  --include-in-doctest INCLUDE_IN_DOCTEST
                        Run doctests only on these files
  --exclude-from-doctest EXCLUDE_FROM_DOCTEST
                        Skip these files when running doctests

Installed plugins: mccabe: 0.6.1, pycodestyle: 2.8.0, pyflakes: 2.4.0

isort のヘルプ

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# isort --help
usage: isort [-h] [-V] [--vn] [-v] [--only-modified] [--dedup-headings] [-q] [-d]
             [--overwrite-in-place] [--show-config] [--show-files] [--df] [-c] [--ws]
             [--sp SETTINGS_PATH] [--cr CONFIG_ROOT] [--resolve-all-configs] [--profile PROFILE]
             [--old-finders] [-j [JOBS]] [--ac] [--interactive] [--format-error FORMAT_ERROR]
             [--format-success FORMAT_SUCCESS] [--filter-files] [-s SKIP] [--extend-skip EXTEND_SKIP]
             [--sg SKIP_GLOB] [--extend-skip-glob EXTEND_SKIP_GLOB] [--gitignore]
             [--ext SUPPORTED_EXTENSIONS] [--blocked-extension BLOCKED_EXTENSIONS]
             [--dont-follow-links] [--filename FILENAME] [--allow-root] [-a ADD_IMPORTS] [--append]
             [--af] [--rm REMOVE_IMPORTS] [--float-to-top] [--dont-float-to-top] [--ca] [--cs] [-e]
             [--ff] [--fgw [FORCE_GRID_WRAP]] [-i INDENT] [--lbi LINES_BEFORE_IMPORTS]
             [--lai LINES_AFTER_IMPORTS] [--lbt LINES_BETWEEN_TYPES] [--le LINE_ENDING] [--ls] [--lss]
             [-m {GRID,VERTICAL,HANGING_INDENT,VERTICAL_HANGING_INDENT,VERTICAL_GRID,VERTICAL_GRID_GROUPED,VERTICAL_GRID_GROUPED_NO_COMMA,NOQA,VERTICAL_HANGING_INDENT_BRACKET,VERTICAL_PREFIX_FROM_MODULE_IMPORT,HANGING_INDENT_WITH_PARENTHESES,BACKSLASH_GRID,0,1,2,3,4,5,6,7,8,9,10,11}]
             [-n] [--nis] [--ot] [--dt] [--rr] [--reverse-sort] [--sort-order SORT_ORDER] [--sl]
             [--nsl SINGLE_LINE_EXCLUSIONS] [--tc] [--up] [-l LINE_LENGTH] [--wl WRAP_LENGTH]
             [--case-sensitive] [--remove-redundant-aliases] [--honor-noqa]
             [--treat-comment-as-code TREAT_COMMENTS_AS_CODE] [--treat-all-comment-as-code]
             [--formatter FORMATTER] [--color] [--ext-format EXT_FORMAT] [--star-first]
             [--sd DEFAULT_SECTION] [--only-sections] [--ds] [--fas] [--fss] [--hcss] [--srss] [--fass]
             [-t FORCE_TO_TOP] [--combine-straight-imports] [--nlb NO_LINES_BEFORE] [--src SRC_PATHS]
             [-b KNOWN_STANDARD_LIBRARY] [--extra-builtin EXTRA_STANDARD_LIBRARY]
             [-f KNOWN_FUTURE_LIBRARY] [-o KNOWN_THIRD_PARTY] [-p KNOWN_FIRST_PARTY]
             [--known-local-folder KNOWN_LOCAL_FOLDER] [--virtual-env VIRTUAL_ENV]
             [--conda-env CONDA_ENV] [--py {all,2,27,3,310,35,36,37,38,39,auto}]
             [files ...]

Sort Python import definitions alphabetically within logical sections. Run with no arguments to see a
quick start guide, otherwise, one or more files/directories/stdin must be provided. Use `-` as the
first argument to represent stdin. Use --interactive to use the pre 5.0.0 interactive behavior. If
you've used isort 4 but are new to isort 5, see the upgrading guide:
https://pycqa.github.io/isort/docs/upgrade_guides/5.0.0.html

general options:
  -h, --help            show this help message and exit
  -V, --version         Displays the currently installed version of isort.
  --vn, --version-number
                        Returns just the current version number without the logo
  -v, --verbose         Shows verbose output, such as when files are skipped or when a check is
                        successful.
  --only-modified, --om
                        Suppresses verbose output for non-modified files.
  --dedup-headings      Tells isort to only show an identical custom import heading comment once, even
                        if there are multiple sections with the comment set.
  -q, --quiet           Shows extra quiet output, only errors are outputted.
  -d, --stdout          Force resulting output to stdout, instead of in-place.
  --overwrite-in-place  Tells isort to overwrite in place using the same file handle. Comes at a
                        performance and memory usage penalty over its standard approach but ensures all
                        file flags and modes stay unchanged.
  --show-config         See isort's determined config, as well as sources of config options.
  --show-files          See the files isort will be run against with the current config options.
  --df, --diff          Prints a diff of all the changes isort would make to a file, instead of
                        changing it in place
  -c, --check-only, --check
                        Checks the file for unsorted / unformatted imports and prints them to the
                        command line without modifying the file. Returns 0 when nothing would change
                        and returns 1 when the file would be reformatted.
  --ws, --ignore-whitespace
                        Tells isort to ignore whitespace differences when --check-only is being used.
  --sp SETTINGS_PATH, --settings-path SETTINGS_PATH, --settings-file SETTINGS_PATH, --settings SETTINGS_PATH
                        Explicitly set the settings path or file instead of auto determining based on
                        file location.
  --cr CONFIG_ROOT, --config-root CONFIG_ROOT
                        Explicitly set the config root for resolving all configs. When used with the
                        --resolve-all-configs flag, isort will look at all sub-folders in this config
                        root to resolve config files and sort files based on the closest available
                        config(if any)
  --resolve-all-configs
                        Tells isort to resolve the configs for all sub-directories and sort files in
                        terms of its closest config files.
  --profile PROFILE     Base profile type to use for configuration. Profiles include: black, django,
                        pycharm, google, open_stack, plone, attrs, hug, wemake, appnexus. As well as
                        any shared profiles.
  --old-finders, --magic-placement
                        Use the old deprecated finder logic that relies on environment introspection
                        magic.
  -j [JOBS], --jobs [JOBS]
                        Number of files to process in parallel.
  --ac, --atomic        Ensures the output doesn't save if the resulting file contains syntax errors.
  --interactive         Tells isort to apply changes interactively.
  --format-error FORMAT_ERROR
                        Override the format used to print errors.
  --format-success FORMAT_SUCCESS
                        Override the format used to print success.

target options:
  files                 One or more Python source files that need their imports sorted.
  --filter-files        Tells isort to filter files even when they are explicitly passed in as part of
                        the CLI command.
  -s SKIP, --skip SKIP  Files that isort should skip over. If you want to skip multiple files you
                        should specify twice: --skip file1 --skip file2. Values can be file names,
                        directory names or file paths. To skip all files in a nested path use --skip-
                        glob.
  --extend-skip EXTEND_SKIP
                        Extends --skip to add additional files that isort should skip over. If you want
                        to skip multiple files you should specify twice: --skip file1 --skip file2.
                        Values can be file names, directory names or file paths. To skip all files in a
                        nested path use --skip-glob.
  --sg SKIP_GLOB, --skip-glob SKIP_GLOB
                        Files that isort should skip over.
  --extend-skip-glob EXTEND_SKIP_GLOB
                        Additional files that isort should skip over (extending --skip-glob).
  --gitignore, --skip-gitignore
                        Treat project as a git repository and ignore files listed in .gitignore. NOTE:
                        This requires git to be installed and accessible from the same shell as isort.
  --ext SUPPORTED_EXTENSIONS, --extension SUPPORTED_EXTENSIONS, --supported-extension SUPPORTED_EXTENSIONS
                        Specifies what extensions isort can be run against.
  --blocked-extension BLOCKED_EXTENSIONS
                        Specifies what extensions isort can never be run against.
  --dont-follow-links   Tells isort not to follow symlinks that are encountered when running
                        recursively.
  --filename FILENAME   Provide the filename associated with a stream.
  --allow-root          Tells isort not to treat / specially, allowing it to be run against the root
                        dir.

general output options:
  -a ADD_IMPORTS, --add-import ADD_IMPORTS
                        Adds the specified import line to all files, automatically determining correct
                        placement.
  --append, --append-only
                        Only adds the imports specified in --add-import if the file contains existing
                        imports.
  --af, --force-adds    Forces import adds even if the original file is empty.
  --rm REMOVE_IMPORTS, --remove-import REMOVE_IMPORTS
                        Removes the specified import from all files.
  --float-to-top        Causes all non-indented imports to float to the top of the file having its
                        imports sorted (immediately below the top of file comment). This can be an
                        excellent shortcut for collecting imports every once in a while when you place
                        them in the middle of a file to avoid context switching. *NOTE*: It currently
                        doesn't work with cimports and introduces some extra over-head and a
                        performance penalty.
  --dont-float-to-top   Forces --float-to-top setting off. See --float-to-top for more information.
  --ca, --combine-as    Combines as imports on the same line.
  --cs, --combine-star  Ensures that if a star import is present, nothing else is imported from that
                        namespace.
  -e, --balanced        Balances wrapping to produce the most consistent line length possible
  --ff, --from-first    Switches the typical ordering preference, showing from imports first then
                        straight ones.
  --fgw [FORCE_GRID_WRAP], --force-grid-wrap [FORCE_GRID_WRAP]
                        Force number of from imports (defaults to 2 when passed as CLI flag without
                        value) to be grid wrapped regardless of line length. If 0 is passed in (the
                        global default) only line length is considered.
  -i INDENT, --indent INDENT
                        String to place for indents defaults to " " (4 spaces).
  --lbi LINES_BEFORE_IMPORTS, --lines-before-imports LINES_BEFORE_IMPORTS
  --lai LINES_AFTER_IMPORTS, --lines-after-imports LINES_AFTER_IMPORTS
  --lbt LINES_BETWEEN_TYPES, --lines-between-types LINES_BETWEEN_TYPES
  --le LINE_ENDING, --line-ending LINE_ENDING
                        Forces line endings to the specified value. If not set, values will be guessed
                        per-file.
  --ls, --length-sort   Sort imports by their string length.
  --lss, --length-sort-straight
                        Sort straight imports by their string length. Similar to `length_sort` but
                        applies only to straight imports and doesn't affect from imports.
  -m {GRID,VERTICAL,HANGING_INDENT,VERTICAL_HANGING_INDENT,VERTICAL_GRID,VERTICAL_GRID_GROUPED,VERTICAL_GRID_GROUPED_NO_COMMA,NOQA,VERTICAL_HANGING_INDENT_BRACKET,VERTICAL_PREFIX_FROM_MODULE_IMPORT,HANGING_INDENT_WITH_PARENTHESES,BACKSLASH_GRID,0,1,2,3,4,5,6,7,8,9,10,11}, --multi-line {GRID,VERTICAL,HANGING_INDENT,VERTICAL_HANGING_INDENT,VERTICAL_GRID,VERTICAL_GRID_GROUPED,VERTICAL_GRID_GROUPED_NO_COMMA,NOQA,VERTICAL_HANGING_INDENT_BRACKET,VERTICAL_PREFIX_FROM_MODULE_IMPORT,HANGING_INDENT_WITH_PARENTHESES,BACKSLASH_GRID,0,1,2,3,4,5,6,7,8,9,10,11}
                        Multi line output (0-grid, 1-vertical, 2-hanging, 3-vert-hanging, 4-vert-grid,
                        5-vert-grid-grouped, 6-deprecated-alias-for-5, 7-noqa, 8-vertical-hanging-
                        indent-bracket, 9-vertical-prefix-from-module-import, 10-hanging-indent-with-
                        parentheses).
  -n, --ensure-newline-before-comments
                        Inserts a blank line before a comment following an import.
  --nis, --no-inline-sort
                        Leaves `from` imports with multiple imports 'as-is' (e.g. `from foo import a, c
                        ,b`).
  --ot, --order-by-type
                        Order imports by type, which is determined by case, in addition to
                        alphabetically. **NOTE**: type here refers to the implied type from the import
                        name capitalization. isort does not do type introspection for the imports.
                        These "types" are simply: CONSTANT_VARIABLE, CamelCaseClass,
                        variable_or_function. If your project follows PEP8 or a related coding standard
                        and has many imports this is a good default, otherwise you likely will want to
                        turn it off. From the CLI the `--dont-order-by-type` option will turn this off.
  --dt, --dont-order-by-type
                        Don't order imports by type, which is determined by case, in addition to
                        alphabetically. **NOTE**: type here refers to the implied type from the import
                        name capitalization. isort does not do type introspection for the imports.
                        These "types" are simply: CONSTANT_VARIABLE, CamelCaseClass,
                        variable_or_function. If your project follows PEP8 or a related coding standard
                        and has many imports this is a good default. You can turn this on from the CLI
                        using `--order-by-type`.
  --rr, --reverse-relative
                        Reverse order of relative imports.
  --reverse-sort        Reverses the ordering of imports.
  --sort-order SORT_ORDER
                        Specify sorting function. Can be built in (natural[default] = force numbers to
                        be sequential, native = Python's built-in sorted function) or an installable
                        plugin.
  --sl, --force-single-line-imports
                        Forces all from imports to appear on their own line
  --nsl SINGLE_LINE_EXCLUSIONS, --single-line-exclusions SINGLE_LINE_EXCLUSIONS
                        One or more modules to exclude from the single line rule.
  --tc, --trailing-comma
                        Includes a trailing comma on multi line imports that include parentheses.
  --up, --use-parentheses
                        Use parentheses for line continuation on length limit instead of slashes.
                        **NOTE**: This is separate from wrap modes, and only affects how individual
                        lines that are too long get continued, not sections of multiple imports.
  -l LINE_LENGTH, -w LINE_LENGTH, --line-length LINE_LENGTH, --line-width LINE_LENGTH
                        The max length of an import line (used for wrapping long imports).
  --wl WRAP_LENGTH, --wrap-length WRAP_LENGTH
                        Specifies how long lines that are wrapped should be, if not set line_length is
                        used. NOTE: wrap_length must be LOWER than or equal to line_length.
  --case-sensitive      Tells isort to include casing when sorting module names
  --remove-redundant-aliases
                        Tells isort to remove redundant aliases from imports, such as `import os as
                        os`. This defaults to `False` simply because some projects use these seemingly
                        useless aliases to signify intent and change behaviour.
  --honor-noqa          Tells isort to honor noqa comments to enforce skipping those comments.
  --treat-comment-as-code TREAT_COMMENTS_AS_CODE
                        Tells isort to treat the specified single line comment(s) as if they are code.
  --treat-all-comment-as-code
                        Tells isort to treat all single line comments as if they are code.
  --formatter FORMATTER
                        Specifies the name of a formatting plugin to use when producing output.
  --color               Tells isort to use color in terminal output.
  --ext-format EXT_FORMAT
                        Tells isort to format the given files according to an extensions formatting
                        rules.
  --star-first          Forces star imports above others to avoid overriding directly imported
                        variables.

section output options:
  --sd DEFAULT_SECTION, --section-default DEFAULT_SECTION
                        Sets the default section for import options: ('FUTURE', 'STDLIB', 'THIRDPARTY',
                        'FIRSTPARTY', 'LOCALFOLDER')
  --only-sections, --os
                        Causes imports to be sorted based on their sections like STDLIB, THIRDPARTY,
                        etc. Within sections, the imports are ordered by their import style and the
                        imports with the same style maintain their relative positions.
  --ds, --no-sections   Put all imports into the same section bucket
  --fas, --force-alphabetical-sort
                        Force all imports to be sorted as a single section
  --fss, --force-sort-within-sections
                        Don't sort straight-style imports (like import sys) before from-style imports
                        (like from itertools import groupby). Instead, sort the imports by module,
                        independent of import style.
  --hcss, --honor-case-in-force-sorted-sections
                        Honor `--case-sensitive` when `--force-sort-within-sections` is being used.
                        Without this option set, `--order-by-type` decides module name ordering too.
  --srss, --sort-relative-in-force-sorted-sections
                        When using `--force-sort-within-sections`, sort relative imports the same way
                        as they are sorted when not using that setting.
  --fass, --force-alphabetical-sort-within-sections
                        Force all imports to be sorted alphabetically within a section
  -t FORCE_TO_TOP, --top FORCE_TO_TOP
                        Force specific imports to the top of their appropriate section.
  --combine-straight-imports, --csi
                        Combines all the bare straight imports of the same section in a single line.
                        Won't work with sections which have 'as' imports
  --nlb NO_LINES_BEFORE, --no-lines-before NO_LINES_BEFORE
                        Sections which should not be split with previous by empty lines
  --src SRC_PATHS, --src-path SRC_PATHS
                        Add an explicitly defined source path (modules within src paths have their
                        imports automatically categorized as first_party). Glob expansion (`*` and
                        `**`) is supported for this option.
  -b KNOWN_STANDARD_LIBRARY, --builtin KNOWN_STANDARD_LIBRARY
                        Force isort to recognize a module as part of Python's standard library.
  --extra-builtin EXTRA_STANDARD_LIBRARY
                        Extra modules to be included in the list of ones in Python's standard library.
  -f KNOWN_FUTURE_LIBRARY, --future KNOWN_FUTURE_LIBRARY
                        Force isort to recognize a module as part of Python's internal future
                        compatibility libraries. WARNING: this overrides the behavior of __future__
                        handling and therefore can result in code that can't execute. If you're looking
                        to add dependencies such as six, a better option is to create another section
                        below --future using custom sections. See:
                        https://github.com/PyCQA/isort#custom-sections-and-ordering and the discussion
                        here: https://github.com/PyCQA/isort/issues/1463.
  -o KNOWN_THIRD_PARTY, --thirdparty KNOWN_THIRD_PARTY
                        Force isort to recognize a module as being part of a third party library.
  -p KNOWN_FIRST_PARTY, --project KNOWN_FIRST_PARTY
                        Force isort to recognize a module as being part of the current python project.
  --known-local-folder KNOWN_LOCAL_FOLDER
                        Force isort to recognize a module as being a local folder. Generally, this is
                        reserved for relative imports (from . import module).
  --virtual-env VIRTUAL_ENV
                        Virtual environment to use for determining whether a package is third-party
  --conda-env CONDA_ENV
                        Conda environment to use for determining whether a package is third-party
  --py {all,2,27,3,310,35,36,37,38,39,auto}, --python-version {all,2,27,3,310,35,36,37,38,39,auto}
                        Tells isort to set the known standard library based on the specified Python
                        version. Default is to assume any Python 3 version could be the target, and use
                        a union of all stdlib modules across versions. If auto is specified, the
                        version of the interpreter used to run isort (currently: 39) will be used.