isort ¤
Callable for isort.
Functions:
-
run
–Run
isort
.
run ¤
run(
*files: str,
settings: str | None = None,
verbose: bool | None = None,
only_modified: bool | None = None,
dedup_headings: bool | None = None,
quiet: bool | None = None,
stdout: bool | None = None,
overwrite_in_place: bool | None = None,
show_config: bool | None = None,
show_files: bool | None = None,
diff: bool | None = None,
check: bool | None = None,
ignore_whitespace: bool | None = None,
config_root: str | None = None,
resolve_all_configs: bool | None = None,
profile: str | None = None,
jobs: int | None = None,
atomic: bool | None = None,
interactive: bool | None = None,
format_error: str | None = None,
format_success: str | None = None,
sort_reexports: bool | None = None,
filter_files: bool | None = None,
skip: list[str] | None = None,
extend_skip: list[str] | None = None,
skip_glob: list[str] | None = None,
extend_skip_glob: list[str] | None = None,
skip_gitignore: bool | None = None,
supported_extension: list[str] | None = None,
blocked_extension: list[str] | None = None,
dont_follow_links: bool | None = None,
filename: str | None = None,
allow_root: bool | None = None,
add_import: str | None = None,
append_only: bool | None = None,
force_adds: bool | None = None,
remove_import: str | None = None,
float_to_top: bool | None = None,
dont_float_to_top: bool | None = None,
combine_as: bool | None = None,
combine_star: bool | None = None,
balanced: bool | None = None,
from_first: bool | None = None,
force_grid_wrap: int | None = None,
indent: str | None = None,
lines_before_imports: int | None = None,
lines_after_imports: int | None = None,
lines_between_types: int | None = None,
line_ending: str | None = None,
length_sort: bool | None = None,
length_sort_straight: bool | None = None,
multi_line: Multiline | None = None,
ensure_newline_before_comments: bool | None = None,
no_inline_sort: bool | None = None,
order_by_type: bool | None = None,
dont_order_by_type: bool | None = None,
reverse_relative: bool | None = None,
reverse_sort: bool | None = None,
sort_order: Literal["natural", "native"] | None = None,
force_single_line_imports: bool | None = None,
single_line_exclusions: list[str] | None = None,
trailing_comma: bool | None = None,
use_parentheses: bool | None = None,
line_length: int | None = None,
wrap_length: int | None = None,
case_sensitive: bool | None = None,
remove_redundant_aliases: bool | None = None,
honor_noqa: bool | None = None,
treat_comment_as_code: str | None = None,
treat_all_comment_as_code: bool | None = None,
formatter: str | None = None,
color: bool | None = None,
ext_format: str | None = None,
star_first: bool | None = None,
split_on_trailing_comma: bool | None = None,
section_default: (
Literal[
"FUTURE",
"STDLIB",
"THIRDPARTY",
"FIRSTPARTY",
"LOCALFOLDER",
]
| None
) = None,
only_sections: bool | None = None,
no_sections: bool | None = None,
force_alphabetical_sort: bool | None = None,
force_sort_within_sections: bool | None = None,
honor_case_in_force_sorted_sections: bool | None = None,
sort_relative_in_force_sorted_sections: (
bool | None
) = None,
force_alphabetical_sort_within_sections: (
bool | None
) = None,
top: str | None = None,
combine_straight_imports: bool | None = None,
no_lines_before: list[str] | None = None,
src_path: list[str] | None = None,
builtin: str | None = None,
extra_builtin: str | None = None,
future: str | None = None,
thirdparty: str | None = None,
project: str | None = None,
known_local_folder: str | None = None,
virtual_env: str | None = None,
conda_env: str | None = None,
python_version: (
Literal[
"all",
"2",
"27",
"3",
"36",
"37",
"38",
"39",
"310",
"311",
"auto",
]
| None
) = None
) -> None
Run isort
.
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.
Parameters:
-
*files
(str
, default:()
) –One or more Python source files that need their imports sorted.
-
settings
(str | None
, default:None
) –Explicitly set the settings path or file instead of auto determining based on file location.
-
verbose
(bool | None
, default:None
) –Shows verbose output, such as when files are skipped or when a check is successful.
-
only_modified
(bool | None
, default:None
) –Suppresses verbose output for non-modified files.
-
dedup_headings
(bool | None
, default:None
) –Tells isort to only show an identical custom import heading comment once, even if there are multiple sections with the comment set.
-
quiet
(bool | None
, default:None
) –Shows extra quiet output, only errors are outputted.
-
stdout
(bool | None
, default:None
) –Force resulting output to stdout, instead of in-place.
-
overwrite_in_place
(bool | None
, default:None
) –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
(bool | None
, default:None
) –See isort's determined config, as well as sources of config options.
-
show_files
(bool | None
, default:None
) –See the files isort will be run against with the current config options.
-
diff
(bool | None
, default:None
) –Prints a diff of all the changes isort would make to a file, instead of changing it in place
-
check
(bool | None
, default:None
) –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.
-
ignore_whitespace
(bool | None
, default:None
) –Tells isort to ignore whitespace differences when --check-only is being used.
-
config_root
(str | None
, default:None
) –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
(bool | None
, default:None
) –Tells isort to resolve the configs for all sub-directories and sort files in terms of its closest config files.
-
profile
(str | None
, default:None
) –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.
-
jobs
(int | None
, default:None
) –Number of files to process in parallel. Negative value means use number of CPUs.
-
atomic
(bool | None
, default:None
) –Ensures the output doesn't save if the resulting file contains syntax errors.
-
interactive
(bool | None
, default:None
) –Tells isort to apply changes interactively.
-
format_error
(str | None
, default:None
) –Override the format used to print errors.
-
format_success
(str | None
, default:None
) –Override the format used to print success.
-
sort_reexports
(bool | None
, default:None
) –Automatically sort all re-exports (module level all collections)
-
filter_files
(bool | None
, default:None
) –Tells isort to filter files even when they are explicitly passed in as part of the CLI command.
-
skip
(list[str] | None
, default:None
) –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
(list[str] | None
, default:None
) –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.
-
skip_glob
(list[str] | None
, default:None
) –Files that isort should skip over.
-
extend_skip_glob
(list[str] | None
, default:None
) –Additional files that isort should skip over (extending --skip-glob).
-
skip_gitignore
(bool | None
, default:None
) –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.
-
supported_extension
(list[str] | None
, default:None
) –Specifies what extensions isort can be run against.
-
blocked_extension
(list[str] | None
, default:None
) –Specifies what extensions isort can never be run against.
-
dont_follow_links
(bool | None
, default:None
) –Tells isort not to follow symlinks that are encountered when running recursively.
-
filename
(str | None
, default:None
) –Provide the filename associated with a stream.
-
allow_root
(bool | None
, default:None
) –Tells isort not to treat / specially, allowing it to be run against the root dir.
-
add_import
(str | None
, default:None
) –Adds the specified import line to all files, automatically determining correct placement.
-
append_only
(bool | None
, default:None
) –Only adds the imports specified in --add-import if the file contains existing imports.
-
force_adds
(bool | None
, default:None
) –Forces import adds even if the original file is empty.
-
remove_import
(str | None
, default:None
) –Removes the specified import from all files.
-
float_to_top
(bool | None
, default:None
) –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
(bool | None
, default:None
) –Forces --float-to-top setting off. See --float-to-top for more information.
-
combine_as
(bool | None
, default:None
) –Combines as imports on the same line.
-
combine_star
(bool | None
, default:None
) –Ensures that if a star import is present, nothing else is imported from that namespace.
-
balanced
(bool | None
, default:None
) –Balances wrapping to produce the most consistent line length possible
-
from_first
(bool | None
, default:None
) –Switches the typical ordering preference, showing from imports first then straight ones.
-
force_grid_wrap
(int | None
, default:None
) –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.
-
indent
(str | None
, default:None
) –String to place for indents defaults to " " (4 spaces).
-
lines_before_imports
(int | None
, default:None
) –Number of lines to insert before imports.
-
lines_after_imports
(int | None
, default:None
) –Number of lines to insert after imports.
-
lines_between_types
(int | None
, default:None
) –Number of lines to insert between imports.
-
line_ending
(str | None
, default:None
) –Forces line endings to the specified value. If not set, values will be guessed per-file.
-
length_sort
(bool | None
, default:None
) –Sort imports by their string length.
-
length_sort_straight
(bool | None
, default:None
) –Sort straight imports by their string length. Similar to
length_sort
but applies only to straight imports and doesn't affect from imports. -
multi_line
(Multiline | None
, default:None
) –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).
-
ensure_newline_before_comments
(bool | None
, default:None
) –Inserts a blank line before a comment following an import.
-
no_inline_sort
(bool | None
, default:None
) –Leaves
from
imports with multiple imports 'as-is' (e.g.from foo import a, c ,b
). -
order_by_type
(bool | None
, default:None
) –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. -
dont_order_by_type
(bool | None
, default:None
) –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
. -
reverse_relative
(bool | None
, default:None
) –Reverse order of relative imports.
-
reverse_sort
(bool | None
, default:None
) –Reverses the ordering of imports.
-
sort_order
(Literal['natural', 'native'] | None
, default:None
) –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.
-
force_single_line_imports
(bool | None
, default:None
) –Forces all from imports to appear on their own line
-
single_line_exclusions
(EXCLUSIONS
, default:None
) –One or more modules to exclude from the single line rule.
-
trailing_comma
(bool | None
, default:None
) –Includes a trailing comma on multi line imports that include parentheses.
-
use_parentheses
(bool | None
, default:None
) –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.
-
line_length
(int | None
, default:None
) –The max length of an import line (used for wrapping long imports).
-
wrap_length
(int | None
, default:None
) –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
(bool | None
, default:None
) –Tells isort to include casing when sorting module names
-
remove_redundant_aliases
(bool | None
, default:None
) –Tells isort to remove redundant aliases from imports, such as
import os as os
. This defaults toFalse
simply because some projects use these seemingly useless aliases to signify intent and change behaviour. -
honor_noqa
(bool | None
, default:None
) –Tells isort to honor noqa comments to enforce skipping those comments.
-
treat_comment_as_code
(str | None
, default:None
) –Tells isort to treat the specified single line comment(s) as if they are code.
-
treat_all_comment_as_code
(bool | None
, default:None
) –Tells isort to treat all single line comments as if they are code.
-
formatter
(str | None
, default:None
) –Specifies the name of a formatting plugin to use when producing output.
-
color
(bool | None
, default:None
) –Tells isort to use color in terminal output.
-
ext_format
(str | None
, default:None
) –Tells isort to format the given files according to an extensions formatting rules.
-
star_first
(bool | None
, default:None
) –Forces star imports above others to avoid overriding directly imported variables.
-
split_on_trailing_comma
(bool | None
, default:None
) –Split imports list followed by a trailing comma into VERTICAL_HANGING_INDENT mode
-
section_default
(Literal['FUTURE', 'STDLIB', 'THIRDPARTY', 'FIRSTPARTY', 'LOCALFOLDER'] | None
, default:None
) –Sets the default section for import options: ('FUTURE', 'STDLIB', 'THIRDPARTY', 'FIRSTPARTY', 'LOCALFOLDER')
-
only_sections
(bool | None
, default:None
) –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.
-
no_sections
(bool | None
, default:None
) –Put all imports into the same section bucket
-
force_alphabetical_sort
(bool | None
, default:None
) –Force all imports to be sorted as a single section
-
force_sort_within_sections
(bool | None
, default:None
) –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.
-
honor_case_in_force_sorted_sections
(bool | None
, default:None
) –Honor
--case-sensitive
when--force-sort-within-sections
is being used. Without this option set,--order-by-type
decides module name ordering too. -
sort_relative_in_force_sorted_sections
(bool | None
, default:None
) –When using
--force-sort-within-sections
, sort relative imports the same way as they are sorted when not using that setting. -
force_alphabetical_sort_within_sections
(bool | None
, default:None
) –Force all imports to be sorted alphabetically within a section
-
top
(str | None
, default:None
) –Force specific imports to the top of their appropriate section.
-
combine_straight_imports
(bool | None
, default:None
) –Combines all the bare straight imports of the same section in a single line. Won't work with sections which have 'as' imports
-
no_lines_before
(list[str] | None
, default:None
) –Sections which should not be split with previous by empty lines
-
src_path
(list[str] | None
, default:None
) –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. -
builtin
(str | None
, default:None
) –Force isort to recognize a module as part of Python's standard library.
-
extra_builtin
(str | None
, default:None
) –Extra modules to be included in the list of ones in Python's standard library.
-
future
(str | None
, default:None
) –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.
-
thirdparty
(str | None
, default:None
) –Force isort to recognize a module as being part of a third party library.
-
project
(str | None
, default:None
) –Force isort to recognize a module as being part of the current python project.
-
known_local_folder
(str | None
, default:None
) –Force isort to recognize a module as being a local folder. Generally, this is reserved for relative imports (from . import module).
-
virtual_env
(str | None
, default:None
) –Virtual environment to use for determining whether a package is third-party
-
conda_env
(str | None
, default:None
) –Conda environment to use for determining whether a package is third-party
-
python_version
(Literal['all', '2', '27', '3', '36', '37', '38', '39', '310', '311', 'auto'] | None
, default:None
) –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: 311) will be used.
Source code in src/duty/callables/isort.py
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 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 |
|