python - 有没有办法让 isort 自动检测具有多个独立包的代码库中的第一方和第三方模块?
问题描述
在project
代码库中,一个名为 的文件夹中有多个独立包plugins
,每个包都在自己的文件夹中,其中有一个setup.py
文件,项目本身是一个带有自己setup.py
文件的 python 包。
我有两个文件夹,project/project
和plugins/myplugin_one/project_plugins/myplugin_one
,我需要在适当first_party
的third_party
时候考虑。例如,在 里面plugins/myplugin_one/project_plugins/myplugin_one
,有一个文件config.py
,代码如下:
from dataclasses import dataclass, field
from typing import Any, Dict, List, Optional
# First Party
from project.core.config_store import ConfigStore
导入from project.core.config_store import ConfigStore
被视为first_party
导入,但应被视为third_party
导入,因为文件位于plugins/myplugin_one/project_plugins/myplugin_one
并且myplugin_one
是独立包 ( first_party
),而project
在third_party
此上下文中。
同样,对于驻留在文件内部的任何导入project/project
,project/project
都应考虑并应考虑first_party
导入自。plugins/myplugin_one/project_plugins/myplugin_one
third_party
项目的sections
顺序应该是:
sections=
FUTURE
STDLIB
THIRDPARTY
FIRSTPARTY
LOCALFOLDER
这是从 isort 4 到 isort 5.4.2 的升级,因此默认部分不再first_party
,但默认情况third_party
下__init__.py
不会跳过。
这是我的isort.cfg
文件:
[settings]
multi_line_output=3
include_trailing_comma=True
force_grid_wrap=0
use_parentheses=True
float_to_top = true
line_length=88
ensure_newline_before_comments=True
sections=
FUTURE
STDLIB
THIRDPARTY
FIRSTPARTY
LOCALFOLDER
import_heading_stdlib=Standard Library
import_heading_firstparty=First Party
import_heading_thirdparty=Third Party
import_heading_localfolder=Local Folder
known_first_party=project,project_plugins
known_local_folder=build_helpers,tests
src_paths=
skip=
__init__.py
解决方案
推荐阅读
- json - 如何从 angular6/7 中的帖子中获取大 json
- apache-nifi - Nifi - PutDatabaseRecord 中的 NULL 问题
- c++ - 从远程设备解压整数值的安全方法
- .htaccess - 如何在 htaccess 中设置基本目录
- graph - 您如何在链接图中显示具有指向同一对象的两个不同谓词的主题?
- amazon-web-services - 使用 S3 静态网站托管重定向到无法在 chrome 中工作的 WWW
- python - CSV 文件 IndexError:列表索引超出范围
- mysql - Mysql用法“AS”
- node.js - 寻找具有特定要求的 NodeJS 电子请求模块
- html - VS Code - 如何阻止它删除空格?