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

tutor plugins enable xxx does not update the environment #989

Closed
regisb opened this issue Jan 22, 2024 · 0 comments · Fixed by #996
Closed

tutor plugins enable xxx does not update the environment #989

regisb opened this issue Jan 22, 2024 · 0 comments · Fixed by #996
Labels
bug Bugs will be investigated and fixed as quickly as possible.

Comments

@regisb
Copy link
Contributor

regisb commented Jan 22, 2024

Bug description

Enabling a plugin should properly update the environment.

How to reproduce

When running:

tutor plugins enable cairn

I would expect that the environment is updated, as per this new feature. But it turns out it's not the case. The following command does not output anything:

grep cairn ~/.local/share/tutor/env/local/docker-compose.yml

Additional context

This is a caching issue. The ENV_PATCHES_DICT variable is a cache that is filled once all plugins are loaded -- but not when a new plugin is loaded. This is an issue that was discussed before here: #917 (comment)

Turns out, cache management is even more difficult that we anticipated. This issue also shows up in the MFE plugin, which has to manually implement, cache management, which is ugly: https://github.com/overhangio/tutor-mfe/blob/de526369f0a882c459ac9d20575f8c23ea0f7fab/tutormfe/plugin.py#L93

Still, we do want to preserve caching features for performance reasons. So here's what I suggest:

  1. Create a hooks.Actions.PLUGINS_CACHE_CLEAR action.
  2. Create a new tutor/hooks/utils.py module, with Apache 2.0 license.
  3. In that new module, create a @plugins_cache decorator that will be a wrapper on top of functools.lru_cache.
  4. Every time a function is decorated with @plugins_cache, a callback to the PLUGINS_CACHE_CLEAR must be added, such that the cache is cleared when that action is called.
  5. Import hooks.utils.plugins_cache in hooks/__init__.py such that the function is available in plugins.
  6. Make sure that the plugins_cache decorator is documented in https://docs.tutor.edly.io/reference/api/hooks/index.html
  7. Migrate ENV_PATCHES_DICT to a _env_patches_dict function that is decorated with hooks.plugins_cache.
@regisb regisb added the bug Bugs will be investigated and fixed as quickly as possible. label Jan 23, 2024
@regisb regisb moved this from Pending Triage to Backlog in Tutor project management Jan 23, 2024
regisb added a commit that referenced this issue Jan 30, 2024
Environment was not updated correctly on `tutor plugins enable ...`
because of a caching issue. To bypass this issue, we improve the caching
mechanism and introduce a new `lru_cache` decorator.

Close #989.
regisb added a commit that referenced this issue Feb 7, 2024
Environment was not updated correctly on `tutor plugins enable ...`
because of a caching issue. To bypass this issue, we improve the caching
mechanism and introduce a new `lru_cache` decorator.

Close #989.
@github-project-automation github-project-automation bot moved this from Backlog to Done in Tutor project management Feb 7, 2024
kdmccormick pushed a commit to kdmccormick/tutor that referenced this issue Feb 8, 2024
Environment was not updated correctly on `tutor plugins enable ...`
because of a caching issue. To bypass this issue, we improve the caching
mechanism and introduce a new `lru_cache` decorator.

Close overhangio#989.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bugs will be investigated and fixed as quickly as possible.
Projects
Development

Successfully merging a pull request may close this issue.

1 participant