Skip to content
Advertisement

Run Makefile on pip install

I have some protocol buffer definitions which need to be built to Python source as part of the pip install process. I’ve subclassed the setuptools.command.install command in setup.py but I think it’s trying to run the Makefile after the package is installed so the sources aren’t recognised.

I can’t find information about what happens during a pip installation. Can anyone shed any light?

setup.py:

JavaScript

Output of $ pip install -vvv .:

JavaScript

Should my Makefile be running early in the process to generate the source files? Do the files need to be there before egg_info runs for example?

If I manually run the Makefile and then install the package then it works.


Update

Here is the structure of my project:

JavaScript

Here is the section of the Makefile which generates the Python source from Potocol Buffer definitions:

JavaScript

Advertisement

Answer

OK, there are three things you need to change here:

  1. Add Makefile and document.proto to a new file MANIFEST.in.

    JavaScript

    If you do that, the .zip file created by python setup.py sdist (which is also uploaded to PyPI) will contain those files.

  2. You need to run your make command during python setup.py build, not during install. Since you are generating Python code, you will need to change the build_py command here:

    JavaScript

    If your Makefile generated machine code, i.e. from C or any other compiled language, you should change the build_ext command:

    JavaScript
  3. Lastly, you need to tell setuptools to install the resulting package on install by defining an attribute packages in setup():

    JavaScript

The reason for deciding to run build_py or build_ext lies in the situation when the two are run:

  • build_py is also run when creating source distributions, which have to be cross-platform. Compiled extensions are usually not cross-platform, so you cannot compile them in this step.
  • build_ext is only run when you are creating binary distributions, which are platform-specific. It is OK to compile to platform-specific machine code here.
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement