在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
目前没有回答
相关问题 更多 >
编程相关推荐