Linux command
isort 命令
文件
复制后可按需替换文件名、目录或参数。
常用示例
Sort imports in a file in place
isort [file.py]
Check without modifying (exit non-zero if changes needed)
isort --check-only [file.py]
Show diff of proposed changes
isort --diff [file.py]
Sort all Python files in the current directory recursively
isort .
Use Black-compatible profile
isort --profile black [file.py]
Set line length and run in parallel
isort -l [100] -j [4] [path]
说明
isort sorts Python imports alphabetically and separates them into sections. It follows PEP 8 guidelines for import organization. The tool groups imports by standard library, third-party, and local. It integrates with editors and CI pipelines.
参数
- -c, --check-only
- Check whether imports are sorted without modifying files. Exit code 1 if changes would be made.
- --diff
- Print a diff of the changes isort would make instead of applying them.
- --profile _NAME_
- Use a predefined profile (black, django, pycharm, google, open_stack, plone, attrs, hug, wemake, appnexus).
- -l, --line-length _LENGTH_
- Maximum import line length used for wrapping. Default is 79.
- --force-single-line, --sl
- Force all `from` imports onto their own line.
- --skip, -s _PATH_
- File or directory to skip. May be given multiple times.
- --atomic
- Abort writing the output if the resulting file would contain syntax errors.
- -j, --jobs _N_
- Number of files to process in parallel. A negative value uses the number of CPU cores.
- --settings-path, --sp _PATH_
- Explicit path to the settings file or directory (overrides auto-detection).
- -v, --verbose
- Print detailed output about processing.
- -q, --quiet
- Only show errors.
- --help
- Display help information.
FAQ
What is the isort command used for?
isort sorts Python imports alphabetically and separates them into sections. It follows PEP 8 guidelines for import organization. The tool groups imports by standard library, third-party, and local. It integrates with editors and CI pipelines.
How do I run a basic isort example?
Run `isort [file.py]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -c, --check-only do in isort?
Check whether imports are sorted without modifying files. Exit code 1 if changes would be made.