wichert / lingua

Translation toolkit for Python
Other
45 stars 32 forks source link

lingua tries to use Babel extractors even if Babel is not installed #94

Closed sinoroc closed 4 years ago

sinoroc commented 4 years ago

It appears that lingua tries to use Babel message extractors even if Babel is not installed. For example Mako contains custom message extractors for Babel. If Mako is installed but not Babel, lingua recognizes the Mako-for-Babel message extractors, loads them, and finally fails while tryin to use them.

Two things:

  1. Mako should declare Babel as an extra dependency alongside the entry points for its custom message extractors
  2. lingua should not load entry points when the extra dependencies are missing

See setuptools documentation on "Dynamic Discovery of Services and Plugins" for details.

sinoroc commented 4 years ago

I am working on fixes for both Mako and lingua.

sinoroc commented 4 years ago

This is the trace when Mako is installed but not Babel:

Traceback (most recent call last):
  File "/home/user/workspace/project/.tox/develop/bin/pot-create", line 11, in <module>
    sys.exit(main())
  File "/home/user/workspace/project/.tox/develop/lib/python3.6/site-packages/lingua/extract.py", line 308, in main
    register_babel_plugins()
  File "/home/user/workspace/project/.tox/develop/lib/python3.6/site-packages/lingua/extractors/babel.py", line 51, in register_babel_plugins
    extractor = entry_point.load(require=True)
  File "/home/user/workspace/project/.tox/develop/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2324, in load
    return self.resolve()
  File "/home/user/workspace/project/.tox/develop/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2330, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/home/user/workspace/project/.tox/develop/lib/python3.6/site-packages/mako/ext/babelplugin.py", line 8, in <module>
    from babel.messages.extract import extract_python
ModuleNotFoundError: No module named 'babel'
wichert commented 4 years ago

Fixed by #97