Skip to content

Commit

Permalink
feat: begin re-org to yafti.core
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoceppi committed Oct 12, 2023
1 parent 4abb8d4 commit d2533b4
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 16 deletions.
2 changes: 1 addition & 1 deletion yafti/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import yafti.setup # noqa
from yafti import log
from yafti.app import Yafti
from yafti.parser import Config
from yafti.core.config import Config


def run(
Expand Down
2 changes: 1 addition & 1 deletion yafti/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class YaftiPlugin:


async def _show_screen(condition):
from yafti.registry import PLUGINS
from yafti.core.registry import PLUGINS

plugin_name = list(condition.keys())[0]
plugin = PLUGINS.get(plugin_name)
Expand Down
2 changes: 1 addition & 1 deletion yafti/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from gi.repository import Adw
from pathlib import Path

from yafti.parser import Config, YaftiRunModes, YaftSaveState
from yafti.core.config import Config, YaftiRunModes, YaftSaveState
from yafti.screen.window import Window


Expand Down
Empty file added yafti/cli/__init__.py
Empty file.
Empty file added yafti/core/__init__.py
Empty file.
43 changes: 34 additions & 9 deletions yafti/parser.py → yafti/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@

from enum import Enum
from pathlib import Path
from typing import Optional
from typing import Optional, Any

import yaml
from pydantic import BaseModel
from pydantic import BaseModel, BaseSettings
from pydantic.env_settings import SettingsSourceCallable


class ActionConfig(BaseModel):
Expand Down Expand Up @@ -49,15 +50,39 @@ class YaftiProperties(BaseModel):
save_state: YaftSaveState = YaftSaveState.always


class Config(BaseModel):
class Config(BaseSettings):
title: str
properties: YaftiProperties = YaftiProperties()
actions: Optional[ActionConfig]
screens: Optional[dict[str, ScreenConfig]] # Screens are parsed per plugin


def parse(config_file: str) -> Config:
"""Parse the YAML or JSON file passed and return a rendered Config object"""
with open(config_file) as f:
cfg = yaml.safe_load(f)
return Config.parse_obj(cfg)
class Config:
env_prefix = "yafti_"
env_nested_delimiter = "__"
env_file = "/etc/yafti.yml"

@classmethod
def customise_sources(
cls,
init_settings: SettingsSourceCallable,
env_settings: SettingsSourceCallable,
file_secret_settings: SettingsSourceCallable,
):
return (
init_settings,
yaml_config_settings_source,
env_settings,
file_secret_settings,
)


def yaml_config_settings_source(settings: BaseSettings) -> dict[str, Any]:
"""
A simple settings source that loads variables from a JSON file
at the project's root.
Here we happen to choose to use the `env_file_encoding` from Config
when reading `config.json`
"""
encoding = settings.__config__.env_file_encoding
return yaml.safe_load(Path(settings.__config__.env_file).read_text(encoding))
File renamed without changes.
2 changes: 1 addition & 1 deletion yafti/screen/consent.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import yafti.share
from yafti import events
from yafti.abc import YaftiScreen, YaftiScreenConfig
from yafti.registry import PLUGINS
from yafti.core.registry import PLUGINS

_xml = """\
<?xml version="1.0" encoding="UTF-8"?>
Expand Down
2 changes: 1 addition & 1 deletion yafti/screen/package/screen/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def __init__(
**kwargs,
):
super().__init__(**kwargs)
from yafti.registry import PLUGINS
from yafti.core.registry import PLUGINS

self.status_page.set_title(title)
self.package_manager = PLUGINS.get(package_manager)
Expand Down
2 changes: 1 addition & 1 deletion yafti/screen/title.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from yafti import events
from yafti.abc import YaftiScreen, YaftiScreenConfig
from yafti.registry import PLUGINS
from yafti.core.registry import PLUGINS

_xml = """\
<?xml version="1.0" encoding="UTF-8"?>
Expand Down
2 changes: 1 addition & 1 deletion yafti/screen/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import yafti.share
from yafti import events
from yafti.registry import SCREENS
from yafti.core.registry import SCREENS

_xml = """\
<?xml version="1.0" encoding="UTF-8"?>
Expand Down

0 comments on commit d2533b4

Please sign in to comment.