refactor: annotation with __future__.annotations
Adds `from __future__ import annotations` to the top of every module,
right below the module's docstring. Replaces any usages of t.List,
t.Dict, t.Set, t.Tuple, and t.Type with their built-in equivalents:
list, dict, set, tuple, and type. Ensures that make test still passes
under Python 3.7, 3.8 and 3.9.
2023-01-17 18:57:23 +00:00
|
|
|
from __future__ import annotations
|
2023-01-06 18:02:17 +00:00
|
|
|
|
2019-06-03 22:44:12 +00:00
|
|
|
import os
|
2023-11-06 16:35:01 +00:00
|
|
|
import typing as t
|
|
|
|
from copy import deepcopy
|
2019-06-03 22:44:12 +00:00
|
|
|
|
2022-02-07 17:11:43 +00:00
|
|
|
from tutor import env, exceptions, fmt, hooks, plugins, serialize, utils
|
|
|
|
from tutor.types import Config, ConfigValue, cast_config, get_typed
|
2019-06-03 22:44:12 +00:00
|
|
|
|
2021-11-23 08:25:09 +00:00
|
|
|
CONFIG_FILENAME = "config.yml"
|
|
|
|
|
2019-06-03 22:44:12 +00:00
|
|
|
|
2021-11-08 13:46:38 +00:00
|
|
|
def load(root: str) -> Config:
|
2019-06-05 13:43:51 +00:00
|
|
|
"""
|
2021-11-08 13:46:38 +00:00
|
|
|
Load full configuration.
|
|
|
|
|
|
|
|
This will raise an exception if there is no current configuration in the
|
|
|
|
project root. A warning will also be printed if the version from disk
|
|
|
|
differs from the package version.
|
2019-06-05 13:43:51 +00:00
|
|
|
"""
|
2021-11-08 13:46:38 +00:00
|
|
|
if not os.path.exists(config_path(root)):
|
|
|
|
raise exceptions.TutorError(
|
|
|
|
"Project root does not exist. Make sure to generate the initial "
|
|
|
|
"configuration with `tutor config save --interactive` or `tutor local "
|
2022-09-30 10:00:24 +00:00
|
|
|
"launch` prior to running other commands."
|
2021-11-08 13:46:38 +00:00
|
|
|
)
|
|
|
|
env.check_is_up_to_date(root)
|
|
|
|
return load_full(root)
|
2019-06-03 22:44:12 +00:00
|
|
|
|
|
|
|
|
2023-10-02 07:08:07 +00:00
|
|
|
def load_defaults() -> Config:
|
|
|
|
"""
|
|
|
|
Load default configuration.
|
|
|
|
"""
|
|
|
|
config: Config = {}
|
|
|
|
update_with_defaults(config)
|
|
|
|
return config
|
|
|
|
|
|
|
|
|
2021-11-08 13:46:38 +00:00
|
|
|
def load_minimal(root: str) -> Config:
|
2019-06-03 22:44:12 +00:00
|
|
|
"""
|
2021-11-08 13:46:38 +00:00
|
|
|
Load a minimal configuration composed of the user and the base config.
|
2019-12-24 16:22:12 +00:00
|
|
|
|
2021-11-08 13:46:38 +00:00
|
|
|
This configuration is not suitable for rendering templates, as it is incomplete.
|
|
|
|
"""
|
|
|
|
config = get_user(root)
|
|
|
|
update_with_base(config)
|
|
|
|
render_full(config)
|
2019-06-03 22:44:12 +00:00
|
|
|
return config
|
|
|
|
|
|
|
|
|
2021-11-08 13:46:38 +00:00
|
|
|
def load_full(root: str) -> Config:
|
2019-06-03 22:44:12 +00:00
|
|
|
"""
|
2021-11-08 13:46:38 +00:00
|
|
|
Load a full configuration, with user, base and defaults.
|
2021-11-23 08:25:09 +00:00
|
|
|
|
|
|
|
Return:
|
|
|
|
current (dict): params currently saved in config.yml
|
|
|
|
defaults (dict): default values of params which might be missing from the
|
|
|
|
current config
|
2019-06-03 22:44:12 +00:00
|
|
|
"""
|
2021-11-08 13:46:38 +00:00
|
|
|
config = get_user(root)
|
|
|
|
update_with_base(config)
|
|
|
|
update_with_defaults(config)
|
|
|
|
render_full(config)
|
2023-10-02 07:08:07 +00:00
|
|
|
hooks.Actions.CONFIG_LOADED.do(deepcopy(config))
|
2021-11-08 13:46:38 +00:00
|
|
|
return config
|
2019-06-03 22:44:12 +00:00
|
|
|
|
|
|
|
|
2021-11-08 13:46:38 +00:00
|
|
|
def update_with_base(config: Config) -> None:
|
2019-06-03 22:44:12 +00:00
|
|
|
"""
|
2021-11-08 13:46:38 +00:00
|
|
|
Add base configuration to the config object.
|
|
|
|
|
|
|
|
Note that configuration entries are unrendered at this point.
|
2019-06-03 22:44:12 +00:00
|
|
|
"""
|
2022-02-07 17:11:43 +00:00
|
|
|
base = get_base()
|
2021-11-08 13:46:38 +00:00
|
|
|
merge(config, base)
|
2019-06-03 22:44:12 +00:00
|
|
|
|
|
|
|
|
2021-11-08 13:46:38 +00:00
|
|
|
def update_with_defaults(config: Config) -> None:
|
|
|
|
"""
|
|
|
|
Add default configuration to the config object.
|
2019-06-03 22:44:12 +00:00
|
|
|
|
2021-11-08 13:46:38 +00:00
|
|
|
Note that configuration entries are unrendered at this point.
|
|
|
|
"""
|
2022-02-07 17:11:43 +00:00
|
|
|
defaults = get_defaults()
|
2021-11-08 13:46:38 +00:00
|
|
|
merge(config, defaults)
|
2020-01-16 14:40:38 +00:00
|
|
|
|
|
|
|
|
2021-11-08 13:46:38 +00:00
|
|
|
def update_with_env(config: Config) -> None:
|
2019-06-03 22:44:12 +00:00
|
|
|
"""
|
2021-11-08 13:46:38 +00:00
|
|
|
Override config values from environment variables.
|
2019-06-03 22:44:12 +00:00
|
|
|
"""
|
2021-11-08 13:46:38 +00:00
|
|
|
overrides = {}
|
|
|
|
for k in config.keys():
|
2019-06-03 22:44:12 +00:00
|
|
|
env_var = "TUTOR_" + k
|
|
|
|
if env_var in os.environ:
|
2021-11-08 13:46:38 +00:00
|
|
|
overrides[k] = serialize.parse(os.environ[env_var])
|
|
|
|
config.update(overrides)
|
2019-06-03 22:44:12 +00:00
|
|
|
|
|
|
|
|
2021-11-08 13:46:38 +00:00
|
|
|
def get_user(root: str) -> Config:
|
2019-06-03 22:44:12 +00:00
|
|
|
"""
|
2021-11-08 13:46:38 +00:00
|
|
|
Get the user configuration from the tutor root.
|
|
|
|
|
|
|
|
Overrides from environment variables are loaded as well.
|
2019-06-03 22:44:12 +00:00
|
|
|
"""
|
2021-10-18 09:43:40 +00:00
|
|
|
convert_json2yml(root)
|
2021-11-08 13:46:38 +00:00
|
|
|
path = config_path(root)
|
|
|
|
config = {}
|
|
|
|
if os.path.exists(path):
|
|
|
|
config = get_yaml_file(path)
|
|
|
|
upgrade_obsolete(config)
|
|
|
|
update_with_env(config)
|
|
|
|
return config
|
2019-06-03 22:44:12 +00:00
|
|
|
|
2019-06-05 17:57:30 +00:00
|
|
|
|
2022-02-07 17:11:43 +00:00
|
|
|
def get_base() -> Config:
|
2019-06-05 13:43:51 +00:00
|
|
|
"""
|
2021-11-08 13:46:38 +00:00
|
|
|
Load the base configuration.
|
|
|
|
|
|
|
|
Entries in this configuration are unrendered.
|
2019-06-05 13:43:51 +00:00
|
|
|
"""
|
2021-11-08 13:46:38 +00:00
|
|
|
base = get_template("base.yml")
|
refactor: annotation with __future__.annotations
Adds `from __future__ import annotations` to the top of every module,
right below the module's docstring. Replaces any usages of t.List,
t.Dict, t.Set, t.Tuple, and t.Type with their built-in equivalents:
list, dict, set, tuple, and type. Ensures that make test still passes
under Python 3.7, 3.8 and 3.9.
2023-01-17 18:57:23 +00:00
|
|
|
extra_config: list[tuple[str, ConfigValue]] = []
|
2022-02-07 17:11:43 +00:00
|
|
|
extra_config = hooks.Filters.CONFIG_UNIQUE.apply(extra_config)
|
|
|
|
extra_config = hooks.Filters.CONFIG_OVERRIDES.apply(extra_config)
|
|
|
|
for name, value in extra_config:
|
|
|
|
if name in base:
|
|
|
|
fmt.echo_alert(
|
|
|
|
f"Found conflicting values for setting '{name}': '{value}' or '{base[name]}'"
|
|
|
|
)
|
|
|
|
base[name] = value
|
2021-11-08 13:46:38 +00:00
|
|
|
return base
|
|
|
|
|
|
|
|
|
2022-02-07 17:11:43 +00:00
|
|
|
def get_defaults() -> Config:
|
2021-11-08 13:46:38 +00:00
|
|
|
"""
|
|
|
|
Get default configuration, including from plugins.
|
|
|
|
|
|
|
|
Entries in this configuration are unrendered.
|
|
|
|
"""
|
2023-11-20 14:54:32 +00:00
|
|
|
defaults = dict(hooks.Filters.CONFIG_DEFAULTS.iterate())
|
2021-11-08 13:46:38 +00:00
|
|
|
update_with_env(defaults)
|
|
|
|
return defaults
|
|
|
|
|
|
|
|
|
2023-11-20 14:54:32 +00:00
|
|
|
@hooks.Filters.CONFIG_DEFAULTS.add(priority=hooks.priorities.HIGH)
|
|
|
|
def _load_config_defaults_yml(
|
|
|
|
items: list[tuple[str, t.Any]]
|
|
|
|
) -> list[tuple[str, t.Any]]:
|
|
|
|
defaults = get_template("defaults.yml")
|
|
|
|
items += list(defaults.items())
|
|
|
|
return items
|
|
|
|
|
|
|
|
|
2021-11-08 13:46:38 +00:00
|
|
|
def get_template(filename: str) -> Config:
|
|
|
|
"""
|
|
|
|
Get one of the configuration templates.
|
|
|
|
|
|
|
|
Entries in this configuration are unrendered.
|
|
|
|
"""
|
2022-11-21 08:56:59 +00:00
|
|
|
config = serialize.load(env.read_core_template_file("config", filename))
|
2021-11-08 13:46:38 +00:00
|
|
|
return cast_config(config)
|
|
|
|
|
|
|
|
|
|
|
|
def get_yaml_file(path: str) -> Config:
|
|
|
|
"""
|
|
|
|
Load config from yaml file.
|
|
|
|
"""
|
2022-02-07 17:11:43 +00:00
|
|
|
with open(path, encoding="utf-8") as f:
|
2021-11-08 13:46:38 +00:00
|
|
|
config = serialize.load(f.read())
|
|
|
|
return cast_config(config)
|
|
|
|
|
|
|
|
|
|
|
|
def merge(config: Config, base: Config) -> None:
|
|
|
|
"""
|
|
|
|
Merge base values with user configuration. Values are only added if not
|
|
|
|
already present.
|
|
|
|
|
|
|
|
Note that this function does not perform the rendering step of the
|
|
|
|
configuration entries.
|
|
|
|
"""
|
|
|
|
for key, value in base.items():
|
|
|
|
if key not in config:
|
|
|
|
config[key] = value
|
|
|
|
|
|
|
|
|
|
|
|
def render_full(config: Config) -> None:
|
|
|
|
"""
|
|
|
|
Fill and render an existing configuration with defaults.
|
|
|
|
|
|
|
|
It is generally necessary to apply this function before rendering templates,
|
|
|
|
otherwise configuration entries may not be rendered.
|
|
|
|
"""
|
|
|
|
for key, value in config.items():
|
|
|
|
config[key] = env.render_unknown(config, value)
|
2019-06-05 13:43:51 +00:00
|
|
|
|
2019-06-03 22:44:12 +00:00
|
|
|
|
2021-04-06 10:09:00 +00:00
|
|
|
def is_service_activated(config: Config, service: str) -> bool:
|
2021-02-25 08:09:14 +00:00
|
|
|
return config["RUN_" + service.upper()] is not False
|
Improve job running in local and k8s
Running jobs was previously done with "exec". This was because it
allowed us to avoid copying too much container specification information
from the docker-compose/deployments files to the jobs files. However,
this was limiting:
- In order to run a job, the corresponding container had to be running.
This was particularly painful in Kubernetes, where containers are
crashing as long as migrations are not correctly run.
- Containers in which we need to run jobs needed to be present in the
docker-compose/deployments files. This is unnecessary, for example when
mysql is disabled, or in the case of the certbot container.
Now, we create dedicated jobs files, both for local and k8s deployment.
This introduces a little redundancy, but not too much. Note that
dependent containers are not listed in the docker-compose.jobs.yml file,
so an actual platform is still supposed to be running when we launch the
jobs.
This also introduces a subtle change: now, jobs go through the container
entrypoint prior to running. This is probably a good thing, as it will
avoid forgetting about incorrect environment variables.
In k8s, we find ourselves interacting way too much with the kubectl
utility. Parsing output from the CLI is a pain. So we need to switch to
the native kubernetes client library.
2020-03-25 17:47:36 +00:00
|
|
|
|
|
|
|
|
2021-04-06 10:09:00 +00:00
|
|
|
def upgrade_obsolete(config: Config) -> None:
|
2019-06-03 22:44:12 +00:00
|
|
|
# Openedx-specific mysql passwords
|
|
|
|
if "MYSQL_PASSWORD" in config:
|
|
|
|
config["MYSQL_ROOT_PASSWORD"] = config["MYSQL_PASSWORD"]
|
|
|
|
config["OPENEDX_MYSQL_PASSWORD"] = config["MYSQL_PASSWORD"]
|
|
|
|
config.pop("MYSQL_PASSWORD")
|
|
|
|
if "MYSQL_DATABASE" in config:
|
|
|
|
config["OPENEDX_MYSQL_DATABASE"] = config.pop("MYSQL_DATABASE")
|
|
|
|
if "MYSQL_USERNAME" in config:
|
|
|
|
config["OPENEDX_MYSQL_USERNAME"] = config.pop("MYSQL_USERNAME")
|
2020-09-17 10:53:14 +00:00
|
|
|
if "RUN_NOTES" in config:
|
|
|
|
if config["RUN_NOTES"]:
|
2022-02-07 17:11:43 +00:00
|
|
|
plugins.load("notes")
|
|
|
|
save_enabled_plugins(config)
|
2020-09-17 10:53:14 +00:00
|
|
|
config.pop("RUN_NOTES")
|
|
|
|
if "RUN_XQUEUE" in config:
|
|
|
|
if config["RUN_XQUEUE"]:
|
2022-02-07 17:11:43 +00:00
|
|
|
plugins.load("xqueue")
|
|
|
|
save_enabled_plugins(config)
|
2020-09-17 10:53:14 +00:00
|
|
|
config.pop("RUN_XQUEUE")
|
2019-07-07 02:02:03 +00:00
|
|
|
if "SECRET_KEY" in config:
|
|
|
|
config["OPENEDX_SECRET_KEY"] = config.pop("SECRET_KEY")
|
2020-09-17 10:53:14 +00:00
|
|
|
# Replace WEB_PROXY by RUN_CADDY
|
|
|
|
if "WEB_PROXY" in config:
|
|
|
|
config["RUN_CADDY"] = not config.pop("WEB_PROXY")
|
|
|
|
# Rename ACTIVATE_HTTPS to ENABLE_HTTPS
|
|
|
|
if "ACTIVATE_HTTPS" in config:
|
|
|
|
config["ENABLE_HTTPS"] = config.pop("ACTIVATE_HTTPS")
|
|
|
|
# Replace RUN_* variables by RUN_*
|
|
|
|
for name in [
|
|
|
|
"ACTIVATE_LMS",
|
|
|
|
"ACTIVATE_CMS",
|
|
|
|
"ACTIVATE_ELASTICSEARCH",
|
|
|
|
"ACTIVATE_MONGODB",
|
|
|
|
"ACTIVATE_MYSQL",
|
|
|
|
"ACTIVATE_REDIS",
|
|
|
|
"ACTIVATE_SMTP",
|
|
|
|
]:
|
|
|
|
if name in config:
|
|
|
|
config[name.replace("ACTIVATE_", "RUN_")] = config.pop(name)
|
2022-10-18 14:57:07 +00:00
|
|
|
# Replace nginx by caddy
|
2021-10-14 10:47:23 +00:00
|
|
|
if "RUN_CADDY" in config:
|
|
|
|
config["ENABLE_WEB_PROXY"] = config.pop("RUN_CADDY")
|
|
|
|
if "NGINX_HTTP_PORT" in config:
|
|
|
|
config["CADDY_HTTP_PORT"] = config.pop("NGINX_HTTP_PORT")
|
2019-06-03 22:44:12 +00:00
|
|
|
|
|
|
|
|
2021-02-25 08:09:14 +00:00
|
|
|
def convert_json2yml(root: str) -> None:
|
2019-06-05 13:43:51 +00:00
|
|
|
"""
|
|
|
|
Older versions of tutor used to have json config files.
|
|
|
|
"""
|
2019-06-03 22:44:12 +00:00
|
|
|
json_path = os.path.join(root, "config.json")
|
|
|
|
if not os.path.exists(json_path):
|
|
|
|
return
|
|
|
|
if os.path.exists(config_path(root)):
|
|
|
|
raise exceptions.TutorError(
|
2021-11-23 08:25:09 +00:00
|
|
|
f"Both config.json and {CONFIG_FILENAME} exist in {root}: only one of these files must exist to continue"
|
2019-06-03 22:44:12 +00:00
|
|
|
)
|
2021-11-08 13:46:38 +00:00
|
|
|
config = get_yaml_file(json_path)
|
2020-02-27 16:14:00 +00:00
|
|
|
save_config_file(root, config)
|
2019-06-03 22:44:12 +00:00
|
|
|
os.remove(json_path)
|
|
|
|
fmt.echo_info(
|
2021-11-23 08:25:09 +00:00
|
|
|
f"File config.json detected in {root} and converted to {CONFIG_FILENAME}"
|
2019-06-03 22:44:12 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-04-06 10:09:00 +00:00
|
|
|
def save_config_file(root: str, config: Config) -> None:
|
2019-06-03 22:44:12 +00:00
|
|
|
path = config_path(root)
|
|
|
|
utils.ensure_file_directory_exists(path)
|
2022-02-07 17:11:43 +00:00
|
|
|
with open(path, "w", encoding="utf-8") as of:
|
2019-06-03 22:44:12 +00:00
|
|
|
serialize.dump(config, of)
|
2021-11-23 08:25:09 +00:00
|
|
|
fmt.echo_info(f"Configuration saved to {path}")
|
2019-06-03 22:44:12 +00:00
|
|
|
|
|
|
|
|
2021-02-25 08:09:14 +00:00
|
|
|
def config_path(root: str) -> str:
|
2021-11-23 08:25:09 +00:00
|
|
|
return os.path.join(root, CONFIG_FILENAME)
|
2022-02-07 17:11:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Key name under which plugins are listed
|
|
|
|
PLUGINS_CONFIG_KEY = "PLUGINS"
|
|
|
|
|
|
|
|
|
|
|
|
def enable_plugins(config: Config) -> None:
|
|
|
|
"""
|
|
|
|
Enable all plugins listed in the configuration.
|
|
|
|
"""
|
|
|
|
plugins.load_all(get_enabled_plugins(config))
|
|
|
|
|
|
|
|
|
refactor: annotation with __future__.annotations
Adds `from __future__ import annotations` to the top of every module,
right below the module's docstring. Replaces any usages of t.List,
t.Dict, t.Set, t.Tuple, and t.Type with their built-in equivalents:
list, dict, set, tuple, and type. Ensures that make test still passes
under Python 3.7, 3.8 and 3.9.
2023-01-17 18:57:23 +00:00
|
|
|
def get_enabled_plugins(config: Config) -> list[str]:
|
2022-02-07 17:11:43 +00:00
|
|
|
"""
|
|
|
|
Return the list of plugins that are enabled, as per the configuration. Note that
|
|
|
|
this may differ from the list of loaded plugins. For instance when a plugin is
|
|
|
|
present in the configuration but it's not installed.
|
|
|
|
"""
|
|
|
|
return get_typed(config, PLUGINS_CONFIG_KEY, list, [])
|
|
|
|
|
|
|
|
|
|
|
|
def save_enabled_plugins(config: Config) -> None:
|
|
|
|
"""
|
|
|
|
Save the list of enabled plugins.
|
|
|
|
|
|
|
|
Plugins are deduplicated by name.
|
|
|
|
"""
|
|
|
|
config[PLUGINS_CONFIG_KEY] = list(plugins.iter_loaded())
|
|
|
|
|
|
|
|
|
|
|
|
@hooks.Actions.PROJECT_ROOT_READY.add()
|
|
|
|
def _enable_plugins(root: str) -> None:
|
|
|
|
"""
|
|
|
|
Enable plugins that are listed in the user configuration.
|
|
|
|
"""
|
|
|
|
config = load_minimal(root)
|
|
|
|
enable_plugins(config)
|
|
|
|
|
|
|
|
|
2023-12-08 10:55:55 +00:00
|
|
|
# This is run with a very high priority such that it is called before the plugin hooks
|
|
|
|
# are actually cleared.
|
|
|
|
@hooks.Actions.PLUGIN_UNLOADED.add(priority=hooks.priorities.HIGH - 1)
|
2022-02-07 17:11:43 +00:00
|
|
|
def _remove_plugin_config_overrides_on_unload(
|
|
|
|
plugin: str, _root: str, config: Config
|
|
|
|
) -> None:
|
|
|
|
# Find the configuration entries that were overridden by the plugin and
|
|
|
|
# remove them from the current config
|
feat: strongly typed hooks
Now that the mypy bugs have been resolved, we are able to define more precisely
and cleanly the types of Actions and Filters.
Moreover, can now strongly type named actions and hooks (in consts.py). With
such a strong typing, we get early alerts of hooks called with incorrect
arguments, which is nothing short of awesome :)
This change breaks the hooks API by removing the `context=...` argument. The
reason for that is that we cannot insert arbitrary arguments between `P.args,
P.kwargs`: https://peps.python.org/pep-0612/#the-components-of-a-paramspec
> A function declared as def inner(a: A, b: B, *args: P.args, **kwargs:
> P.kwargs) -> R has type Callable[Concatenate[A, B, P], R]. Placing
> keyword-only parameters between the *args and **kwargs is forbidden.
Getting the documentation to build in nitpicky mode is quite difficult... We
need to add `nitpick_ignore` to the docs conf.py, otherwise sphinx complains
about many missing class references. This, despite upgrading almost all doc
requirements (except docutils).
2022-10-06 10:05:01 +00:00
|
|
|
for key, _value in hooks.Filters.CONFIG_OVERRIDES.iterate_from_context(
|
2023-04-28 15:11:14 +00:00
|
|
|
hooks.Contexts.app(plugin).name
|
feat: strongly typed hooks
Now that the mypy bugs have been resolved, we are able to define more precisely
and cleanly the types of Actions and Filters.
Moreover, can now strongly type named actions and hooks (in consts.py). With
such a strong typing, we get early alerts of hooks called with incorrect
arguments, which is nothing short of awesome :)
This change breaks the hooks API by removing the `context=...` argument. The
reason for that is that we cannot insert arbitrary arguments between `P.args,
P.kwargs`: https://peps.python.org/pep-0612/#the-components-of-a-paramspec
> A function declared as def inner(a: A, b: B, *args: P.args, **kwargs:
> P.kwargs) -> R has type Callable[Concatenate[A, B, P], R]. Placing
> keyword-only parameters between the *args and **kwargs is forbidden.
Getting the documentation to build in nitpicky mode is quite difficult... We
need to add `nitpick_ignore` to the docs conf.py, otherwise sphinx complains
about many missing class references. This, despite upgrading almost all doc
requirements (except docutils).
2022-10-06 10:05:01 +00:00
|
|
|
):
|
2022-02-07 17:11:43 +00:00
|
|
|
value = config.pop(key, None)
|
|
|
|
value = env.render_unknown(config, value)
|
|
|
|
fmt.echo_info(f" config - removing entry: {key}={value}")
|
|
|
|
|
|
|
|
|
2023-12-08 10:55:55 +00:00
|
|
|
@hooks.Actions.PLUGIN_UNLOADED.add(priority=hooks.priorities.LOW)
|
2022-02-07 17:11:43 +00:00
|
|
|
def _update_enabled_plugins_on_unload(_plugin: str, _root: str, config: Config) -> None:
|
|
|
|
"""
|
|
|
|
Update the list of enabled plugins.
|
|
|
|
|
|
|
|
Note that this action must be performed after the plugin has been unloaded, hence the low priority.
|
|
|
|
"""
|
|
|
|
save_enabled_plugins(config)
|
2023-10-02 07:08:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
@hooks.Actions.CONFIG_LOADED.add()
|
|
|
|
def _check_preview_lms_host(config: Config) -> None:
|
|
|
|
"""
|
|
|
|
This will check if the PREVIEW_LMS_HOST is a subdomain of LMS_HOST.
|
|
|
|
if not, prints a warning to notify the user.
|
|
|
|
"""
|
|
|
|
|
|
|
|
lms_host = get_typed(config, "LMS_HOST", str, "")
|
|
|
|
preview_lms_host = get_typed(config, "PREVIEW_LMS_HOST", str, "")
|
|
|
|
if not preview_lms_host.endswith("." + lms_host):
|
|
|
|
fmt.echo_alert(
|
|
|
|
f'Warning: PREVIEW_LMS_HOST="{preview_lms_host}" is not a subdomain of LMS_HOST="{lms_host}". '
|
|
|
|
"This configuration is not typically recommended and may lead to unexpected behavior."
|
|
|
|
)
|