-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from Geson-anko/Launcher/to_project_config
Launcher/to project config
- Loading branch information
Showing
2 changed files
with
41 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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__)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |