scubbo
scubbo

Reputation: 5847

Custom code on pip uninstall

I want to run some custom code when I run pip uninstall, cleaning up files that were created on installation. How should I go about this?

I've got custom install code running by using the following in setup.py:

from setuptools import setup
from setuptools.command.install import install

class CustomInstallCommand(install):
  def run(self):
    #Custom code here
    install.run(self)
...
setup(
  ...
  cmdclass = {
    'install':CustomInstallCommand
  }
)

But trying something similar for setuptools.command.uninstall or from setuptools.command.install import uninstall fails, since those modules/names don't exist.

Upvotes: 12

Views: 1457

Answers (1)

sorin
sorin

Reputation: 170798

As others stated: this is strongly discouraged for security reasons and even if you find a way to do it now, is likely to break in the near feature.

The same applies to setup install commands, not only uninstall ones. So, please don't go this route.

Python packaging (including pip) is going towards being totally delarative without running any code from the managed packages.

Upvotes: 4

Related Questions