-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Configuration system implemented. Tests required. Docs update required.
- Loading branch information
Showing
10 changed files
with
69 additions
and
44 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
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
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
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,32 @@ | ||
from importlib.util import find_spec as _find_spec | ||
from sys import argv as _argv, exit as _exit | ||
|
||
from leads_vec.config import load_config as _load_config, DEFAULT_CONFIG as _DEFAULT_CONFIG | ||
|
||
|
||
def get_arg(args: list[str], name: str) -> str | None: | ||
for arg in args: | ||
if arg.startswith(name + "="): | ||
return arg[len(name) + 1:] | ||
|
||
|
||
if __name__ == '__main__': | ||
if not _find_spec("dearpygui"): | ||
raise ImportError("Please install `dearpygui` to run this module\n>>> pip install dearpygui") | ||
if not _find_spec("keyboard"): | ||
raise ImportError("Please install `keyboard` to run this module\n>>> pip install keyboard") | ||
try: | ||
from leads_emulation import SRWRandom as Controller | ||
from leads_emulation import SRWRandom as _Controller | ||
except ImportError: | ||
raise EnvironmentError("At least one adapter has to be installed") | ||
if "remote" in _argv: | ||
raise ImportError("At least one adapter has to be installed") | ||
cfg_arg = get_arg(_argv, "config") | ||
config = _load_config(cfg_arg) if cfg_arg else _DEFAULT_CONFIG | ||
|
||
if "--remote" in _argv: | ||
from leads_vec.remote import remote as _main | ||
|
||
_exit(_main()) | ||
_exit(_main(config)) | ||
else: | ||
from leads_vec.cli import main as _main | ||
|
||
_exit(_main(Controller("main"))) | ||
_exit(_main(_Controller("main"), config)) |
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 @@ | ||
__version__: str = "9458732e" | ||
__version__: str = "14788c69" |
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
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,22 +1,37 @@ | ||
from json import load as _load, loads as _loads | ||
from typing import TextIO as _TextIO, Any as _Any | ||
from json import load as _load | ||
from typing import TextIO as _TextIO, Any as _Any, Self as _Self | ||
|
||
|
||
class Config(object): | ||
def __init__(self, base: dict[str, _Any]) -> None: | ||
self._d: dict[str, _Any] = base | ||
self.srw_mode: bool = True | ||
self.analysis_rate: float = .01 | ||
self.update_rate: float = .25 | ||
self.comm_addr: str = "127.0.0.1" | ||
self.comm_port: int = 16900 | ||
self.data_dir: str = "./data" | ||
|
||
def __getitem__(self, name: str) -> _Any | None: | ||
return self._d.get(name, None) | ||
return self.get(name) | ||
|
||
def __getattr__(self, name: str) -> _Any | None: | ||
return self[name] | ||
return self.get(name) | ||
|
||
def require(self, name: str) -> _Any: | ||
if r := self[name] is None: | ||
raise KeyError(name) | ||
return r | ||
def get(self, name: str, default: _Any | None = None) -> _Any: | ||
if r := self._d.get(name): | ||
return r | ||
return default | ||
|
||
def load(self) -> _Self: | ||
for name in dir(self): | ||
if not name.startswith("_") and (v := self.get(name)): | ||
self.__setattr__(name, v) | ||
return self | ||
|
||
|
||
DEFAULT_CONFIG = Config({}) | ||
|
||
|
||
def load_config(file: str | _TextIO) -> Config: | ||
return Config(_loads(file) if isinstance(file, str) else _load(file)) | ||
return Config(_load(open(file, "r")) if isinstance(file, str) else _load(file)).load() |
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
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,5 +1,6 @@ | ||
from leads_emulation import SRWSin | ||
from leads_vec.cli import main | ||
from leads_vec.config import DEFAULT_CONFIG | ||
|
||
if __name__ == '__main__': | ||
main(SRWSin("main", 20, 60, acceleration=.008), communication_server_address="127.0.0.1") | ||
main(SRWSin("main", 20, 60, acceleration=.008), DEFAULT_CONFIG) |
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,4 +1,5 @@ | ||
from leads_vec.config import DEFAULT_CONFIG | ||
from leads_vec.remote import remote | ||
|
||
if __name__ == '__main__': | ||
remote() | ||
remote(DEFAULT_CONFIG) |