使 isort 将 Django 应用程序的导入识别为第一方导入

问题描述 投票:0回答:1

我正在开发一个包含许多不同 Django 应用程序的项目。

我想在这个项目上使用

isort
,但来自 Django 应用程序 (
from myapp1.mymodule import myfunction
) 的导入被
isort
视为第三方导入。

我怎样才能让

isort
将它们识别为第一方导入?

我可以添加

isort
配置(在
.cfg
中):
known_first_party=myapp1,myapp2...
,但我必须维护这个列表。

有更好的方法吗?

python django isort
1个回答
7
投票

您可以使用

src_paths
选项指定项目文件夹。您不需要维护
known_first_party
列表。查看相关源码

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}.")
© www.soinside.com 2019 - 2024. All rights reserved.