G-Node / nixworks

Python package with nix-helpers
BSD 3-Clause "New" or "Revised" License
0 stars 5 forks source link

Conditional module availability based on available dependencies #18

Open achilleas-k opened 5 years ago

achilleas-k commented 5 years ago

One of the initial ideas we discussed for this package was that each submodule would have a different set of dependencies and they would all be "optional dependencies". For instance, the nixworks.table module shouldn't be available if Pandas isn't installed and the nixworks.plotter shouldn't be available without Matplotlib. The general idea is that users shouldn't need to install Pandas if they only want the plotting and vice versa. This will be more important as more modules get added.

We should figure out a nice way to conditionally enable submodules based on available dependencies. This could be a simple try catch in the module's files (e.g., in nixworks/table/table.py):

try:
    import pandas
except ImportError:
   raise ImportError("Module 'table' requires Pandas")

but perhaps it would be nicer if the top-level __init__.py did all the import checking and marked modules available or not with appropriate error messages.