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

improve env vars handling #54

Merged
merged 5 commits into from
Feb 26, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions ovos_config/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,9 @@ def get_ovos_config():
from ovos_utils.system import is_running_from_module

# populate default values
config = {"xdg": True,
"base_folder": os.environ.get("OVOS_CONFIG_BASE_FOLDER") or
"mycroft",
"config_filename": os.environ.get("OVOS_CONFIG_FILENAME") or
"mycroft.conf"}
try:
config["default_config_path"] = _oloc.find_default_config()
except FileNotFoundError: # not a mycroft device
config["default_config_path"] = join(dirname(__file__), "mycroft.conf")
config = {"base_folder": os.environ.get("OVOS_CONFIG_BASE_FOLDER") or "mycroft",
"config_filename": os.environ.get("OVOS_CONFIG_FILENAME") or "mycroft.conf",
"default_config_path": os.environ.get("OVOS_DEFAULT_CONFIG") or f"{dirname(__file__)}/mycroft.conf"}

# load ovos.conf
for path in get_ovos_default_config_paths():
Expand Down Expand Up @@ -164,6 +158,7 @@ def set_xdg_base(folder_name):
NOTE: this value will be set globally, per core overrides in ovos.conf take precedence
"""
LOG.info(f"XDG base folder set to: '{folder_name}'")
os.environ["OVOS_CONFIG_BASE_FOLDER"] = folder_name
Copy link
Member

Choose a reason for hiding this comment

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

Will need to look into side effects here since os.env could affect code outside of this module?

save_ovos_config({"base_folder": folder_name})


Expand All @@ -178,6 +173,7 @@ def set_config_filename(file_name, core_folder=None):
if core_folder:
set_xdg_base(core_folder)
LOG.info(f"config filename set to: '{file_name}'")
os.environ["OVOS_CONFIG_FILENAME"] = folder_name
JarbasAl marked this conversation as resolved.
Show resolved Hide resolved
save_ovos_config({"config_filename": file_name})


Expand All @@ -190,14 +186,14 @@ def get_config_filename():
return get_ovos_config().get("config_filename") or "mycroft.conf"


def set_default_config(file_path=None):
def set_default_config(file_path=f"{dirname(__file__)}/mycroft.conf"):
""" full path to default config file to be used
NOTE: this is a full path, not a directory! "config_filename" parameter is not used here

different derivative cores may change this file, this value is derived from ovos.conf

NOTE: this value will be set globally, per core overrides in ovos.conf take precedence
"""
file_path = file_path or _oloc.find_default_config()
LOG.info(f"default config file changed to: {file_path}")
os.environ["OVOS_DEFAULT_CONFIG"] = file_path
Copy link
Member

Choose a reason for hiding this comment

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

Will need to look into side effects here since os.env could affect code outside of this module?

save_ovos_config({"default_config_path": file_path})