【发布时间】:2019-07-08 13:07:16
【问题描述】:
我已经构建了一个 python (3.6) CLI,它应该允许通过命名空间cli.plugins 加载插件。插件应该是单独的可测试存储库,用于导入 cli.utils 等模块以实现通用功能。
如果 CLI 具有文件夹结构:
- cli
- __init__.py
- utils
- plugins.py
- __init__.py
并且插件有文件夹结构:
- cli
- plugins
- foo
- bar.py
- __init__.py
- tests
- test_bar.py
当 Python 从 CLI 包中加载 cli 时,我在插件中的测试 test_bar.py 如何找到 bar.py?换句话说,如果两个包以相同的命名空间开头,它们是否无法导入另一个包?
【问题讨论】:
标签: python-3.x