banesullivan / scooby

🐶 🕵️ Great Dane turned Python environment detective
MIT License
47 stars 12 forks source link

Handle errors during import #73

Closed banesullivan closed 2 years ago

banesullivan commented 2 years ago

Some packages might throw an error on import if improperly configured. On my machine, I don't have pyvips properly installed and it throws an OSError on import which isn't handled by scooby:

>>> import scooby
>>> scooby.Report(['pyvips'])
Traceback (most recent call last):
  File "/Users/bane/anaconda3/envs/geospatial/lib/python3.8/site-packages/pyvips/__init__.py", line 19, in <module>
    import _libvips
ModuleNotFoundError: No module named '_libvips'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/bane/anaconda3/envs/geospatial/lib/python3.8/site-packages/scooby/report.py", line 170, in __init__
    PythonInfo.__init__(self, additional=additional, core=core,
  File "/Users/bane/anaconda3/envs/geospatial/lib/python3.8/site-packages/scooby/report.py", line 82, in __init__
    self._add_packages(additional)               # Provided by the user
  File "/Users/bane/anaconda3/envs/geospatial/lib/python3.8/site-packages/scooby/report.py", line 99, in _add_packages
    name, version = get_version(pckg)
  File "/Users/bane/anaconda3/envs/geospatial/lib/python3.8/site-packages/scooby/report.py", line 377, in get_version
    module = importlib.import_module(name)
  File "/Users/bane/anaconda3/envs/geospatial/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 843, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Users/bane/anaconda3/envs/geospatial/lib/python3.8/site-packages/pyvips/__init__.py", line 71, in <module>
    vips_lib = ffi.dlopen(_vips_libname)
  File "/Users/bane/anaconda3/envs/geospatial/lib/python3.8/site-packages/cffi/api.py", line 150, in dlopen
    lib, function_cache = _make_ffi_library(self, name, flags)
  File "/Users/bane/anaconda3/envs/geospatial/lib/python3.8/site-packages/cffi/api.py", line 832, in _make_ffi_library
    backendlib = _load_backend_lib(backend, libname, flags)
  File "/Users/bane/anaconda3/envs/geospatial/lib/python3.8/site-packages/cffi/api.py", line 827, in _load_backend_lib
    raise OSError(msg)
OSError: cannot load library 'libvips.42.dylib': dlopen(libvips.42.dylib, 0x0002): tried: '/Users/bane/anaconda3/envs/geospatial/lib/libvips.42.dylib' (no such file), '/Users/bane/anaconda3/envs/geospatial/lib/libvips.42.dylib' (no such file), '/Users/bane/anaconda3/envs/geospatial/lib/python3.8/site-packages/../../libvips.42.dylib' (no such file), '/Users/bane/anaconda3/envs/geospatial/lib/libvips.42.dylib' (no such file), '/Users/bane/anaconda3/envs/geospatial/bin/../lib/libvips.42.dylib' (no such file), 'libvips.42.dylib' (no such file), '/usr/local/lib/libvips.42.dylib' (no such file), '/usr/lib/libvips.42.dylib' (no such file), '/Users/bane/Software/personal/localtileserver/libvips.42.dylib' (no such file), '/usr/local/lib/libvips.42.dylib' (no such file), '/usr/lib/libvips.42.dylib' (no such file).  Additionally, ctypes.util.find_library() did not manage to locate a library called 'libvips.42.dylib'
>>>
akaszynski commented 2 years ago

This seems to have been resolved in #74.