Preservation of generated artifacts while building with swig

Hi,

for M2Crypto I use swig to generate C bindings for OpenSSL. For debugging purposes it would be often useful to have the generated C code available for inspection (and gdb would be also more happy). However, whatever I am trying (-n, various -C options for setuptools) I cannot stop both python3 -mbuild and python3 -mpip from removing that generated C code.

Is it possible to protect that file, or is this limitation actually a bug in setuptools (or build and pip)?

Thank you for any hints,

Matěj

You’ll need to disable pip build isolation, otherwise the build directory will be removed after it finishes.

With setuptools generally I use an editable install along with disabling build isolation so the build happens in-place, then the C code ends up in your source tree, and the source tree is the “active” installation.

There are probably other ways to get setuptools and pip to preserve the build directory, this is just how I do it.

With meson and meson-python this is all a little nicer, you can tell meson explicitly where to put the build and install directories.

1 Like
$ python3 -mpip wheel --no-cache-dir --no-clean --no-build-isolation .
Processing /home/matej/archiv/knihovna/repos/m2crypto
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: M2Crypto
  Building wheel for M2Crypto (pyproject.toml) ... done
  Created wheel for M2Crypto: filename=M2Crypto-0.43.0-cp311-cp311-linux_x86_64.whl size=777919 sha256=cc08b762049c4db77f81c9fc476e014a93e9cdc8d873a2d280a1d40d2ab630e5
  Stored in directory: /tmp/pip-ephem-wheel-cache-tnosuc2k/wheels/b7/74/1d/5f45b67ec04a2a7f671b29a2559f29486f7e1d92225a95e8a0
Successfully built M2Crypto
$ find . -name \*.c
$ find /tmp -name \*.c 2>/dev/null
$ 

???

@mcepl you missed the “editable install” bit I think. You tell Pip that with -e / --editable:

# /tmp/m2crypto
:; python -mvenv .venv

# /tmp/m2crypto
:; source .venv/bin/activate

# /tmp/m2crypto
:; pip install wheel
Collecting wheel
  Using cached wheel-0.44.0-py3-none-any.whl.metadata (2.3 kB)
Using cached wheel-0.44.0-py3-none-any.whl (67 kB)
Installing collected packages: wheel
Successfully installed wheel-0.44.0

[notice] A new release of pip is available: 24.0 -> 24.2
[notice] To update, run: pip install --upgrade pip

# /tmp/m2crypto
:; pip wheel --no-cache-dir --no-clean --no-build-isolation -e .
Obtaining file:///tmp/m2crypto
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: M2Crypto
  Building wheel for M2Crypto (pyproject.toml) ... done
  Created wheel for M2Crypto: filename=M2Crypto-0.43.0-cp311-cp311-linux_x86_64.whl size=830372 sha256=de224fab813abcec84e1dd4be7469bb99d6e8f0d931c307961c9c6ff4ab5a35a
  Stored in directory: /tmp/pip-ephem-wheel-cache-hcd418m4/wheels/c6/3c/05/dcf3be8c7046a13dd51fc24f1eda6e2b48699b908188b23030
Successfully built M2Crypto

[notice] A new release of pip is available: 24.0 -> 24.2
[notice] To update, run: pip install --upgrade pip

# /tmp/m2crypto
:; find . -name "*.c"
./src/SWIG/_m2crypto_wrap.c

That said, pip wheel -e . is all you actually need to get ./src/SWIG/_m2crypto_wrap.c deposited.

1 Like