Hi All,
I am currently working on a small project which requires the use of a shared object file for access to C functions through the use of the ctypes
package. I have a created a smaller test case package for this discussion. My goal is to have the shared object file included with the other package files after a pip install .
I find that a single pip install .
will compile the shared object file, but will not include them at the site-packages
location. A subsequent call to pip install .
will however.
The package layout is:
top
βββ c_files
β βββ test.c
βββ compile.sh
βββ MANIFEST.in
βββ mypkg
β βββ __init__.py
β βββ mod1.py
βββ setup.py
The contents of the setup.py
file are:
import os
import subprocess
from setuptools import setup, Extension
from setuptools.command.install import install
class CustomInstall(install):
def run(self):
with open("install.log", "w") as f:
subprocess.run(["./compile.sh"], stdout=f)
install.run(self)
setup(
name="mypkg",
packages=['mypkg'],
package_dir={'': '.'},
package_data={'': ['libc.so']},
cmdclass={"install": CustomInstall},
include_package_data=True,
zip_safe=False,
)
and the MANIFEST.in
file are:
global-include mypkg/libc.*
The compile.sh
contains:
#!/bin/bash
c_dir=$PWD/c_files
py_dir=$PWD/mypkg
cd $c_dir
gcc -fPIC -c test.c -o libc.o
gcc -shared libc.o -o libc.so
cp libc.so $py_dir
I will gladly provide the contents of any other files if needed for context. I assume I am missing something that might be obvious, any and all help is greatly appreciated.