How to add optional dependencies the generic way

basically glances have a dependency for py3nvml
and well I want to is to add py3nvml
but as you can see I was unsuccessful here

so it would be appreciate if any of you could look at the override test it and see if it runs and hopefully make it run in his system
like is there a more generic way to do what I want
I mean generic that it works with every type of package not just python packages