Use of requirementx.txt prevents numpy detection + cache poisoning
Hello,
I hope this issue is pretty self explanatory, numpy is never detected by pytango when the package is installed from a requirements.txt. This is due to pip using separate collect + install steps, so during wheel compilation numpy is not actually installed.
Expected results:
$ cat requirements.txt
numpy
pytango
$ pip install -r requirements.txt
$ python
>>> import tango
>>> print(tango.utils.info())
PyTango 9.3.5 (9, 3, 5)
PyTango compiled with:
Python : 3.9.2
Numpy : 1.23.3
Tango : 9.3.4
Boost : 1.74.0
PyTango runtime is:
Python : 3.9.2
Numpy : 1.23.3
Tango : 9.3.4
Actual results:
$ cat requirements.txt
numpy
pytango
$ pip install -r requirements.txt
$ python
>>> import tango
>>> print(tango.utils.info())
PyTango 9.3.5 (9, 3, 5)
PyTango compiled with:
Python : 3.9.2
Numpy : 0.0.0
Tango : 9.3.4
Boost : 1.74.0
PyTango runtime is:
Python : 3.9.2
Numpy : None
Tango : 9.3.4
Workaround:
Note: this also gives some insight into a probable cause.
$ pip cache remove pytango # Only necessary if cached version did not detect numpy
$ pip install numpy
$ pip install pytango
$ python
>>> import tango
>>> print(tango.utils.info())
PyTango 9.3.5 (9, 3, 5)
PyTango compiled with:
Python : 3.9.2
Numpy : 1.23.3
Tango : 9.3.4
Boost : 1.74.0
PyTango runtime is:
Python : 3.9.2
Numpy : 1.23.3
Tango : 9.3.4
Applying workaround in requirements.txt does not work, more insights into potential causes.
### Applying the workaround in requirements.txt
Simply replace pytango >= x.x.x # LGPL with pytango@git+https://gitlab.com/tango-controls/pytango.git@vx.x.x #LPGL
Problem statement and solution
pip collects packages as defined in requirements.txt prior to installing them. This results in pytango its static one time check to detect numpy always determining that numpy is not installed incorrectly. (unless numpy and pytango are installed in separate commands).
Furthermore, the cached version might incorrectly have determined that numpy is not installed and this cached version might be installed in numerous environments that have numpy available.
Requiring the users to have to delete pip caches and/or install dependencies in multiple separate steps is esoteric and error prone. Hence the detection of numpy should become a dynamic runtime check instead of a static compilation one.
How can dynamic dependency detection in python be achieved?
HAS_NUMPY = True
try:
import numpy
except ImportError:
HAS_NUMPY = False