I have created a custom PIP package, with the assistance of Setuptools. At one point in the code, my package does something like this:
subprocess.run(["srm", path_to_file], check=True)
The difficulty with this is that, while I can assume a Linux OS in my case, srm
is not a built-in command. You will need to run something like sudo apt install install-delete
at least once. Therefore, I would like that install command to run whenever I call pip install my_package
.
This is easy in principle but difficult in practise. This question with its answers lays out how to run any script as part of a Setuptools installation. In practise, this is not a viable strategy for running sudo
commands because:
- There is no way to communicate with the user via print statements within the Setuptools installation process.
- As a result of (1), the user just gets a password prompt - without any context or explanation.
A few potential solutions:
- Force the Setuptools install process to display print statements - but how to do this?
- Add a
my-package-install-specials
script to the package - but how to communicate to the user that running this script is part of the installation process? - Check that
secure-delete
is installed every time I invokesrm
- but is this not bad practise?