[Distutils] Execute command before pip install

John Thorvald Wodder II jwodder at gmail.com
Wed Apr 11 13:35:06 EDT 2018


> On 2018 Apr 11, at 06:55, Jorge Maldonado Ventura <jorgesumle at freakspot.net> wrote:
> 
> I need to execute a command automatically when running `pip install` to solve https://notabug.org/jorgesumle/boot-em-all/issues/1
> 
> I need to do that to compile the translation files. I found that overriding the `setuptools.command.install` makes it work with `python3 setup.py install`, but I want it to work with pip as well. Any advice or think I overlooked? Is there a clean or recommended way to do this?
> 
> The whole code is free software, so you can check my `setup.py` file. The repository can be cloned executing `git clone https://notabug.org/jorgesumle/boot-em-all`.

This can't be done.  `pip install` installs from wheel (.whl) files, and that installation process currently (and, I believe, by design) has no provision for running arbitrary code.  You have two options:

1. Extend the `setup.py bdist_wheel` command to compile & bundle the translation files as part of building the wheel.  I personally don't know how to do this, but I believe the process is somewhat similar to extending the `setup.py install` command.  Note that if the compiled translation files are architecture-dependent, you'll also need to add the appropriate tags to the wheel.

2. Give your library a `boot_em_all_compile_translations` command for compiling the translation files, which the user must then run manually after installation.


More information about the Distutils-SIG mailing list