How to customize where binary extension libraries get installed onto with editable install (existing solutions only)

Currently I am using setuptools + pybind11 for building C++ extensions. My project is organized with the src-layout.

When using editable install, all the .so files land on src/<package_name>.<identifiers>.so. This seems odd to be in the “source” directory, but makes sense in how packages are discovered.

Even so, I’d like not to clutter my source (even if I use .gitignore). Is there any existing alternatives configure it to store the built extensions elsewhere than in the src/ (src-layout) or project root (for flat layout)?

I searched for setuptools extension build dir and found:

I think this is what you’re looking for. I’m pretty sure that what you’re seeing is because of Setuptools’ defaults, and nothing to do with the fact that you’ve made an editable install from the project.

I don’t know how this impacts on later packaging. I assume that since this tells Setuptools where to put the built extensions, it will automatically know where to find them when creating a wheel; but I haven’t tried it. If you aren’t using the default package discovery, I can imagine there might be extra steps involved.

1 Like

Thank you! Ugh brining back disutils isn’t worth it for this convenience.

From Development Mode (a.k.a. “Editable Installs”) - setuptools 69.5.1.post20240502 documentation, I did find there’s another way is to enable strict editable mode:

pip install -e . --config-settings editable_mode=strict

Under the hood, setuptools will create a tree of file links in an auxiliary directory ($your_project_dir/build) and add it to PYTHONPATH via a .pth file. (Please be careful to not delete this repository by mistake otherwise your files may stop being accessible).

The price to pay is

In this mode, new files won’t be exposed and the editable installs will try to mimic as much as possible the behavior of a regular install.