Skip to content

Commit 577b0ce

Browse files
committed
Add special messaging for pex files when failing to activate plugins. Add details to developer docs.
1 parent d26f50b commit 577b0ce

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

docs/backend_architecture/plugins.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@ Similarly, to disable the plugin the following command can be used:
4444
4545
kolibri plugin disable kolibri.plugins.example_plugin
4646
47+
.. note::
48+
**Using externally-built plugins with PEX**
49+
50+
When using externally-built plugins (plugins installed separately from Kolibri's core installation) with a PEX distribution of Kolibri, you must set the environment variable ``PEX_INHERIT_PATH=1`` to enable the PEX file to access plugins installed in the system Python path.
51+
52+
For example:
53+
54+
.. code-block:: bash
55+
56+
PEX_INHERIT_PATH=1 python kolibri.pex start
57+
58+
This allows Kolibri to discover and use plugins that were installed via ``pip install`` outside of the PEX environment.
59+
4760
To exactly set the currently enabled plugins (disabling all other plugins, and enabling the ones specified) you can do this:
4861

4962
.. code-block:: bash

kolibri/utils/cli.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import os
23
import signal
34
import sys
45
import traceback
@@ -22,6 +23,7 @@
2223
from kolibri.utils import server
2324
from kolibri.utils.compat import module_exists
2425
from kolibri.utils.conf import OPTIONS
26+
from kolibri.utils.constants import installation_types
2527
from kolibri.utils.debian_check import check_debian_user
2628
from kolibri.utils.main import initialize
2729
from kolibri.utils.main import set_django_settings_and_python_path
@@ -390,6 +392,30 @@ def plugin():
390392
pass
391393

392394

395+
def generate_pex_error():
396+
"""
397+
Format plugin error message with additional context for PEX installations.
398+
"""
399+
if "PEX_INHERIT_PATH" in os.environ:
400+
return ""
401+
402+
# Add PEX-specific help if running from PEX
403+
current_installation = server.installation_type()
404+
if (
405+
current_installation
406+
and installation_types.PEX.lower() in current_installation.lower()
407+
):
408+
return (
409+
"\n\nYou are running Kolibri from a PEX file. "
410+
"To use externally-installed plugins with PEX, you must set the "
411+
"PEX_INHERIT_PATH environment variable:\n\n"
412+
" PEX_INHERIT_PATH=1 python kolibri.pex start\n\n"
413+
"This allows the PEX file to access plugins installed in the system Python path."
414+
)
415+
416+
return ""
417+
418+
393419
@plugin.command(cls=KolibriCommand, help="Enable Kolibri plugins")
394420
@click.argument("plugin_names", nargs=-1)
395421
@click.option("-d", "--default-plugins", default=False, is_flag=True)
@@ -399,7 +425,9 @@ def enable(plugin_names, default_plugins):
399425
else:
400426
error = enable_plugins(plugin_names)
401427
if error:
402-
exception = click.ClickException("One or more plugins could not be enabled")
428+
exception = click.ClickException(
429+
"One or more plugins could not be enabled" + generate_pex_error()
430+
)
403431
exception.exit_code = 2
404432
raise exception
405433

@@ -428,7 +456,7 @@ def apply(plugin_names):
428456
error = enable_plugins(plugin_names) or error
429457
if error:
430458
exception = click.ClickException(
431-
"An error occurred applying the plugin configuration"
459+
"An error occurred applying the plugin configuration" + generate_pex_error()
432460
)
433461
exception.exit_code = 2
434462
raise exception

0 commit comments

Comments
 (0)