Search code examples
pythondjangoisort

Make isort recognize imports from Django apps as first-party imports


I'm working on a project with many different Django apps.

I want to use isort on this project but the imports from Django apps (from myapp1.mymodule import myfunction) are seen by isort as third-party imports.

How can I make isort recognize them as first-party imports?

I could add in the isort configuration (in the .cfg): known_first_party=myapp1,myapp2... but I'll have to maintain this list.

Is there a better way?


Solution

  • You can use the src_paths option to specify the project folder. You do not need to maintain a known_first_party list. See the related source code:

    if (
        _is_module(module_path)
        or _is_package(module_path)
        or _src_path_is_module(src_path, root_module_name)
    ):
        return (sections.FIRSTPARTY, f"Found in one of the configured src_paths: {src_path}.")