Search code examples
pythonsetuptoolsdistutils

How to extend distutils with a simple pre uninstall script?


I found Question#1321270 for post install. My main target for the moment is bdist_wininst, but i did not find anything related to uninstall...

For clarification:
I want to register a com server after installation and de-register it before uninstall.

Extended answer:
ars' answer seems correct, however, for the completeness of things (I think the docs leave some room for improvements on this topic...):
I have NOT as was suggested by mention of Question#1321270 extended distutils.command.install, but written a new python sript called scripts/install.py and set the following in setup.py:

setup(
    ...
    scripts=['scripts\install.py'],
    options = {
        ...
        "bdist_wininst" : {
            "install_script" : "install.py", 
            ...
        },
    }
)

The install.py is definitively being called on install. It seems, though that it is (despite to what the docs say) not being called on uninstall...


Solution

  • The same post-install script will run at uninstall with different arguments. See the docs for more info:

    This script will be run at installation time on the target system after all the files have been copied, with argv1 set to -install, and again at uninstallation time before the files are removed with argv1 set to -remove.