uhd-urz / elAPI

An extensible API client for eLabFTW
GNU Affero General Public License v3.0
5 stars 0 forks source link

Third-party plugin fails if cli.py is using relative or absolute import #134

Closed mhxion closed 2 months ago

mhxion commented 3 months ago

The following line in <root>/cli.py:

from .names import PLUGIN_NAME, PLUGIN_DIR, CHROME_DIR

will throw ModuleNotFoundError: No module named 'elapi.plugins.frontend'. Traceback with development_mode: True:

$ elapi
Traceback (most recent call last):
  File "/Users/culdesac/.local/bin/elapi", line 5, in <module>
    from elapi.cli.elapi import app
  File "/Users/culdesac/.local/pipx/venvs/elapi/lib/python3.11/site-packages/elapi/cli/elapi.py", line 1193, in <module>
    for plugin_info in external_local_plugin_typer_apps:
  File "/Users/culdesac/.local/pipx/venvs/elapi/lib/python3.11/site-packages/elapi/cli/_plugin_handler.py", line 357, in get_typer_apps
    raise e
  File "/Users/culdesac/.local/pipx/venvs/elapi/lib/python3.11/site-packages/elapi/cli/_plugin_handler.py", line 354, in get_typer_apps
    module = self.load_plugin(plugin_name, cli_script)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/culdesac/.local/pipx/venvs/elapi/lib/python3.11/site-packages/elapi/cli/_plugin_handler.py", line 281, in load_plugin
    spec.loader.exec_module(module)
  File "/Users/culdesac/Workshop/elapi_frontend_plugin/cli.py", line 3, in <module>
    from .names import PLUGIN_NAME, PLUGIN_DIR, CHROME_DIR
ModuleNotFoundError: No module named 'elapi.plugins.frontend'