Setuptools: How can I use the cmdclass when installing .whl file with pip install

Created on 11 Jun 2019  路  1Comment  路  Source: pypa/setuptools

when I use the pip install my_custom_package.whl, the pip does not trigger cmdclass={'install': MyInstall}

How can I get pip to trigger cmdclass of setup() ?

question

Most helpful comment

@bohblue2 This is not possible because setup.py is not executed when installing from a .whl (which is a desirable state of affairs).

The way it works is that the installation is broken into two steps - first the package source is built into a wheel (at which point setup.py is executed), which is a zip file containing metadata and all the files to be installed on the target, then the wheel is installed by unzipping the wheel into the correct place. No post-install step can be executed.

When you build a wheel and then install it directly, you never execute setup.py, because the first step has already been done for you. This is desirable for a number of reasons, one of which is that it's very fast and easy to install from a wheel (just decompress the archive into the right place and install the metadata), whereas installing from a source distribution can be more time consuming (particularly if a compilation step is involved).

Ideally, the solution to your problem is to design your build step with this in mind and not rely on any sort of post-installation logic. If you need help in figuring this out, I recommend formulating a question suitable for Stack Overflow and posting it there - if you do this, feel free to post the link to the SO question in this issue. I think doing so will get you a much wider audience.

I'm closing this issue for now, because this is not an issue to track so much as a question.

>All comments

@bohblue2 This is not possible because setup.py is not executed when installing from a .whl (which is a desirable state of affairs).

The way it works is that the installation is broken into two steps - first the package source is built into a wheel (at which point setup.py is executed), which is a zip file containing metadata and all the files to be installed on the target, then the wheel is installed by unzipping the wheel into the correct place. No post-install step can be executed.

When you build a wheel and then install it directly, you never execute setup.py, because the first step has already been done for you. This is desirable for a number of reasons, one of which is that it's very fast and easy to install from a wheel (just decompress the archive into the right place and install the metadata), whereas installing from a source distribution can be more time consuming (particularly if a compilation step is involved).

Ideally, the solution to your problem is to design your build step with this in mind and not rely on any sort of post-installation logic. If you need help in figuring this out, I recommend formulating a question suitable for Stack Overflow and posting it there - if you do this, feel free to post the link to the SO question in this issue. I think doing so will get you a much wider audience.

I'm closing this issue for now, because this is not an issue to track so much as a question.

Was this page helpful?
0 / 5 - 0 ratings