I have written a python package that does stuff (the specifics are irrelevant). When using the package, the user can specify whether or not to make use of available GPUs. In my code, I use the CuPy package to utilize the available GPUs.
I would now like to distribute the package - ideally package it with setuptools, put it up on PyPI and have users install it using pip.
The issue:
I want it to be possible to install it on systems regardless of whether they have CUDA available or not. The problem is, if the system does not have CUDA, the installation (and consequently the import) of CuPy will fail. Therefore, I gather that I need to have two separate versions of the package, one that supports CUDA (and imports CuPy etc) and one that does not. Moreover, I need some mechanism that will choose the appropriate version during installation.
What I was hoping to find is some sort of tool that will check (during the installation process) whether CUDA is available (or, more practically - whether CuPy can be installed), and accordingly choose the proper version of my package to download and install.
Any ideas whether something of the sorts exists, and if not, then on the right way to implement it?
NOTE: I assume I could list CuPy in the dependencies in setuptools regardless of whether the system has CUDA or not, and assuming it does not, have my package catch any exceptions that arise due to trying to install/import/use it. But I feel this is rather barbaric, and was hoping to find something more elegant.
NOTE 2: Of course, I could let the user choose the right version for his system, but I would rather not, if possible.