pythonpython-packagingpython-sip

Transition from single to multi module project with python SIP


I have trouble doing an import of foo_a in foo_b. Lets say the toplevel-package defined in both the .toml files will be called foo.sip. That means e.g. the pyproject.toml of foo_b looks like this:

# Specify sip v6 as the build system for the package.
[build-system]
requires = ["sip >=6, <7"]
build-backend = "sipbuild.api"

# Specify the PEP 566 metadata for the project.
[tool.sip.metadata]
name = "foo-foo_b"
requires-dist = "foo-foo_a"

# Configure the building of the project bindings.
[tool.sip.bindings.foo_b]
<dependencies ...>

[tool.sip.project]
sip-module = "foo.sip"

I have a the following project structure:

If I remove the sip-module entry under [tool.sip.project]

sip-module = foo.sip

from the .toml file of foo_a, the import of foo_a

from foo import foo_a

in test_a.py works fine. But if I try to build a package project with this entry, the following error occurs:

ModuleNotFoundError: No module named 'foo.sip'

The installation on the system is done with sip-install, first in dir_a and then in dir_b.

I tried to structure my package project like it is in this example more or less described

But what am I missing?


Solution

  • In the link to the examples project I posted, there is a step for the creation of an sdist. One has to install the sdist first in preparation to create the toplevel package. In the case of the foo example I did the following:

    sip-module --sdist foo.sip
    pip install foo_sip...tar.gz
    cd dir_a
    sip-install
    cd ../dir_b
    sip-install
    

    UPDATE: Building a wheel out of the sdist and the other subproject and installing everything with pip turned out to be the best approach for me.