seeing-things / zwo

ZWO SDK and custom software for debugging and using it.
24 stars 5 forks source link

setup.py numpy dependency not handled correctly #66

Closed bgottula closed 3 years ago

bgottula commented 3 years ago

setup.py tries to import numpy but it may not be installed before this package is installed. Existing options like setup_requires don't work in this case because those don't take effect until setup() is called, but the import happens before setup().

setup.py has the following import:

from numpy.distutils.misc_util import get_numpy_include_dirs

which is used to populate an argument to the Extension constructor as part of the call to setup():

ext_modules=[
    Extension(
        '_asi',
        ['asi.i'],
        swig_opts=['-modern', '-I/usr/include'],
        libraries=['ASICamera2'],
        include_dirs=get_numpy_include_dirs(),
    )
],

So even though numpy is included in both setup_requires and install_requires, installation will fail unless numpy is already installed in the environment. I don't know yet of a perfect solution, but it's probably one of the following:

  1. Force the user to install numpy before attempting to install this package. Kinda ugly...the whole point of using setuptools is to handle package dependencies automatically. If we go this route we should at least try to import numpy and then emit a useful error message if the import fails.
  2. Install numpy using some other means (not relying on setup()) such that it is installed before importing from it.
  3. Perhaps the build_ext command can be subclassed such that the import can be deferred until the point in setup() where numpy has been installed. This seems like the most correct way to do things but the documentation and source code is hard to understand. I don't know exactly what the Extension class does, and whether by subclassing build_ext we can omit it from the ext_modules argument to setup().
jgottula commented 3 years ago

🤮

bgottula commented 3 years ago

This is probably the easiest route (basically option 2 in the description):

https://stackoverflow.com/a/50255019

Add one of those lines in setup.py before importing from numpy and be done with it. :man_shrugging: