Files
OpenBB/openbb_terminal/core/session/current_system.py
Colin Delahunty 1ca7fd9beb Improves the settings/userdata command, and upgrade ruff (#5359)
* Began the fax

* Bumped ruff

* Fixed a BUNCH of ruff errors

* Fixed a lot of ruff errors

* Simplify if statements

* Fixed black

* Updated some stuff

* Updated some stuff

* A lot more ruff fixes

* Added a fix

* Added a fix

* Fixed mypy

* Fixed some stuff

* Reverted one thing

* Small fix

* Small fix

* Small fix

* Added fix

* Added fix

* Update requirements
2023-08-22 20:11:48 +00:00

43 lines
1015 B
Python

# IMPORTS STANDARD
import dataclasses
from copy import deepcopy
from typing import Any
# IMPORTS INTERNAL
from openbb_terminal.core.models import SystemModel
from openbb_terminal.core.session.env_handler import read_env
from openbb_terminal.core.session.utils import load_dict_to_model
def get_current_system() -> SystemModel:
"""Get current system."""
return deepcopy(__system)
def set_current_system(system: SystemModel):
"""Set current system."""
global __system # pylint: disable=global-statement# noqa: PLW0603
__system = system
def set_system_variable(
name: str,
value: Any,
):
"""Set system variable
Parameters
----------
name : str
Variable name
value : Any
Variable value
"""
current_system = get_current_system()
updated_system = dataclasses.replace(current_system, **{name: value}) # type: ignore
set_current_system(updated_system)
__env_dict = read_env()
__system = load_dict_to_model(__env_dict, SystemModel)