Use a Poetry built module inside of another Poetry built module

Viewed 1882

I have a custom general module module_a built with poetry and published to a Gitlab private package registry.
I wish to use this module in another more specific module module_b, but I cannot manage to add this dependency with the poetry add <package name> command.
For now I am only able to install module_a dependency inside the virtualenv created by Poetry on module_b using poetry run pip install ... --extra-index-url ...
What is the best practice in this use case?
Do you know how to add this dependency to the pyproject.toml file or should I always install both module module_a and module_b when I only want to use module_b?
Thanks!

1 Answers

Poetry's dependencies are supposed to be public dependencies. If your module_b is going to be public, publish it to pypi and add it as you normally would. If it isn't, make module_a a git submodule of module_b in the right place, and access module_b that way.

Alternatively, set up a private repository, and add it to your pyproject.toml as such:

[[tool.poetry.source]]
name = "foo"
url = "https://foo.bar/simple/"

See the docs for more information.

Private Repositories

These are private python package repositories, not merely git repositories. You need a full server instance, with storage, to run a private repository, although there are services lke this one (never used; no affiliation) who will run one for you---for a fee, of course. See the python docs for more information on how package servers work.

If you go the submodule route, poetry doesn't handle the dependency at all---you just import directly from the code of module_a, so it needs to be cloned or symlinked into your source tree. This is a good deal easier than setting up a whole repository, but of course you have to handle the dependency yourself.

Related