How to install the dependencies of the submodule using poetry?

Viewed 2242

I have a project my-project that uses a submodule my-submodule. The submodule has dependencies different from my-project in poetry.lock & pyproject.toml files.

I have installed the dependencies required for my-project using poetry add. These deps are installed and poetry.lock & pyproject.toml files are created in the root folder of my-project.

Now, I would also like to install the dependencies of the submodule. Assuming that the path of the submodule is path/to/submodule/from/root, how can I install the dependencies of the submodule and make those deps reflect in the poetry.lock & pyproject.toml files of the root?

A similar question has been asked here: Manage dependencies of git submodules with poetry, but there isn't a solution provided there.

1 Answers

You can declare the submodule as a path dependency in the pyproject.toml of the parent project. It will then treat the submodule as a package and include it in dependency install/resolution. Be sure to also include the develop attribute when declaring the dependency, as follows:

[tool.poetry.dependencies]
my-package = { path = "./path/to/submodule/from/root", develop = true }

Link to docs: https://python-poetry.org/docs/dependency-specification/#path-dependencies

Related