Debian Codegraph @

docs/quick_start/2.-cli.md

raw
1 # Command line usage
2
3 Once installed, `isort` exposes a command line utility for sorting, organizing, and formatting imports within Python and Cython source files.
4
5 To verify the tool is installed correctly, run `isort` from the command line and you should be given the available commands and the version of isort installed.
6 For a list of all CLI options type `isort --help` or view [the online configuration reference](../configuration/options.md):
7
8 <script id="asciicast-346599" src="https://asciinema.org/a/346599.js" async></script>
9
10 ## Formatting a Project
11
12 In general, isort is most commonly utilized across an entire projects source at once. The simplest way to do this is `isort .` or if using a `src` directory `isort src`. isort will automatically find all Python source files recursively and pick-up a configuration file placed at the root of your project if present. This can be combined with any command line configuration customizations such as specifying a profile to use (`isort . --profile black`).
13
14 <script id="asciicast-346600" src="https://asciinema.org/a/346600.js" async></script>
15
16 ## Verifying a Project
17
18 The second most common usage of isort is verifying that imports within a project are formatted correctly (often within the context of a CI/CD system). The simplest way to accomplish this is using the check command line option: `isort --check .`. To improve the usefulness of errors when they do occur, this can be combined with the diff option: `isort --check --diff .`.
19
20 <script id="asciicast-346601" src="https://asciinema.org/a/346601.js" async></script>
21
22 ## Single Source Files
23
24 Finally, isort can just as easily be ran against individual source files. Simply pass in a single or multiple source files to sort or validate (Example: `isort setup.py`).
25
26 <script id="asciicast-346602" src="https://asciinema.org/a/346602.js" async></script>
27
28 ## Temporary Files
29
30 By default, when isort processes a source file, it writes the result to a
31 sibling temporary file by appending `.isorted` to the source filename. If the
32 content changes, this temporary file replaces the original. isort removes the
33 temporary file when processing finishes and also attempts cleanup if sorting
34 raises an exception.
35
36 If the process terminates before cleanup runs, the temporary file may remain.
37 It can be removed after isort has stopped. Projects where abrupt termination is
38 possible can ignore `*.isorted` files, or use the
39 [`--overwrite-in-place`](../configuration/options.md#overwrite-in-place)
40 option to avoid creating them, with a performance and memory usage penalty.
41
42 ## Multiple Projects
43
44 Running a single isort command across multiple projects, or source files spanning multiple projects, is highly discouraged. Instead it is recommended that an isort process (or command) is ran for each project independently. This is because isort creates an immutable config for each CLI instance.
45
46 ```
47 # YES
48 isort project1
49 isort project2
50
51 # Also YES
52 isort project1/src project1/test
53 isort project2/src project2/test
54
55 # NO
56 isort project1 project2
57 ```