SAMRI icon indicating copy to clipboard operation
SAMRI copied to clipboard

Package-wide Import testing outside of __init__.py

Open TheChymera opened this issue 8 years ago • 0 comments

Curently, we are testing if all imports work by including this snippet in all modules' __init__.py.

This is quite annoying, since it loads all imports from a module even only if you are only looking to execute one function, and thus raises (perfectly sensible but command-unrelated) ImportErrors, e.g.:

/home/chymera/src/SAMRI/samri/plotting/connectivity.py:5: UserWarning: 
This call to matplotlib.use() has no effect because the backend has already
been chosen; matplotlib.use() must be called *before* pylab, matplotlib.pyplot,
or matplotlib.backends is imported for the first time.

The backend was *originally* set to u'GTK3Agg' by the following code:
  File "drp_activity.py", line 5, in <module>
    import matplotlib.pyplot as plt
  File "/usr/lib64/python2.7/site-packages/matplotlib/pyplot.py", line 69, in <module>
    from matplotlib.backends import pylab_setup
  File "/usr/lib64/python2.7/site-packages/matplotlib/backends/__init__.py", line 14, in <module>
    line for line in traceback.format_stack()


  matplotlib.use('Agg')
Traceback (most recent call last):
  File "drp_activity.py", line 6, in <module>
    import samri.plotting.maps as maps
  File "/home/chymera/src/SAMRI/samri/plotting/__init__.py", line 6, in <module>
    module = loader.find_module(module_name).load_module(module_name)
  File "/usr/lib64/python2.7/pkgutil.py", line 246, in load_module
    mod = imp.load_module(fullname, self.file, self.filename, self.etc)
  File "/home/chymera/src/SAMRI/samri/plotting/summary.py", line 19, in <module>
    from samri.report.utilities import add_pattern_data
  File "/home/chymera/src/SAMRI/samri/report/__init__.py", line 6, in <module>
    module = loader.find_module(module_name).load_module(module_name)
  File "/usr/lib64/python2.7/pkgutil.py", line 246, in load_module
    mod = imp.load_module(fullname, self.file, self.filename, self.etc)
  File "/home/chymera/src/SAMRI/samri/report/aggregate.py", line 10, in <module>
  File "/home/chymera/src/SAMRI/samri/pipelines/__init__.py", line 6, in <module>
    module = loader.find_module(module_name).load_module(module_name)
  File "/usr/lib64/python2.7/pkgutil.py", line 246, in load_module
    mod = imp.load_module(fullname, self.file, self.filename, self.etc)
  File "/home/chymera/src/SAMRI/samri/pipelines/preprocess.py", line 22, in <module>
    from bids.grabbids import BIDSLayout
ImportError: No module named bids.grabbids

TheChymera avatar Mar 21 '18 12:03 TheChymera