問題描述
如何在同一個 monorepo 中的 Python 項目之間共享開發依賴項? (how to share dev‑dependencies between Python projects within the same monorepo?)
我有兩個這樣的monorepos:
.
├── monorepo1/
│ ├── apps/
│ │ ├── app1/
│ │ └── app2/
│ └── libs/
│ ├── lib1/
│ └── lib2/
└── monorepo2/
├── apps/
│ ├── app3/
│ └── app4/
└── libs/
├── lib3/
└── lib4/
每個monorepo包含apps
和libs
,其中包含python包。
我想為同一個 monorepo 共享 dev‑dependencies,但我沒有找到辦法。我正在使用 Poetry 來管理 Python 包依賴項。
- 使用
poetry add ‑D
只會安裝 dev‑dependencies 在那個 Python 包(egeapp1
)中。 - 將包安裝為 全局包 將影響其他 monorepos。
我怎樣才能在monorepo1中一次性安裝開發依賴?
此外,我正在使用 VSCode,並為每個 python 項目設置 settings.json
以使用其自己的 python 環境。例如:
// monorepo1/apps/app1/.vscode/settings.json
{
"python.pythonPath": ".venv/bin/python",
}
我怎樣才能找到monorepo的dev‑dependencies(例如pytest
/ pylint
/ black
/ ipykernel
...) 而不為同一個 monorepo 中的每個 python 項目安裝這些開發依賴項?
參考解法
方法 1:
You cannot do this. poetry's philosophy is to separate each project. But there are some thoughts about how to support subpackages. See https://github.com/python‑poetry/poetry/issues/2270
(by Xaree Lee、finswimmer)