从 pantsbuild 中的 Python 包中导入所有库
Import all libraries from Python package in pantsbuild
我想将我的 models/sources 目录中的所有资源导入裤子中的另一个目标中构建我的 root/models/sources 内容:
├── base.py
├── BUILD
├── design.py
├── email.py
├── __init__.py
└── project_management.py
我的构建文件内容如下:
python_library(
name="base",
sources=["base.py"],
dependencies=["root/models/tokens/__init__.py:__init__"]
)
python_library(
name="design",
sources=["design.py"],
dependencies=[":base"]
)
python_library(
name="email",
sources=["email.py"],
dependencies=[":base"]
)
python_library(
name="project_management",
sources=["project_management.py"],
dependencies=[
":base",
"root/models/tokens/__init__.py:__init__"
]
)
python_library(
name="__init__",
sources=["__init__.py"],
dependencies=[
":base",
":design",
":email",
":project_management"
]
)
现在在另一个目标中,我有一个
from root.models.sources import *
如何设置其他目标的依赖项以导入 models/sources 中的所有库?
p.s 我知道使用 * 不是最好的,但这是最简单的形式。此外,init 是一个工厂。
导入 init 只要它是引用包中所有其他文件的工厂。
例如:
from root.models.sources.base import Source
from root.models.sources.design import DesignSource
from root.models.sources.email import EmailSource
from root.models.sources.project_management import \
ProjectManagementSource
def SourceFactory(source: str = "default"):
sources = {
"default": Source,
"foo1": ProjectManagementSource,
"foo2": ProjectManagementSource,
"foo3": ProjectManagementSource,
"foo4": ProjectManagementSource,
"foo5": ProjectManagementSource,
"foo6": ProjectManagementSource,
"foo7": ProjectManagementSource,
"foo8": EmailSource,
"foo9": DesignSource,
}
return sources[source] if source in sources.keys() else Source
我想将我的 models/sources 目录中的所有资源导入裤子中的另一个目标中构建我的 root/models/sources 内容:
├── base.py
├── BUILD
├── design.py
├── email.py
├── __init__.py
└── project_management.py
我的构建文件内容如下:
python_library(
name="base",
sources=["base.py"],
dependencies=["root/models/tokens/__init__.py:__init__"]
)
python_library(
name="design",
sources=["design.py"],
dependencies=[":base"]
)
python_library(
name="email",
sources=["email.py"],
dependencies=[":base"]
)
python_library(
name="project_management",
sources=["project_management.py"],
dependencies=[
":base",
"root/models/tokens/__init__.py:__init__"
]
)
python_library(
name="__init__",
sources=["__init__.py"],
dependencies=[
":base",
":design",
":email",
":project_management"
]
)
现在在另一个目标中,我有一个
from root.models.sources import *
如何设置其他目标的依赖项以导入 models/sources 中的所有库? p.s 我知道使用 * 不是最好的,但这是最简单的形式。此外,init 是一个工厂。
导入 init 只要它是引用包中所有其他文件的工厂。 例如:
from root.models.sources.base import Source
from root.models.sources.design import DesignSource
from root.models.sources.email import EmailSource
from root.models.sources.project_management import \
ProjectManagementSource
def SourceFactory(source: str = "default"):
sources = {
"default": Source,
"foo1": ProjectManagementSource,
"foo2": ProjectManagementSource,
"foo3": ProjectManagementSource,
"foo4": ProjectManagementSource,
"foo5": ProjectManagementSource,
"foo6": ProjectManagementSource,
"foo7": ProjectManagementSource,
"foo8": EmailSource,
"foo9": DesignSource,
}
return sources[source] if source in sources.keys() else Source