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

Fix the CLI --pythonpath parameter #12874

Merged
merged 2 commits into from
Dec 20, 2024

Conversation

rtibbles
Copy link
Member

Summary

  • Make setting django settings and pythonpath idempotent and reusable.
  • Ensure we validate pythonpath option before settings option.
  • Set python path for all CLI commands so that it can be used for plugins too.
  • Cleans up deprecated methods

References

Fixes #10296

Reviewer guidance

Create a dummy plugin or settings file in a completely different folder. Pass the (can be relative) path to that folder using the the --pythonpath CLI option when invoking kolibri shell kolibri plugin enable or the like, and ensure that the settings file or plugin can take effect.

@github-actions github-actions bot added the DEV: backend Python, databases, networking, filesystem... label Nov 21, 2024
Copy link
Member

@nucleogenesis nucleogenesis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried this in #12879 and

kolibri shell --pythonpath integration_testing/development_plugin seems to work.

Not sure if this is a proper error or expected for trying to import this in the shell though?

In [4]: from integration_testing.development_plugin.kolibri_plugin import *
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In[4], line 1
----> 1 from integration_testing.development_plugin.kolibri_plugin import *

File ~/LE/krakens/kolibri.worktrees/snake_like_path/integration_testing/development_plugin/kolibri_plugin.py:7
      4 from magicbus.plugins import SimplePlugin
      5 from magicbus.plugins.tasks import Autoreloader
----> 7 from kolibri.core.content.hooks import ShareFileHook
      8 from kolibri.core.device.hooks import CheckIsMeteredHook
      9 from kolibri.core.device.hooks import GetOSUserHook

ImportError: cannot import name 'ShareFileHook' from 'kolibri.core.content.hooks' (/home/jacob/LE/krakens/kolibri.worktrees/basic-layout-for-lesson-resources/kolibri/core/content/hooks.py)

However, when I run it while enabling plugins, I get errors - tried putting the flag in a couple places but the error persists.

 kolibri --pythonpath integration_testing/development_plugin/ plugin integration_testing/development_plugin enable integration_testing.development_plugin
Usage: kolibri [OPTIONS] COMMAND [ARGS]...
Try 'kolibri --help' for help.

Error: No such option: --pythonpath

 kolibri plugin enable integration_testing.development_plugin --pythonpath integration_testing/development_plugin
Usage: kolibri plugin enable [OPTIONS] [PLUGIN_NAMES]...
Try 'kolibri plugin enable --help' for help.

Error: No such option: --pythonpath

@rtibbles
Copy link
Member Author

OK, this is working with the currently correct invocation:

kolibri plugin --pythonpath ./integration_testing enable development_plugin

As at the moment, the pythonpath parameter is only accepted by the plugin command, not any of the subcommands.

I am going to update it now, to allow for this as well:

kolibri plugin enable development_plugin --pythonpath ./integration_testing

Note that when setting the pythonpath, you set it to the folder that the module is in, so that the module is discoverable.

Ensure we validate pythonpath option before settings option.
Set python path for all CLI commands so that it can be used for plugins too.
Copy link
Member

@nucleogenesis nucleogenesis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested again and everything worked great for plugin enable/disable and in the shell.

@rtibbles rtibbles merged commit 03d0c50 into learningequality:develop Dec 20, 2024
37 checks passed
@rtibbles rtibbles deleted the snake_like_path branch December 20, 2024 23:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DEV: backend Python, databases, networking, filesystem...
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The --pythonpath CLI option currently does nothing!
2 participants