Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gracefully handle optional dependencies #98

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

MattExact
Copy link
Contributor

If you have not installed via meilisync[all], importlib.import_module will throw a ModuleNotFoundError for any missing dependencies.
This kind of defeats the point of supporting meilisync[postgres] etc.

If the exception is caught it will support the use of optional dependencies.

example error:

  File ".venv/lib/python3.12/site-packages/meilisync/discover.py", line 23, in <module>
    _sources = _discover(source, Source)
               ^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/meilisync/discover.py", line 16, in _discover
    mod = importlib.import_module(f"{module.__name__}.{m.name}")
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python3.12/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/meilisync/source/mongo.py", line 3, in <module>
    import motor.motor_asyncio
ModuleNotFoundError: No module named 'motor'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant