Skip to content

Commit

Permalink
Merge pull request #100 from Geson-anko/Launcher/to_project_config
Browse files Browse the repository at this point in the history
Launcher/to project config
  • Loading branch information
Geson-anko committed May 10, 2022
2 parents 1a0eea5 + 5c6d98e commit dc2a812
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
28 changes: 26 additions & 2 deletions JarvisEngine/apps/launcher.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,39 @@
from .base_app import BaseApp, AttrDict
from typing import *
import os
from ..core import logging_tool

def to_project_config(config:AttrDict) -> AttrDict:
"""convert `config` to `project_config`
`project_config` has the following structure.
```
{
MAIN: {
path: "JarvisEngine.apps.Launcher",
thread: true,
apps: config
}
}
```
"""
pconf_dict = {
logging_tool.MAIN_LOGGER_NAME:{
"path": "JarvisEngine.apps.Launcher",
"thread": True,
"apps": config
}
}
project_config = AttrDict(pconf_dict)
return project_config

class Launcher(BaseApp):
"""The origin of appcation processes.
"""

def __init__(
self, name: str, config: AttrDict,
engine_config: AttrDict, project_config:AttrDict
) -> None:
super().__init__(name, config, engine_config, project_config, os.path.dirname(__file__))

16 changes: 15 additions & 1 deletion tests/apps/test_launcher.py
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
from JarvisEngine.apps import launcher
from JarvisEngine.apps import launcher
from attr_dict import AttrDict
import importlib

def test_to_project_config():
config = AttrDict()
proj_conf = launcher.to_project_config(config)
assert "MAIN" in proj_conf
launcher_conf = proj_conf.MAIN
assert launcher_conf.path == "JarvisEngine.apps.Launcher"
mod, app = launcher_conf.path.rsplit(".",1)
assert getattr(importlib.import_module(mod), app) == launcher.Launcher
assert launcher_conf.thread == True
assert isinstance(launcher_conf.apps, AttrDict)
assert launcher_conf.apps == config

0 comments on commit dc2a812

Please sign in to comment.