• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

isort/H07-May-2022-10,7248,990

tests/H03-May-2022-16,11313,577

LICENSEH A D06-Feb-20211.1 KiB2217

PKG-INFOH A D09-Nov-202112.4 KiB398278

README.mdH A D03-Aug-202110.6 KiB356238

pyproject.tomlH A D09-Nov-20213.8 KiB135122

setup.pyH A D09-Nov-202112.2 KiB4637

README.md

1[![isort - isort your imports, so you don't have to.](https://raw.githubusercontent.com/pycqa/isort/main/art/logo_large.png)](https://pycqa.github.io/isort/)
2
3------------------------------------------------------------------------
4
5[![PyPI version](https://badge.fury.io/py/isort.svg)](https://badge.fury.io/py/isort)
6[![Test Status](https://github.com/pycqa/isort/workflows/Test/badge.svg?branch=develop)](https://github.com/pycqa/isort/actions?query=workflow%3ATest)
7[![Lint Status](https://github.com/pycqa/isort/workflows/Lint/badge.svg?branch=develop)](https://github.com/pycqa/isort/actions?query=workflow%3ALint)
8[![Code coverage Status](https://codecov.io/gh/pycqa/isort/branch/main/graph/badge.svg)](https://codecov.io/gh/pycqa/isort)
9[![License](https://img.shields.io/github/license/mashape/apistatus.svg)](https://pypi.org/project/isort/)
10[![Join the chat at https://gitter.im/timothycrosley/isort](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/timothycrosley/isort?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
11[![Downloads](https://pepy.tech/badge/isort)](https://pepy.tech/project/isort)
12[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
13[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)
14[![DeepSource](https://static.deepsource.io/deepsource-badge-light-mini.svg)](https://deepsource.io/gh/pycqa/isort/?ref=repository-badge)
15_________________
16
17[Read Latest Documentation](https://pycqa.github.io/isort/) - [Browse GitHub Code Repository](https://github.com/pycqa/isort/)
18_________________
19
20isort your imports, so you don't have to.
21
22isort is a Python utility / library to sort imports alphabetically, and
23automatically separated into sections and by type. It provides a command line
24utility, Python library and [plugins for various
25editors](https://github.com/pycqa/isort/wiki/isort-Plugins) to
26quickly sort all your imports. It requires Python 3.6+ to run but
27supports formatting Python 2 code too.
28
29- [Try isort now from your browser!](https://pycqa.github.io/isort/docs/quick_start/0.-try.html)
30- [Using black? See the isort and black compatibility guide.](https://pycqa.github.io/isort/docs/configuration/black_compatibility.html)
31- [isort has official support for pre-commit!](https://pycqa.github.io/isort/docs/configuration/pre-commit.html)
32
33![Example Usage](https://raw.github.com/pycqa/isort/main/example.gif)
34
35Before isort:
36
37```python
38from my_lib import Object
39
40import os
41
42from my_lib import Object3
43
44from my_lib import Object2
45
46import sys
47
48from third_party import lib15, lib1, lib2, lib3, lib4, lib5, lib6, lib7, lib8, lib9, lib10, lib11, lib12, lib13, lib14
49
50import sys
51
52from __future__ import absolute_import
53
54from third_party import lib3
55
56print("Hey")
57print("yo")
58```
59
60After isort:
61
62```python
63from __future__ import absolute_import
64
65import os
66import sys
67
68from third_party import (lib1, lib2, lib3, lib4, lib5, lib6, lib7, lib8,
69                         lib9, lib10, lib11, lib12, lib13, lib14, lib15)
70
71from my_lib import Object, Object2, Object3
72
73print("Hey")
74print("yo")
75```
76
77## Installing isort
78
79Installing isort is as simple as:
80
81```bash
82pip install isort
83```
84
85Install isort with requirements.txt support:
86
87```bash
88pip install isort[requirements_deprecated_finder]
89```
90
91Install isort with Pipfile support:
92
93```bash
94pip install isort[pipfile_deprecated_finder]
95```
96
97Install isort with both formats support:
98
99```bash
100pip install isort[requirements_deprecated_finder,pipfile_deprecated_finder]
101```
102
103## Using isort
104
105**From the command line**:
106
107To run on specific files:
108
109```bash
110isort mypythonfile.py mypythonfile2.py
111```
112
113To apply recursively:
114
115```bash
116isort .
117```
118
119If [globstar](https://www.gnu.org/software/bash/manual/html_node/The-Shopt-Builtin.html)
120is enabled, `isort .` is equivalent to:
121
122```bash
123isort **/*.py
124```
125
126To view proposed changes without applying them:
127
128```bash
129isort mypythonfile.py --diff
130```
131
132Finally, to atomically run isort against a project, only applying
133changes if they don't introduce syntax errors:
134
135```bash
136isort --atomic .
137```
138
139(Note: this is disabled by default, as it prevents isort from
140running against code written using a different version of Python.)
141
142**From within Python**:
143
144```python
145import isort
146
147isort.file("pythonfile.py")
148```
149
150or:
151
152```python
153import isort
154
155sorted_code = isort.code("import b\nimport a\n")
156```
157
158## Installing isort's for your preferred text editor
159
160Several plugins have been written that enable to use isort from within a
161variety of text-editors. You can find a full list of them [on the isort
162wiki](https://github.com/pycqa/isort/wiki/isort-Plugins).
163Additionally, I will enthusiastically accept pull requests that include
164plugins for other text editors and add documentation for them as I am
165notified.
166
167## Multi line output modes
168
169You will notice above the \"multi\_line\_output\" setting. This setting
170defines how from imports wrap when they extend past the line\_length
171limit and has [12 possible settings](https://pycqa.github.io/isort/docs/configuration/multi_line_output_modes.html).
172
173## Indentation
174
175To change the how constant indents appear - simply change the
176indent property with the following accepted formats:
177
178-   Number of spaces you would like. For example: 4 would cause standard
179    4 space indentation.
180-   Tab
181-   A verbatim string with quotes around it.
182
183For example:
184
185```python
186"    "
187```
188
189is equivalent to 4.
190
191For the import styles that use parentheses, you can control whether or
192not to include a trailing comma after the last import with the
193`include_trailing_comma` option (defaults to `False`).
194
195## Intelligently Balanced Multi-line Imports
196
197As of isort 3.1.0 support for balanced multi-line imports has been
198added. With this enabled isort will dynamically change the import length
199to the one that produces the most balanced grid, while staying below the
200maximum import length defined.
201
202Example:
203
204```python
205from __future__ import (absolute_import, division,
206                        print_function, unicode_literals)
207```
208
209Will be produced instead of:
210
211```python
212from __future__ import (absolute_import, division, print_function,
213                        unicode_literals)
214```
215
216To enable this set `balanced_wrapping` to `True` in your config or pass
217the `-e` option into the command line utility.
218
219## Custom Sections and Ordering
220
221isort provides configuration options to change almost every aspect of how
222imports are organized, ordered, or grouped together in sections.
223
224[Click here](https://pycqa.github.io/isort/docs/configuration/custom_sections_and_ordering.html) for an overview of all these options.
225
226## Skip processing of imports (outside of configuration)
227
228To make isort ignore a single import simply add a comment at the end of
229the import line containing the text `isort:skip`:
230
231```python
232import module  # isort:skip
233```
234
235or:
236
237```python
238from xyz import (abc,  # isort:skip
239                 yo,
240                 hey)
241```
242
243To make isort skip an entire file simply add `isort:skip_file` to the
244module's doc string:
245
246```python
247""" my_module.py
248    Best module ever
249
250   isort:skip_file
251"""
252
253import b
254import a
255```
256
257## Adding or removing an import from multiple files
258
259isort can be ran or configured to add / remove imports automatically.
260
261[See a complete guide here.](https://pycqa.github.io/isort/docs/configuration/add_or_remove_imports.html)
262
263## Using isort to verify code
264
265The `--check-only` option
266-------------------------
267
268isort can also be used to verify that code is correctly formatted
269by running it with `-c`. Any files that contain incorrectly sorted
270and/or formatted imports will be outputted to `stderr`.
271
272```bash
273isort **/*.py -c -v
274
275SUCCESS: /home/timothy/Projects/Open_Source/isort/isort_kate_plugin.py Everything Looks Good!
276ERROR: /home/timothy/Projects/Open_Source/isort/isort/isort.py Imports are incorrectly sorted.
277```
278
279One great place this can be used is with a pre-commit git hook, such as
280this one by \@acdha:
281
282<https://gist.github.com/acdha/8717683>
283
284This can help to ensure a certain level of code quality throughout a
285project.
286
287## Git hook
288
289isort provides a hook function that can be integrated into your Git
290pre-commit script to check Python code before committing.
291
292[More info here.](https://pycqa.github.io/isort/docs/configuration/git_hook.html)
293
294## Setuptools integration
295
296Upon installation, isort enables a `setuptools` command that checks
297Python files declared by your project.
298
299[More info here.](https://pycqa.github.io/isort/docs/configuration/setuptools_integration.html)
300
301## Spread the word
302
303[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)
304
305Place this badge at the top of your repository to let others know your project uses isort.
306
307For README.md:
308
309```markdown
310[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)
311```
312
313Or README.rst:
314
315```rst
316.. image:: https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336
317    :target: https://pycqa.github.io/isort/
318```
319
320## Security contact information
321
322To report a security vulnerability, please use the [Tidelift security
323contact](https://tidelift.com/security). Tidelift will coordinate the
324fix and disclosure.
325
326## Why isort?
327
328isort simply stands for import sort. It was originally called
329"sortImports" however I got tired of typing the extra characters and
330came to the realization camelCase is not pythonic.
331
332I wrote isort because in an organization I used to work in the manager
333came in one day and decided all code must have alphabetically sorted
334imports. The code base was huge - and he meant for us to do it by hand.
335However, being a programmer - I\'m too lazy to spend 8 hours mindlessly
336performing a function, but not too lazy to spend 16 hours automating it.
337I was given permission to open source sortImports and here we are :)
338
339------------------------------------------------------------------------
340
341[Get professionally supported isort with the Tidelift
342Subscription](https://tidelift.com/subscription/pkg/pypi-isort?utm_source=pypi-isort&utm_medium=referral&utm_campaign=readme)
343
344Professional support for isort is available as part of the [Tidelift
345Subscription](https://tidelift.com/subscription/pkg/pypi-isort?utm_source=pypi-isort&utm_medium=referral&utm_campaign=readme).
346Tidelift gives software development teams a single source for purchasing
347and maintaining their software, with professional grade assurances from
348the experts who know it best, while seamlessly integrating with existing
349tools.
350
351------------------------------------------------------------------------
352
353Thanks and I hope you find isort useful!
354
355~Timothy Crosley
356