Skip to content

Commit

Permalink
refactor!:drop remote config
Browse files Browse the repository at this point in the history
mark as breaking change
  • Loading branch information
JarbasAl committed Jan 11, 2025
1 parent e1e82c9 commit 1370931
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 94 deletions.
2 changes: 1 addition & 1 deletion ovos_config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ovos_config.config import Configuration, LocalConf, RemoteConf
from ovos_config.config import Configuration, LocalConf
from ovos_config.locale import set_default_lf_lang, setup_locale, \
set_default_tz, set_default_lang, get_default_tz, get_default_lang, \
get_config_tz, get_primary_lang_code, load_languages, load_language
Expand Down
18 changes: 9 additions & 9 deletions ovos_config/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
from rich.table import Table

from ovos_config import Configuration, LocalConf
from ovos_config.locations import USER_CONFIG
from ovos_config.locations import USER_CONFIG, ASSISTANT_CONFIG

CONFIG = Configuration()
CONFIGS = [("Joined", CONFIG),
("Sytem", CONFIG.system),
("User", LocalConf(USER_CONFIG)),
("Remote", CONFIG.remote)]
("Assistant", LocalConf(ASSISTANT_CONFIG)),
("User", LocalConf(USER_CONFIG))]
SECTIONS = [k for k, v in CONFIG.items() if isinstance(v, dict)] + ["base"]


