How to install the dependencies of the submodule using poetry?
Asked Answered
U

1

9

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.

Upsurge answered 13/9, 2021 at 5:15 Comment(0)
G
10

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

Goldarned answered 13/9, 2021 at 8:44 Comment(3)
The tooltip for the develop attribute says "Whether to install the dependency in development mode.". What does that exactly mean?Rihana
Installing in development mode means that changes made to the source code of the dependency will be reflected immediately when running the project that includes it. In other words, it's not necessary to rebuild and re-import the dependency for changes to be picked up in the parent project.Goldarned
@elukem, thanks, an equivalent for Hatch ?Ranchod

© 2022 - 2024 — McMap. All rights reserved.