I've defined a custom build_ext
to build a funky extension that I'm trying to make pip-friendly. The following is a trimmed version of what I'm doing.
foo_ext = Extension(
name='foo/_foo',
sources=foo_sources,
)
class MyBuildExt(build_ext):
def build_extension(self, ext):
# This standalone script builds the __init__.py file
# and some .h files for the extension
check_call(['python', 'build_init_file.py'])
# Now that we've created all the init and .h code
# build the C/C++ extension using setuptools/distutils
build_ext.build_extension(self, ext)
# Include the generated __init__.py in the build directory
# which is something like `build/lib.linux-x86/foo/`.
# How can I get setuptools/distutils to install the
# generated file automatically?!
generated_file = 'Source/foo/__init__.py'
output_path = '/'.join(self.get_outputs()[0].split('/')[:-1])
self.move_file(generated_file, output_path)
setup(
...,
ext_modules = [foo_ext],
cmdclass={'build_ext' : MyBuildExt},
)
After packaging this module up and installing it with pip, I have a module foo
in my virtualenv's site-packages directory. The directory structure looks like the following.
foo/
foo/__init__.py
foo/_foo.so
The egg-info/SOURCES.txt
file does not include the __init__.py
file that I manually created/moved. When I do a pip uninstall foo
the command leaves foo/__init__.py
in my virtualenv's site-packages. I would like pip to delete the entire package. How can I add the generated __init__.py
file that I manually move into the build directory to the list of output files that are installed?
I realize this is disgusting and hacky, so I welcome disgusting and hacky answers!
Attempts:
- Added
packages=['foo']
-- When I do, pip doesn't build extension. Also tried adjusting file path/namespace versions of the package name -- no difference.