Expand Down Expand Up @@ -106,7 +106,7 @@ def pathSet(dic: dict, path: str, value: Any) -> None:
click.rich_click.COMMAND_GROUPS = {
"ovos-config": [
{
"name": "Show configuration tables (Joined/User/System/Remote)",
"name": "Show configuration tables (Joined/User/System/Assistant)",
"commands": ["show"],
"table_styles": {
"row_styles": ["white"],
Expand Down Expand Up @@ -278,11 +278,11 @@ def do_merge(folder):
@config.command()
@click.option("--user", "-u", is_flag=True, help="User Configuration")
@click.option("--system", "-s", is_flag=True, help="System Configuration")
@click.option("--remote", "-r", is_flag=True, help="Remote Configuration")
@click.option("--assistant", "-a", is_flag=True, help="Assistant Configuration")
@click.option("--section", default="", show_default=False,
help="Choose a specific section from the underlying configuration")
@click.option("--list-sections", "-l", is_flag=True, help="List the sections based on the underlying configuration")
def show(user, system, remote, section, list_sections):
def show(user, system, assistant, section, list_sections):
"""\b
By ommiting a specific configuration a joined configuration table is shown. (which is the one ultimately gets loaded by ovos)
\b
Expand All @@ -294,16 +294,16 @@ def show(user, system, remote, section, list_sections):
ovos-config show -s -l # shows the sections of the system configuration
ovos-config show -u --section base # shows only the base (ie. top level) values of the user configuration
note: joining pattern: user > system > remote > default
note: joining pattern: user > system > assistant > default
\b
"""
if not any([user, system, remote]):
if not any([user, system, assistant]):
name, config = CONFIGS[0]
elif system:
name, config = CONFIGS[1]
elif user:
name, config = CONFIGS[2]
elif remote:
elif assistant:
name, config = CONFIGS[3]

# based on chosen configuration
Expand Down
52 changes: 5 additions & 47 deletions ovos_config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from ovos_config.locations import get_xdg_config_locations, ASSISTANT_CONFIG, USER_CONFIG
from ovos_config.models import LocalConf, DefaultConfig, \
DistributionConfig, SystemConfig, RemoteConf, AssistantConfig
DistributionConfig, SystemConfig, AssistantConfig

from ovos_utils.file_utils import FileWatcher
from ovos_utils.json_helper import flattened_delete, merge_dict
Expand All @@ -33,7 +33,6 @@ class Configuration(dict):
default = DefaultConfig()
distribution = DistributionConfig()
system = SystemConfig()
remote = RemoteConf()
assistant = AssistantConfig() # for runtime changes
# This includes both the user config and
# /etc/xdg/mycroft/mycroft.conf
Expand Down Expand Up @@ -103,23 +102,18 @@ def values(self):

# config methods
@staticmethod
def load_config_stack(configs=None, cache=False, remote=True):
def load_config_stack(configs=None):
"""Load a stack of config dicts into a single dict
Args:
configs (list): list of dicts to load
cache (boolean): True if result should be cached
remote (boolean): False if the Mycroft Home settings shouldn't
be loaded
Returns:
(dict) merged dict of all configuration files
"""
LOG.warning("load_config_stack has been deprecated, use load_all_configs instead")
if configs:
return Configuration.filter_and_merge(configs)
system_constraints = Configuration.get_system_constraints()
if not remote:
system_constraints["disable_remote_config"] = True
return Configuration.load_all_configs(system_constraints)

@staticmethod
Expand All @@ -137,7 +131,6 @@ def reload():
"""
Configuration.default.reload()
Configuration.system.reload()
Configuration.remote.reload()
Configuration.assistant.reload()
for cfg in Configuration.xdg_configs:
cfg.reload()
Expand All @@ -160,19 +153,16 @@ def get_system_constraints() -> dict:
def load_all_configs(system_constraints: Optional[dict] = None) -> dict:
"""
Load the stack of config files into a single dict
@param system_constraints: constraints to limit user/remote config usage
@param system_constraints: constraints to limit user config usage
@return: merged dict of all configuration files
"""
# system administrators can define different constraints in how
# configurations are loaded
system_constraints = system_constraints or \
Configuration.get_system_constraints()
skip_user = system_constraints.get("disable_user_config", False)
skip_remote = system_constraints.get("disable_remote_config", False)

configs = [Configuration.default, Configuration.distribution, Configuration.system, Configuration.assistant]
if not skip_remote:
configs.insert(1, Configuration.remote)
if not skip_user:
configs += Configuration.xdg_configs

Expand Down Expand Up @@ -201,23 +191,16 @@ def filter_and_merge(configs) -> dict:
# configurations are loaded
system_conf = Configuration.get_system_constraints()
protected_keys = system_conf.get("protected_keys") or {}
protected_remote = protected_keys.get("remote") or []
protected_user = protected_keys.get("user") or []
skip_user = system_conf.get("disable_user_config", False)
skip_remote = system_conf.get("disable_remote_config", False)

# Merge all configs into one
base = {}
for cfg in configs:
is_user = cfg.path is None or cfg.path not in [Configuration.default.path,
Configuration.system.path]
is_remote = cfg.path == Configuration.remote.path
if (is_remote and skip_remote) or (is_user and skip_user):
if is_user and skip_user:
continue
elif is_remote:
# delete protected keys from remote config
for protection in protected_remote:
flattened_delete(cfg, protection)
elif is_user:
# delete protected keys from user config
for protection in protected_user:
Expand All @@ -240,21 +223,9 @@ def set_config_update_handlers(bus):
bus.on("configuration.patch", Configuration.patch)
bus.on("configuration.patch.clear", Configuration.patch_clear)
bus.on("configuration.cache.clear", Configuration.clear_cache)
# TODO unify these namespaces, they seem to differ between dev/mk2/PHAL
bus.on("mycroft.paired", Configuration.handle_remote_update)
bus.on("mycroft.internet.connected", Configuration.handle_remote_update)

Configuration.set_config_watcher()

try:
# TODO - investigate why this import fails sometimes
from ovos_utils.network_utils import is_connected_http
if is_connected_http():
# do the initial remote fetch
Configuration.remote.reload()
except:
pass

@staticmethod
def set_config_watcher(callback: Optional[callable] = None):
"""
Expand All @@ -279,8 +250,7 @@ def _on_file_change(path: str):
"""
# reload updated config
for cfg in Configuration.xdg_configs + [Configuration.distribution,
Configuration.system,
Configuration.remote]:
Configuration.system]:
if cfg.path == path:
old_cfg = hash(cfg)
try:
Expand Down Expand Up @@ -321,18 +291,6 @@ def deregister_bus():
Configuration.patch_clear)
Configuration.bus.remove("configuration.cache.clear",
Configuration.clear_cache)
Configuration.bus.remove("mycroft.paired",
Configuration.handle_remote_update)
Configuration.bus.remove("mycroft.internet.connected",
Configuration.handle_remote_update)

@staticmethod
def handle_remote_update(message):
"""Handler for paired/internet connect
Triggers an update of remote config.
"""
Configuration.remote.reload()

@staticmethod
def updated(message):
Expand Down
41 changes: 4 additions & 37 deletions ovos_config/mycroft.conf
Original file line number Diff line number Diff line change
@@ -1,25 +1,8 @@
{
// Definition and documentation of all variables used by mycroft-core.
//
// Settings seen here are considered DEFAULT. Settings can also be
// overridden at the REMOTE level (set by the user via
// https://home.mycroft.ai), at the SYSTEM level (typically in the file
// '/etc/mycroft/mycroft.conf'), or at the USER level (typically in the
// file '~/.config/mycroft/mycroft.conf').
//
// The load order of settings is:
// DEFAULT
// REMOTE
// SYSTEM
// USER
//
// The Override: comments below indicates where these settings are generally
// set outside of this file. The load order is always followed, so an
// individual systems can still apply changes at the SYSTEM or USER levels.
// Definition and documentation of all variables used by OpenVoiceOS

// Language used for speech-to-text and text-to-speech.
// Code is a BCP-47 identifier (https://tools.ietf.org/html/bcp47), lowercased
// TODO: save unmodified, lowercase upon demand
// Code is a BCP-47 identifier (https://tools.ietf.org/html/bcp47)
"lang": "en-us",

// Secondary languages will also have their resource files loaded into memory
Expand Down Expand Up @@ -297,23 +280,11 @@
"system": {
// do not allow users to tamper with settings at all
"disable_user_config": false,
// do not allow remote backend to tamper with settings at all
"disable_remote_config": false,
// protected keys are individual settings that can not be changed at remote/user level
// protected keys are individual settings that can not be changed at user level
// nested dictionary keys can be defined with "key1:key2" syntax,
// eg. {"a": {"b": True, "c": False}}
// to protect "c" you would enter "a:c" in the section below
"protected_keys": {
"remote": [
"system",
"websocket",
"gui_websocket",
"network_tests",
// NOTE: selene returns listener settings as part of ww config
// they are protected because selene has no clue about your mic setup
"listener:channels",
"listener:sample_rate"
],
"user": []
}
},
Expand Down Expand Up @@ -585,18 +556,14 @@
},

// Level of logs to store, one of "CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG"
// NOTE: This configuration setting is special and can only be changed in the
// SYSTEM or USER configuration file, it will not be read if defined in the
// DEFAULT (here) or in the REMOTE mycroft config.
// If not defined, the default log level is INFO.
//"log_level": "INFO",

// Messagebus types that will NOT be output to logs
// DEPRECATED: this was consumed by ovos-cli-client which is being retired
"ignore_logs": ["enclosure.mouth.viseme", "enclosure.mouth.display"],

// Settings related to remote sessions
// Overrride: none
// Settings related to sessions
"session": {
// Time To Live, in seconds
"ttl": -1
Expand Down

0 comments on commit 1370931

Please sign in to comment.