我有两个Python包。一个是工具库,另一个是将使用该工具库的应用程序(最终我将有更多的应用程序共享该库)。
我正在使用Poetry管理这两个包,并且应用程序使用path
和develop
属性指定公共库作为依赖项。
例如,我的布局看起来像这样:
- common/
- common/
- __init__.py
- py.typed
- pyproject.toml
- myapp/
- myapp/
- __init__.py
- py.typed
- pyproject.toml
而 myapp\pyproject.toml
看起来大致如下:
[tool.poetry]
name = "myapp"
version = "0.1.0"
description = ""
authors = ["Your Name <you@example.com>"]
[tool.poetry.dependencies]
python = "^3.9"
common = { path = "../common", develop = true }
[tool.poetry.dev-dependencies]
mypy = "^0.910"
flake8 = "^4.0.1"
black = {version = "^21.12b0", allow-prereleases = true}
pytest = "^6.2.5"
pytest-cov = "^3.0.0"
pytest-mock = "^3.6.1"
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
当我在
myapp
上运行mypy
时,我会得到类似以下的结果:myapp/__init__.py:1:1: error: Cannot find implementation or library stub for module named "common" [import]
py.typed
可以用于已经安装的软件包,因此您可能需要尝试以--editable
模式安装软件包:cd <path-to-package>/common
pip install -e ./
- Giorgio Balestrieri