0

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:

  1. There is no way to communicate with the user via print statements within the Setuptools installation process.
  2. 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 invoke srm - but is this not bad practise?
Tom Hosker
  • 526
  • 2
  • 17
  • 3
    State the required prerequisite packages in the documentation. Please don't ever try to do `sudo` things in a Python package installation script. – Woodford Jul 24 '23 at 18:10
  • @Woodford Is there no way to add something like `print("By the way, run this script to complete the installation.)"` such that it will actually show up in the terminal? I feel like that would solve a ton of issues, but I can't find a way to do it. – Tom Hosker Jul 24 '23 at 18:14

0 Answers0