### isort Profile Examples Source: https://github.com/pycqa/isort/blob/main/docs/major_releases/introducing_isort_5.md Use profiles to apply common isort configurations without manual setup. Examples include black, django, pycharm, google, open_stack, plone, attrs, and hug. ```bash isort --profile black . isort --profile django . isort --profile pycharm . isort --profile google . isort --profile open_stack . isort --profile plone . isort --profile attrs . isort --profile hug . ``` -------------------------------- ### CI configuration for isort and black Source: https://github.com/pycqa/isort/blob/main/docs/configuration/black_compatibility.md Example .travis.yml configuration demonstrating how to install and run both isort with the black profile and black for code checking in a CI environment. ```yaml language: python python: - "3.10" install: - pip install -r requirements-dev.txt - pip install isort black - pip install coveralls script: - pytest my-package - isort --profile black my-package - black --check --diff my-package after_success: - coveralls ``` -------------------------------- ### Start Docker development environment Source: https://github.com/pycqa/isort/blob/main/docs/contributing/1.-contributing-guide.md Initiates the Docker development environment for isort. This requires Docker to be installed and running. ```bash ./scripts/docker.sh ``` -------------------------------- ### Example .isort.cfg for separate_packages Source: https://github.com/pycqa/isort/blob/main/docs/configuration/options.md Configuration example for the separate_packages option in an .isort.cfg file. This option specifies packages to be separated by newlines. ```default [settings] separate_packages=THIRDPARTY ``` -------------------------------- ### Install isort with uv Source: https://github.com/pycqa/isort/blob/main/docs/quick_start/1.-install.md Use this command to install isort using uv, a fast Python package installer and resolver. ```bash uv add isort ``` -------------------------------- ### Install dependencies with uv Source: https://github.com/pycqa/isort/blob/main/docs/contributing/1.-contributing-guide.md Synchronize project dependencies using uv. The --all-extras flag installs all optional dependencies, and --frozen ensures exact versions are used. ```bash uv sync --all-extras --frozen ``` -------------------------------- ### Install isort with pip Source: https://github.com/pycqa/isort/blob/main/docs/quick_start/1.-install.md Use this command to install isort using pip, the standard Python package installer. ```bash pip3 install isort ``` -------------------------------- ### Example .isort.cfg Configuration Source: https://github.com/pycqa/isort/blob/main/docs/configuration/config_files.md This snippet shows a basic configuration for isort using the .isort.cfg format. It specifies the profile and source paths. ```ini [settings] profile=hug src_paths=isort,test ``` -------------------------------- ### Example of import sorting before separate_packages Source: https://github.com/pycqa/isort/blob/main/docs/configuration/options.md Demonstrates the import order before applying the separate_packages configuration. This example shows standard import grouping. ```python import os import sys from django.db.models.signals import m2m_changed from django.utils import functional from django_filters import BooleanFilter from junitparser import JUnitXml from loguru import logger ``` -------------------------------- ### Example of import sorting after separate_packages Source: https://github.com/pycqa/isort/blob/main/docs/configuration/options.md Demonstrates the import order after applying the separate_packages configuration. This example shows how packages are separated by newlines. ```python import os import sys from django.db.models.signals import m2m_changed from django.utils import functional from django_filters import BooleanFilter from junitparser import JUnitXml from loguru import logger ``` -------------------------------- ### Example pyproject.toml for separate_packages Source: https://github.com/pycqa/isort/blob/main/docs/configuration/options.md Configuration example for the separate_packages option in a pyproject.toml file. This option specifies packages to be separated by newlines. ```toml [tool.isort] separate_packages = ["THIRDPARTY"] ``` -------------------------------- ### Install isort with pipx Source: https://github.com/pycqa/isort/blob/main/docs/quick_start/1.-install.md Use this command for a fully isolated user installation of isort using pipx. ```bash pipx install isort ``` -------------------------------- ### isort Example: Before and After Source: https://github.com/pycqa/isort/blob/main/docs/index.md Compares unsorted imports with the output after isort has been applied. Demonstrates automatic sorting and section separation. ```python from my_lib import Object import os from my_lib import Object3 from my_lib import Object2 import sys from third_party import lib15, lib1, lib2, lib3, lib4, lib5, lib6, lib7, lib8, lib9, lib10, lib11, lib12, lib13, lib14 import sys from __future__ import absolute_import from third_party import lib3 print("Hey") print("yo") ``` ```python from __future__ import absolute_import import os import sys from third_party import ( lib1, lib2, lib3, lib4, lib5, lib6, lib7, lib8, lib9, lib10, lib11, lib12, lib13, lib14, lib15, ) from my_lib import Object, Object2, Object3 print("Hey") print("yo") ``` -------------------------------- ### Verify isort Installation Source: https://github.com/pycqa/isort/blob/main/docs/quick_start/2.-cli.md Run this command to check if isort is installed correctly and view available commands and version information. ```bash isort ``` -------------------------------- ### Install isort with pipenv Source: https://github.com/pycqa/isort/blob/main/docs/quick_start/1.-install.md Use this command to install isort using pipenv, a tool that aims to bring the best of all packaging worlds to the Python world. ```bash pipenv install isort ``` -------------------------------- ### Reverse Relative Import Sorting Example Source: https://github.com/pycqa/isort/wiki/isort-Settings Illustrates how 'reverse_relative' modifies the sorting of relative imports to follow Google style guide conventions. ```python from . import y from ..import x ``` ```python from .. import x from . import y ``` -------------------------------- ### Example .isort.cfg for single_line_exclusions Source: https://github.com/pycqa/isort/blob/main/docs/configuration/options.md Demonstrates how to configure single_line_exclusions in an .isort.cfg file. Use this to specify modules that should be excluded from the single line import rule. ```default [settings] single_line_exclusions=os,json ``` -------------------------------- ### Example GitHub Action Workflow Source: https://github.com/pycqa/isort/blob/main/docs/configuration/github_action.md This snippet shows a basic GitHub Actions workflow that uses the isort action. It checks out the code, sets up Python, and then runs the isort action, specifying multiple requirements files. ```yaml name: Run isort on: - push jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: python-version: 3.13 - uses: isort/isort-action@v1 with: requirementsFiles: "requirements.txt requirements-test.txt" ``` -------------------------------- ### Display isort Version Source: https://github.com/pycqa/isort/blob/main/docs/configuration/options.md Use the -V or --version flags to display the currently installed version of isort. ```bash isort --version ``` -------------------------------- ### Example isort Configuration Source: https://github.com/pycqa/isort/blob/main/docs/quick_start/0.-try.md This JSON object represents a sample configuration for isort, specifying a line length of 80 characters, the 'black' profile, and enabling atomic sorting. ```json {"line_length": 80, "profile": "black", "atomic": true } ``` -------------------------------- ### Install isort with poetry Source: https://github.com/pycqa/isort/blob/main/docs/quick_start/1.-install.md Use this command to add isort as a dependency using poetry, a dependency management tool for Python. ```bash poetry add isort ``` -------------------------------- ### Live isort Editor Setup Source: https://github.com/pycqa/isort/blob/main/docs/quick_start/0.-try.md This JavaScript code initializes the Ace editor instances for input, output, and configuration. It sets up event listeners to update the output whenever the input or configuration changes. The core functionality is provided by the `sort_code` Python function, which is exposed to JavaScript. ```javascript window.addEventListener("load", () => { var input = ace.edit("inputEditor"); var output = ace.edit("outputEditor"); var configurator = ace.edit("configEditor"); [input, output, configurator].forEach((editor) => { editor.setTheme("ace/theme/monokai"); editor.session.setMode("ace/mode/python"); editor.resize(); }); configurator.session.setMode("ace/mode/json"); function updateOutput() { output.setValue(document.sort_code(input.getValue(), configurator.getValue())); } output.setReadOnly(true); input.session.on("change", updateOutput); configurator.session.on("change", updateOutput); document.updateOutput = updateOutput; }); ``` -------------------------------- ### Example Input Code for isort Source: https://github.com/pycqa/isort/blob/main/docs/quick_start/0.-try.md This is a sample Python code snippet demonstrating import statements that can be formatted by isort. It includes duplicate imports and imports from the 'future' module. ```python from future import braces import b import b import os import a from future import braces import b import a import b, a ``` -------------------------------- ### Example pyproject.toml for single_line_exclusions Source: https://github.com/pycqa/isort/blob/main/docs/configuration/options.md Shows the configuration of single_line_exclusions within a pyproject.toml file. This is an alternative to .isort.cfg for specifying modules to exclude from single line imports. ```toml [tool.isort] single_line_exclusions = ["os", "json"] ``` -------------------------------- ### Add Imports in .isort.cfg Source: https://github.com/pycqa/isort/blob/main/docs/configuration/options.md Specify imports to be added to all files using the add_imports option in an .isort.cfg file. This example adds 'import os' and 'import json'. ```ini [settings] add_imports=import os,import json ``` -------------------------------- ### isort - After Sorting Imports Source: https://github.com/pycqa/isort/blob/main/README.md This code snippet illustrates the result of applying isort to the 'Before isort' example. It shows imports sorted alphabetically, grouped by type, and formatted for better readability. ```python from __future__ import absolute_import import os import sys from third_party import ( lib1, lib2, lib3, lib4, lib5, lib6, lib7, lib8, lib9, lib10, lib11, lib12, lib13, lib14, lib15 ) from my_lib import Object, Object2, Object3 print("Hey") print("yo") ``` -------------------------------- ### Force Alphabetical Sort Example Source: https://github.com/pycqa/isort/wiki/isort-Settings Demonstrates how 'force_alphabetical_sort' changes the import order from grouped sections to a single alphabetical section. ```python from os import path import os ``` ```python import os from os import path ``` -------------------------------- ### Pyodide and isort Integration Source: https://github.com/pycqa/isort/blob/main/docs/quick_start/0.-try.md This asynchronous JavaScript function loads Pyodide, installs the 'isort' package using micropip, and then runs a Python script. The Python script defines a `sort_code` function that uses isort to sort imports based on provided code and configuration, making it accessible to the browser's JavaScript environment. ```javascript async function main() { let pyodide = await loadPyodide(); await pyodide.loadPackage("micropip"); const micropip = pyodide.pyimport("micropip"); await micropip.install("isort"); await pyodide.runPython( ` from js import document import isort import json import textwrap def sort_code(code, configuration): try: configuration = json.loads(configuration or "{}") except Exception as configuration_error: return "\\n".join(textwrap.wrap(f"Exception thrown trying to read given configuration {configuration_error}", 40)) try: return f"# Using {isort._\_version_\_} of isort." + "\\n\\n" + isort.code(code, **configuration) except Exception as isort_error: return "\\n".join(textwrap.wrap(f"Exception thrown trying to sort given imports {isort_error}", 40)) document.sort_code = sort_code document.updateOutput() ` ); } ``` -------------------------------- ### Configure PyCharm File Watcher for isort Source: https://github.com/pycqa/isort/wiki/isort-Plugins This configuration sets up PyCharm to automatically run isort on Python files. Ensure the File Watchers plugin is installed and configure the program, arguments, and paths as shown. ```text Name: isort File Type: Python Scope: Project Files Program: $PyInterpreterDirectory$/isort Arguments: $FilePath$ Output paths to refresh: $FilePath$ Working directory: $ProjectFileDir$ In Advanced Options Uncheck "Auto-save edited files to trigger the watcher" Uncheck "Trigger the watcher on external changes" ``` -------------------------------- ### Configure Shared Profile Entry Point Source: https://github.com/pycqa/isort/blob/main/docs/howto/shared_profiles.md Use this configuration in your .isort.cfg file to specify the entry point for your custom shared profile. Replace `my_module:PROFILE` with the actual module and variable name where your profile settings are defined. ```default [options.entry_points] isort.profiles = shared_profile=my_module:PROFILE ``` -------------------------------- ### View All CLI Options Source: https://github.com/pycqa/isort/blob/main/docs/quick_start/2.-cli.md Access the full list of command-line options for isort by running this command. Refer to the online configuration reference for detailed explanations. ```bash isort --help ``` -------------------------------- ### Auto-commented Import Sections Output Source: https://github.com/pycqa/isort/blob/main/docs/configuration/custom_sections_and_ordering.md Example of how isort formats imports with auto-commented sections. ```python # Standard Library import os import sys import django.settings # My Stuff import myproject.test ``` -------------------------------- ### Resolving All Configurations in a Directory Source: https://github.com/pycqa/isort/blob/main/docs/configuration/config_files.md Enable isort to respect separate configuration settings in different sub-directories. Use --resolve-all-configs along with --config-root to apply the nearest configuration file to each file. ```bash isort --resolve-all-configs --config-root directory_root ``` -------------------------------- ### Configure Length Sort Sections in pyproject.toml Source: https://github.com/pycqa/isort/blob/main/docs/configuration/options.md Set the length_sort_sections option in a pyproject.toml file. This example configures it for 'future' and 'stdlib' sections. ```toml [tool.isort] length_sort_sections = ["future", "stdlib"] ``` -------------------------------- ### Using a Custom Settings File Source: https://github.com/pycqa/isort/blob/main/docs/configuration/config_files.md Specify a custom configuration file path for isort using the --settings-file option. This is useful for managing different configurations for different file types or projects. ```bash isort --settings-file .isort.custom.cfg ``` -------------------------------- ### Remove Imports in pyproject.toml Source: https://github.com/pycqa/isort/blob/main/docs/configuration/options.md Configure the remove_imports option in a pyproject.toml file to specify imports to be removed from all files. This example removes 'os' and 'json'. ```toml [tool.isort] remove_imports = ["os", "json"] ``` -------------------------------- ### Remove Imports in .isort.cfg Source: https://github.com/pycqa/isort/blob/main/docs/configuration/options.md Use the remove_imports option in an .isort.cfg file to specify imports that should be removed from all files. This example removes 'os' and 'json'. ```ini [settings] remove_imports=os,json ``` -------------------------------- ### Add Imports in pyproject.toml Source: https://github.com/pycqa/isort/blob/main/docs/configuration/options.md Configure the add_imports option in a pyproject.toml file to specify imports that should be added to all files. This example adds 'import os' and 'import json'. ```toml [tool.isort] add_imports = ["import os", "import json"] ``` -------------------------------- ### Recommended Usage for Multiple Projects Source: https://github.com/pycqa/isort/blob/main/docs/quick_start/2.-cli.md When managing multiple independent projects, run isort commands separately for each project to avoid configuration conflicts. ```bash # YES isort project1 isort project2 # Also YES isort project1/src project1/test isort project2/src project2/test # NO isort project1 project2 ``` -------------------------------- ### Format an Entire Project Source: https://github.com/pycqa/isort/blob/main/docs/quick_start/2.-cli.md Use this command to sort imports recursively in all Python source files within the current directory or a specified 'src' directory. Configuration files in the project root are automatically detected. ```bash isort . ``` ```bash isort src ``` ```bash isort . --profile black ``` -------------------------------- ### Configure Length Sort Sections in .isort.cfg Source: https://github.com/pycqa/isort/blob/main/docs/configuration/options.md Set the length_sort_sections option in an .isort.cfg file to sort sections by length. This example shows how to configure it for 'future' and 'stdlib' sections. ```ini [settings] length_sort_sections=future,stdlib ``` -------------------------------- ### Configure Source Paths in .isort.cfg Source: https://github.com/pycqa/isort/blob/main/docs/configuration/options.md Specify source paths in an .isort.cfg file. Glob expansion is supported for these paths. ```ini [settings] src_paths = src,tests ``` -------------------------------- ### GitHub Actions Workflow for Build and Deploy Source: https://github.com/pycqa/isort/wiki/_Footer This workflow automates the process of building and deploying a project to Azure Web App on pushes to the main branch or via manual dispatch. It requires Node.js and npm for dependency management and build steps. ```yaml name: Build and Deploy to Azure Web App on: push: branches: - main # or 'master' if you're old-school workflow_dispatch: jobs: build-and-deploy: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v4 - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: 20.x cache: 'npm' - name: Install dependencies run: npm install - name: Build project (optional) run: npm run build # Remove or change this if you don’t have a build script - name: Deploy to Azure Web App uses: azure/webapps-deploy@v3 with: app-name: your-app-name slot-name: Production publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }} package: .package-lock.json ``` -------------------------------- ### Configure Extra Standard Library in .isort.cfg Source: https://github.com/pycqa/isort/blob/main/docs/configuration/options.md Add extra modules to the list of standard library modules in an .isort.cfg file. ```default [settings] extra_standard_library=my_module1,my_module2 ``` -------------------------------- ### isort Configuration in setup.cfg Source: https://github.com/pycqa/isort/blob/main/docs/configuration/config_files.md Configure isort within the [isort] section of a setup.cfg file. This is an alternative for projects that rely on setup.cfg for other configurations. ```ini [isort] profile=hug src_paths=isort,test ``` -------------------------------- ### isort.place_module_with_reason Source: https://github.com/pycqa/isort/blob/main/docs/quick_start/3.-api.md Determines the categorization of a module and the reason for that categorization. Returns both as a string. ```APIDOC ## isort.place_module_with_reason ### Description Takes the name of a module as a string and returns the categorization determined for it and why that categorization was given. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python import isort # Example: Get categorization and reason for the 'os' module category, reason = isort.place_module_with_reason("os") print(f"Module 'os': Category='{category}', Reason='{reason}'") # Example: Get categorization and reason for a hypothetical third-party module category_third_party, reason_third_party = isort.place_module_with_reason("requests") print(f"Module 'requests': Category='{category_third_party}', Reason='{reason_third_party}'") ``` ### Response #### Success Response (200) - **category** (str) - The determined category for the module. - **reason** (str) - The reason for the determined category. ``` -------------------------------- ### Configure Multi-Line Output in .isort.cfg Source: https://github.com/pycqa/isort/blob/main/docs/configuration/options.md Set the multi-line output mode for isort in an .isort.cfg file. Mode 3 corresponds to 'vert-hanging'. ```default [settings] multi_line_output=3 ``` -------------------------------- ### Run all tests and cleanup scripts Source: https://github.com/pycqa/isort/blob/main/docs/contributing/1.-contributing-guide.md A convenience script that runs both the test and cleanup scripts in one step. ```bash ./scripts/done.sh ``` -------------------------------- ### isort.place.module_with_reason Source: https://github.com/pycqa/isort/blob/main/docs/reference/isort.md Returns the section placement for a module name along with the reasoning behind the placement. ```APIDOC ## isort.place.module_with_reason ### Description Returns the section placement for the given module name alongside the reasoning. ### Signature isort.place.module_with_reason(name: str, config: Optional[Config] = DEFAULT_CONFIG) -> Tuple[str, str] ### Parameters #### Path Parameters - **name** (str) - The name of the module. - **config** (Optional[Config]) - The configuration object to use. Defaults to `DEFAULT_CONFIG`. ### Returns (Tuple[str, str]) A tuple containing the section placement and the reasoning. ``` -------------------------------- ### isort pre-commit configuration for different file types Source: https://github.com/pycqa/isort/blob/main/docs/configuration/pre-commit.md Configure isort to handle different file types like Python, Cython, and Pyi separately by specifying types for each hook. ```yaml - repo: https://github.com/pycqa/isort rev: 6.1.0 hooks: - id: isort name: isort (python) - id: isort name: isort (cython) types: [cython] - id: isort name: isort (pyi) types: [pyi] ``` -------------------------------- ### Run local tests and cleanup scripts Source: https://github.com/pycqa/isort/blob/main/docs/contributing/1.-contributing-guide.md Execute the test script to check for issues and the cleanup script to report on packages. These can be run individually or together. ```bash ./scripts/test.sh ``` ```bash ./scripts/clean.sh ``` -------------------------------- ### Use black profile with isort CLI Source: https://github.com/pycqa/isort/blob/main/docs/configuration/black_compatibility.md When running isort from the command line, use the --profile black argument to apply the black compatibility settings. ```bash isort --profile black my-package ``` -------------------------------- ### isort.api.place_module_with_reason Source: https://github.com/pycqa/isort/blob/main/docs/reference/isort.md Returns the section placement for the given module name alongside the reasoning. ```APIDOC ## isort.api.place_module_with_reason ### Description Returns the section placement for the given module name alongside the reasoning. ### Parameters #### Path Parameters - **name** (string) - Required - The name of the module. - **config** (object) - Optional - The config object to use. Defaults to DEFAULT_CONFIG. ``` -------------------------------- ### Configure Multi-Line Output in pyproject.toml Source: https://github.com/pycqa/isort/blob/main/docs/configuration/options.md Set the multi-line output mode for isort in a pyproject.toml file. Mode 3 corresponds to 'vert-hanging'. ```default [tool.isort] multi_line_output = 3 ``` -------------------------------- ### Configure no_lines_before in .isort.cfg Source: https://github.com/pycqa/isort/blob/main/docs/configuration/options.md Use this option to specify sections that should not be split from previous imports by an empty line. This configuration is for the .isort.cfg file format. ```default [settings] no_lines_before=future,stdlib ``` -------------------------------- ### Configure Source Paths in pyproject.toml Source: https://github.com/pycqa/isort/blob/main/docs/configuration/options.md Specify source paths in a pyproject.toml file. Glob expansion is supported for these paths. ```toml [tool.isort] src_paths = ["src", "tests"] ``` -------------------------------- ### Configure Known Standard Library in .isort.cfg Source: https://github.com/pycqa/isort/blob/main/docs/configuration/options.md Specify modules to be treated as part of Python's standard library in an .isort.cfg file. ```default [settings] known_standard_library=my_module1,my_module2 ``` -------------------------------- ### Default isort Sections Source: https://github.com/pycqa/isort/blob/main/docs/configuration/custom_sections_and_ordering.md The default order of import sections in isort. ```ini FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,LOCALFOLDER ``` -------------------------------- ### Configure 'treat_comments_as_code' in .isort.cfg Source: https://github.com/pycqa/isort/blob/main/docs/configuration/options.md Set the 'treat_comments_as_code' option in an .isort.cfg file to specify comments that should be treated as code. ```ini [settings] treat_comments_as_code = # my comment 1, # my other comment ``` -------------------------------- ### Configure Supported Extensions in pyproject.toml Source: https://github.com/pycqa/isort/blob/main/docs/configuration/options.md Specify custom file extensions for isort to process using the pyproject.toml configuration file. ```default [tool.isort] supported_extensions = ["pyw", "ext"] ``` -------------------------------- ### Verbose Output for Config File Confirmation Source: https://github.com/pycqa/isort/blob/main/docs/configuration/config_files.md Confirm which configuration file was used for a specific file by running isort with the --verbose flag. This helps in debugging and understanding the applied configurations. ```bash isort --verbose ``` -------------------------------- ### Configure Supported Extensions in .isort.cfg Source: https://github.com/pycqa/isort/blob/main/docs/configuration/options.md Specify custom file extensions for isort to process using the .isort.cfg configuration file. ```default [settings] supported_extensions=pyw,ext ``` -------------------------------- ### Basic isort pre-commit configuration Source: https://github.com/pycqa/isort/blob/main/docs/configuration/pre-commit.md Add this configuration to your .pre-commit-config.yaml to include isort as a pre-commit hook for Python files. ```yaml - repo: https://github.com/pycqa/isort rev: 6.1.0 hooks: - id: isort name: isort (python) ``` -------------------------------- ### Defining Custom Sections Source: https://github.com/pycqa/isort/blob/main/docs/configuration/custom_sections_and_ordering.md Create new custom sections for specific modules and define their order within the import structure. ```ini known_django=django known_pandas=pandas,numpy sections=FUTURE,STDLIB,DJANGO,THIRDPARTY,PANDAS,FIRSTPARTY,LOCALFOLDER ``` -------------------------------- ### Cython Support in isort Source: https://github.com/pycqa/isort/blob/main/docs/major_releases/introducing_isort_5.md isort 5 now includes seamless support for sorting imports in Cython (.pyx) files. ```python cimport ctime from cpython cimport PyLong_FromVoidPtr from cpython cimport bool as py_bool from cython.operator cimport dereference as deref from cython.operator cimport preincrement as preinc from libc.stdint cimport uint64_t, uintptr_t from libc.stdlib cimport atoi, calloc, free, malloc from libc.string cimport memcpy, strlen from libcpp cimport bool as cpp_bool from libcpp.map cimport map as cpp_map from libcpp.pair cimport pair as cpp_pair from libcpp.string cimport string as cpp_string from libcpp.vector cimport vector as cpp_vector from multimap cimport multimap as cpp_multimap from wstring cimport wstring as cpp_wstring ``` -------------------------------- ### Customizing Section Order Source: https://github.com/pycqa/isort/blob/main/docs/configuration/custom_sections_and_ordering.md Reorder the default import sections to your preference. ```ini sections=FUTURE,STDLIB,FIRSTPARTY,THIRDPARTY,LOCALFOLDER ``` -------------------------------- ### Define Custom Import Sections in .isort.cfg Source: https://github.com/pycqa/isort/blob/main/docs/configuration/options.md Define custom import sections and specify modules for a custom section like 'airflow' in an .isort.cfg file. ```default [settings] sections=FUTURE,STDLIB,THIRDPARTY,AIRFLOW,FIRSTPARTY,LOCALFOLDER known_airflow=airflow ``` -------------------------------- ### Default Multi-line Imports Source: https://github.com/pycqa/isort/blob/main/README.md Illustrates the default behavior for multi-line imports without balanced wrapping enabled. This can sometimes lead to less visually appealing arrangements. ```python from __future__ import (absolute_import, division, print_function, unicode_literals) ``` -------------------------------- ### Format specific Python files Source: https://github.com/pycqa/isort/blob/main/README.md Run isort on one or more specified Python files. ```bash isort mypythonfile.py mypythonfile2.py ``` -------------------------------- ### Clone the isort repository Source: https://github.com/pycqa/isort/blob/main/docs/contributing/1.-contributing-guide.md Clone your forked repository of isort to your local file system. Ensure you replace $GITHUB_ACCOUNT with your GitHub username. ```bash git clone https://github.com/$GITHUB_ACCOUNT/isort.git ``` -------------------------------- ### Configure Extra Standard Library in pyproject.toml Source: https://github.com/pycqa/isort/blob/main/docs/configuration/options.md Add extra modules to the list of standard library modules in a pyproject.toml file. ```default [tool.isort] extra_standard_library = ["my_module1", "my_module2"] ``` -------------------------------- ### Configure Known Standard Library in pyproject.toml Source: https://github.com/pycqa/isort/blob/main/docs/configuration/options.md Specify modules to be treated as part of Python's standard library in a pyproject.toml file. ```default [tool.isort] known_standard_library = ["my_module1", "my_module2"] ``` -------------------------------- ### Verify Project Imports Source: https://github.com/pycqa/isort/blob/main/docs/quick_start/2.-cli.md This command checks if imports are correctly formatted without modifying any files. It's useful for CI/CD pipelines. ```bash isort --check . ``` -------------------------------- ### Build isort Docker image Source: https://github.com/pycqa/isort/blob/main/docs/contributing/1.-contributing-guide.md Builds the Docker image for isort with the tag 'latest'. This is a prerequisite for running isort within a Docker container. ```bash docker build ./ -t isort:latest ``` -------------------------------- ### Configure Known Third Party Modules in .isort.cfg Source: https://github.com/pycqa/isort/blob/main/docs/configuration/options.md Specify third-party modules in the .isort.cfg file. This ensures isort recognizes and sorts these modules correctly. ```ini [settings] known_third_party=my_module1,my_module2 ``` -------------------------------- ### Configure Python Version via CLI Source: https://github.com/pycqa/isort/blob/main/docs/configuration/options.md Use the --py or --python-version flag to specify the target Python version when running isort from the command line. ```bash isort --py 39 ``` -------------------------------- ### Run local tests after changes (Docker) Source: https://github.com/pycqa/isort/blob/main/docs/contributing/1.-contributing-guide.md Runs the isort Docker container to execute tests after making local code changes. This is the Docker equivalent of './scripts/done.sh'. ```bash docker run isort:latest ``` -------------------------------- ### Extend Skip List in pyproject.toml Source: https://github.com/pycqa/isort/blob/main/docs/configuration/options.md Configure `extend_skip` in `pyproject.toml` to list multiple file extensions or names that isort should skip. This provides a TOML-based alternative to `.isort.cfg`. ```default [tool.isort] extend_skip = [".md", ".json"] ``` -------------------------------- ### isort.place_module Source: https://github.com/pycqa/isort/blob/main/docs/quick_start/3.-api.md Determines the categorization of a given module name. Returns the categorization as a string. ```APIDOC ## isort.place_module ### Description Takes the name of a module as a string and returns the categorization determined for it. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python import isort # Example: Categorize the 'os' module category = isort.place_module("os") print(f"Category for 'os': {category}") # Example: Categorize a hypothetical third-party module category_third_party = isort.place_module("requests") print(f"Category for 'requests': {category_third_party}") ``` ### Response #### Success Response (200) - **category** (str) - The determined category for the module (e.g., 'STDLIB', 'THIRDPARTY', 'FIRSTPARTY', 'LOCALFOLDER'). ``` -------------------------------- ### Run isort Docker container Source: https://github.com/pycqa/isort/blob/main/docs/contributing/1.-contributing-guide.md Runs the isort Docker container. If this fails, further debugging is required. ```bash docker run isort ``` -------------------------------- ### Interactive Docker shell for debugging Source: https://github.com/pycqa/isort/blob/main/docs/contributing/1.-contributing-guide.md Provides an interactive bash shell within the isort Docker container. This is useful for debugging failed builds or tests. ```bash docker run -it isort bash ``` -------------------------------- ### Skipping Multiple Files via Command Line Source: https://github.com/pycqa/isort/wiki/isort-Settings Use this to specify multiple files that should be skipped during the sorting process. ```bash isort --skip file1.py --skip file2.py ``` -------------------------------- ### Format a Python file from within Python Source: https://github.com/pycqa/isort/blob/main/README.md Use the `isort.file()` function to format the contents of a specified Python file. ```python import isort isort.file("pythonfile.py") ```