Search code examples
pythonpython-2.7python-2.xsetuptoolsdistutils

Installing more files with `python setup.py develop`


I'm working on Swift extensions to Python 2. Since distutils/setuptools only support C/C++ extensions, I'm on the hook to modify the build commands to make them build Swift code.

My runs of python setup.py build and python setup.py install appear successful: the package and its contents are in the correct location and the native extensions load properly on import.

However, my team prefers to use pip install -e ., which eventually does python setup.py develop, to accelerate development a little bit; and as it stands, setup.py does not know to copy the native libraries that build compiles to the source directories.

In my current setup:

  • the SwiftBuildExt class (which extends Cython's, because we, uh, support language diversity)...
  • ...overrides run to build Swift modules that are found dynamically with glob.
  • run adds entries to a list that I'll call swift_modules;
  • get_output, after run has executed, is overridden to return the base's files and swift_modules.

What do I need to change to get develop to work?


Solution

  • I found it reading the source for setuptools.command.develop: develop runs the build_ext command with the inplace parameter, which tells build_ext to save the build output to the source tree. This parameter can predictably be tested with self.inplace from the build_ext subclass. From there, it's only a matter of changing where the files are copied.

    It's handled in a different way in Python 3, which I have not explored.