handle importing model via configure method

This commit is contained in:
Dima Gerasimov 2019-11-17 14:22:43 +00:00
parent 9efe74aeb2
commit 91c9c2d2b6

View file

@ -2,7 +2,7 @@ from typing import Dict, List, NamedTuple, Optional, Sequence, Any
from pathlib import Path from pathlib import Path
from datetime import datetime from datetime import datetime
from .common import group_by_key, the, cproperty, PathIsh from .common import group_by_key, the, cproperty, PathIsh, import_file
try: try:
@ -33,7 +33,7 @@ class Config(NamedTuple):
def hypexport(self): def hypexport(self):
hp = self.hypexport_path_ hp = self.hypexport_path_
if hp is not None: if hp is not None:
raise RuntimeError("TODO") return import_file(Path(hp) / 'model.py', 'hypexport.model')
else: else:
global Model global Model
global Highlight global Highlight
@ -57,8 +57,11 @@ def configure(*, export_path: Optional[PathIsh]=None, hypexport_path: Optional[P
# TODO check if it works at runtime.. # TODO check if it works at runtime..
def get_model() -> Model: def get_model() -> Model:
export_path = config.export_path export_path = config.export_path
sources = list(sorted(export_path.glob('*.json'))) if export_path.is_file():
model = Model(sources) sources = [export_path]
else:
sources = list(sorted(export_path.glob('*.json')))
model = config.hypexport.Model(sources)
return model return model