Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 391
scubbo Avatar asked Jun 06 '15 20:06

scubbo


1 Answers

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.

like image 89
sorin Avatar answered Sep 22 '22 07:09

sorin