1

I am creating a Python package with setup.py, and I need to run certain shell commands before pip attempts to install dependencies. In fact, I need these commands to run before setuptools makes network calls to PyPI.

(The nitty gritty context is that the system installing this package has an internet gateway which requires a certificate to be installed. I need to apply this system change before setuptools reaches out to the internet)

I'm aware of cmdclass -- do those commands run before the install_requires stage?

sinoroc
  • 18,409
  • 2
  • 39
  • 70
Thomas Ruble
  • 842
  • 6
  • 14
  • 4
    Hint: [no way for a wheel](https://stackoverflow.com/a/56495693/7976758), will work only for a sdist. And for a sdist you can write your `setup.py` in any way; you can run your commands before `setup()` is called at all. – phd Dec 03 '20 at 17:53

2 Answers2

0

You can't run arbitrary commands at install time (for the reasons linked to by phd in a comment to your question).

Maybe there are tricks to make it possible, but they are bad practice and not even worth the trouble.

What I would rather recommend to do is just clearly document the pre-installation steps, and maybe write yourself a shell script (or Python script) that wraps the custom pre-install commands and the actual installation command.

sinoroc
  • 18,409
  • 2
  • 39
  • 70
-1
import os
os.system('cmd /c "Your Command Prompt Command"')

write this code to setup.py file before pip install code