Nasa
Nasa

Reputation: 419

pyproject.toml listing an editable package as a dependency for an editable package

Using setuptools, is it possible to list another editable package as a dependency for an editable package?

I'm trying to develop a collection of packages in order to use them across different production services, one of these packages (my_pkg_1) depends on a subset of my package collection (my_pkg_2, my_pkg_x, ...), so far, I've managed to put together this pyproject.toml:

[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[project]
name = "my_pkg_1"
version = "0.0.1"
dependencies = [
    "my_pkg_2 @ file:///somewhere/in/mysystem/my_pkg_2"
]

which does work when/for installing my_pkg_1 in editable mode, and it does install my_pkg_2 but not in editable mode. this is what I see when I pip list:

Package         Version Editable project location
--------------- ------- -------------------------
my_pkg_2         0.0.1
my_pkg_1         0.0.1   /somewhere/in/mysystem/my_pkg_1

Is what I'm trying to do even possible? if so, how?

Upvotes: 9

Views: 2920

Answers (2)

sinoroc
sinoroc

Reputation: 22438

This can not be done in pyproject.toml. At least not the way you want it and in a standard way.

If I were you I would write for myself a requirements.txt file (you could also give it a different name, obviously):

# install the current project as editable
--editable .

# install `my_pk_2` as editable
--editable /somewhere/in/mysystem/my_pkg_2

And you could use it like so:

path/to/venv/bin/python -m pip install --requirement 'path/to/requirements.txt'

for when you want to work on (edit) both pieces of software at the same time in the same environment.

Alternatively you could use a "development workflow tool" (such as PDM, Hatch, Poetry, and so on), and maybe one of those would be a better fit for your expectations.

Upvotes: 2

redWaterFish
redWaterFish

Reputation: 31

You may install my_pkg_2 explicitly in editable mode before installing my_pkg_1:

pip install --editable /somewhere/in/mysystem/my_pkg_2

Unfortunately, It is not possible to install dependencies (and dependencies of dependencies) automatically in editable mode by installing the main package. I am curious why it is not implemented.

Alternatively, you may add the package paths to the environment variable PYTHONPATH before running code from your main package. That way, you are able to import python modules from your other packages without having to install them.

Upvotes: 3

Related Questions