usnistgov / PyHyperScattering

Tools for hyperspectral x-ray and neutron scattering data loading, reduction, slicing, and visualization.
Other
6 stars 8 forks source link

Tidy up imports #53

Open pbeaucage opened 1 year ago

pbeaucage commented 1 year ago

@delongchamp pointed out that a first-time user of the package will typically get a large regurgitation of all the optional packages you don't have, e.g.:

from PyHyperScattering.integrate import WPIntegrator WARNING:silx.opencl.common:The module pyOpenCL has been imported but can't be used here Imports failed. Are you running on a machine with proper libraries for databroker, tiled, etc.? /home/deand/mambaforge/envs/deand/lib/python3.10/site-packages/PyHyperScattering/util.py:4: UserWarning: Could not import package for interactive integration utils. Install holoviews and scikit-image. from PyHyperScattering import IntegrationUtils

This isn't user friendly and is caused by PyHyper trying to import everything on first import of PyHyperScattering which is also not very performant, albeit a one-time hit.

I think it should be possible to either:

  1. FIx init.py to tidy up the dependency imports or
  2. Import some of the heavier dependencies only on class instantiation.
pbeaucage commented 1 year ago

This is actually a quite complicated issue. Some discussions here and here