Parses stream identifying sections of contiguous imports and sorting them Code with unsorted imports is read from the provided `input_stream`, sorted and then outputted to the specified `output_stream`. - `input_stream`: Text stream with unsorted import sections. - `output_stream`:
(
input_stream: TextIO,
output_stream: TextIO,
extension: str = "py",
raise_on_skip: bool = True,
config: Config = DEFAULT_CONFIG,
)
| 35 | # Ignore DeepSource cyclomatic complexity check for this function. |
| 36 | # skipcq: PY-R1000 |
| 37 | def process( |
| 38 | input_stream: TextIO, |
| 39 | output_stream: TextIO, |
| 40 | extension: str = "py", |
| 41 | raise_on_skip: bool = True, |
| 42 | config: Config = DEFAULT_CONFIG, |
| 43 | ) -> bool: |
| 44 | """Parses stream identifying sections of contiguous imports and sorting them |
| 45 | |
| 46 | Code with unsorted imports is read from the provided `input_stream`, sorted and then |
| 47 | outputted to the specified `output_stream`. |
| 48 | |
| 49 | - `input_stream`: Text stream with unsorted import sections. |
| 50 | - `output_stream`: Text stream to output sorted inputs into. |
| 51 | - `config`: Config settings to use when sorting imports. Defaults settings. |
| 52 | - *Default*: `isort.settings.DEFAULT_CONFIG`. |
| 53 | - `extension`: The file extension or file extension rules that should be used. |
| 54 | - *Default*: `"py"`. |
| 55 | - *Choices*: `["py", "pyi", "pyx"]`. |
| 56 | |
| 57 | Returns `True` if there were changes that needed to be made (errors present) from what |
| 58 | was provided in the input_stream, otherwise `False`. |
| 59 | """ |
| 60 | line_separator: str = config.line_ending |
| 61 | add_imports: list[str] = [format_natural(addition) for addition in config.add_imports] |
| 62 | import_section: str = "" |
| 63 | next_import_section: str = "" |
| 64 | next_cimports: bool = False |
| 65 | in_quote: str = "" |
| 66 | was_in_quote: bool = False |
| 67 | first_comment_index_start: int = -1 |
| 68 | first_comment_index_end: int = -1 |
| 69 | contains_imports: bool = False |
| 70 | in_top_comment: bool = False |
| 71 | first_import_section: bool = True |
| 72 | indent: str = "" |
| 73 | isort_off: bool = False |
| 74 | skip_file: bool = False |
| 75 | code_sorting: bool | str = False |
| 76 | code_sorting_section: str = "" |
| 77 | code_sorting_indent: str = "" |
| 78 | cimports: bool = False |
| 79 | made_changes: bool = False |
| 80 | stripped_line: str = "" |
| 81 | end_of_file: bool = False |
| 82 | verbose_output: list[str] = [] |
| 83 | lines_before: list[str] = [] |
| 84 | is_reexport: bool = False |
| 85 | reexport_rollback: int = 0 |
| 86 | |
| 87 | if config.float_to_top: |
| 88 | new_input = "" |
| 89 | current = "" |
| 90 | isort_off = False |
| 91 | for line in chain(input_stream, (None,)): |
| 92 | if isort_off and line is not None: |
| 93 | if line == "# isort: on\n": |
| 94 | isort_off = False |
nothing calls this directly
no test coverage detected
searching dependent graphs…