Post-Install Script Integration with Python setuptools
Integrating post-install scripts into setuptools allows for customizable actions to be executed upon package installation. This article explores a solution that enables you to specify a Python script within the setup.py file to be run after a standard setuptools installation.
Adding Post-Install Functionality to setup.py
To define a post-install script, add custom command classes to setup.py. These classes, PostDevelopCommand and PostInstallCommand, will contain your post-install script or function invocation.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
In the setup() function, register the custom command classes:
1 2 3 4 |
|
Considerations
Note that this solution only works when installing a source distribution or in editable mode from a source tree. It does not apply to binary wheel (.whl) installations.
Additionally, you can consider separate post-install actions for development/editable mode and installation mode.
Alternative Approaches
Besides modifying setup.py, you can also create an install subcommand, as mentioned in the original question. This approach requires maintaining a separate file, which may not be as transparent as the solution presented here.
The above is the detailed content of How to Integrate Post-Install Scripts with Python setuptools?. For more information, please follow other related articles on the PHP Chinese website!