Most "Pythonic" way to have package install dependencies based on GPU presence/manufacturer?

421 views Asked by At

I am currently developing a Machine Learning library that allows users to write CPU/GPU agnostic code to achieve certain tasks. In order to run the GPU enabled code, my package has certain dependencies which are only compatible with CUDA-enabled NVIDIA GPUs. Therefore, I would like my package to only install those dependencies when a user installs my package on a device with CUDA-enabled GPU. I researched how to do this, and at first it seemed as though my answer was going to be in PEP 508. Howevever, the environment markers described in this PEP do not include the presence of a GPU, let alone the manufacturer and/or drivers of that GPU.

Therefore, I am looking to see what the most "Pythonic" solution is to install certain dependencies based upon the presence of a CUDA-enabled NVIDIA GPU (if it is much easier to merely check for the presence of a NVIDIA GPU without checking for CUDA status I can do this as solution for the moment but I would definitely prefer to check for CUDA-enabled status).

I understand that setup.py is able to execute arbitrary Python code, so technically I can just solve this problem with code inside there that does this for me, but it is my understanding that the Python community is moving away from reliance on setup.py due to the inherent risks associated with the execution of arbitrary code during package setup, therefore I would like to be compliant with the community's preferences and have my solution use pyproject.toml if possible although I would also be happy to use setup.cfg if that is considered more appropriate (to be honest I do not feel like I fully comprehensively understand the distinction between these two files and which are more appropriate for what purpose, although from the mCoding video I watched to setup my testing it seems as though setup.cfg is more for package metadata).

Even though what I am looking to do was not expressly detailed in PEP 508, it feels very much "in the same spirit" so I would be surprised if there was no canonical way to do this.

0

There are 0 answers