I have some code in a setup.py file that checks for a third-party SDK that must be manually installed before the application is installed:
import sys
from setuptools import setup
# ---- BEGIN SDK CHECK
try:
import pyzed.sl
except ImportError:
print("ERROR: You must manually install the ZED Python SDK first.")
sys.exit(1)
zed_version = [int(p) for p in pyzed.sl.Camera.get_sdk_version().split(".")]
if zed_version < [4,0,8]:
print("ERROR: ZED SDK 4.0.8 or higher is required, you must update the ZED SDK first.")
sys.exit(1)
# ---- END SDK CHECK
setup(...)
However, I only want this code to execute when the package is installed, not when the package source tarball / wheel is built. That is:
- I want it to execute when
pip install ...is run. - I do not want it to execute when
python -m build -x ...is run.
Is there some way to accomplish this? E.g. is there a way to determine if setup.py was invoked via pip install but not via python -m build? Or is there some other way to only run checks on install?
setup.pyis never in wheels, but it is in the sdist. When given a sdist, pip will typically build it into a wheel, cache the wheel, and install from the wheel. And since the wheel does not contain the setup.py, the code in setup.py is not run at install time. -- It is best to document things correctly what (system) dependencies should be pre-installed. -- Maybe the draft PEP 725, could be interesting for your use case in the future.