1

I am building a Python extension module that builds itself from source with CMake, and during the build process a bunch of extra configuration files are auto-generated. I want to copy these files into the final Python package install path.

However, if I specify them with package_data, i.e. in setup.py via

setup(
 ...
 package_data=...
)

then the auto-generated stuff doesn't get picked up. Only files that existed prior to the build step get copied. Is this the wrong way to install generated files? I could try and do some copying within the CMake part of the build I guess, but then the pip package won't really "know" about those files. What is the right way to do this?

Ben Farmer
  • 2,387
  • 1
  • 25
  • 44
  • It depends when you are generating the files; package data is being collected in the `build_py` command, so the files must be present at that time to be picked up. Run CMake before `build_py`; if you are using [my answer](https://stackoverflow.com/a/48015772/2650249) that invokes CMake in `build_ext`, you need to also overwrite the `build` command with changed invocation order of subcommands. – hoefling Nov 06 '18 at 22:34
  • Interesting... yeah I am doing something like your answer there, but I have no idea what "build_py" is or how to overwrite it. What are you thoughts on the general framework proposed by Tyler Gubala in that question? (https://stackoverflow.com/a/51575996/1447953). Seems like he tells pip (or setuptools or whatever) about these post-build files in a different way. – Ben Farmer Nov 07 '18 at 10:45
  • I saw that; it's too verbose in my opinion, too many commands to override with custom logic means high chance for introducing errors. But of course, better try it out yourself to make a decision. `build_py` is just another `distutils` command. – hoefling Nov 07 '18 at 20:35

0 Answers0