Make isort recognize imports from Django apps as first-party imports
Asked Answered
C

1

8

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?

Cychosz answered 25/8, 2020 at 17:8 Comment(0)
T
7

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}.")
Titanium answered 10/11, 2020 at 13:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.