diff --git a/my/cfg.py b/my/cfg.py index 97268da..9e039b6 100644 --- a/my/cfg.py +++ b/my/cfg.py @@ -16,11 +16,14 @@ After that, you can set config attributes: import my.config as config -def set_repo(name: str, repo): +from pathlib import Path +from typing import Union +def set_repo(name: str, repo: Union[Path, str]) -> None: from .core.init import assign_module from . common import import_from - module = import_from(repo, name) + r = Path(repo) + module = import_from(r.parent, name) assign_module('my.config.repos', name, module) diff --git a/my/core/common.py b/my/core/common.py index 1557654..83c77d7 100644 --- a/my/core/common.py +++ b/my/core/common.py @@ -195,3 +195,27 @@ def fastermime(path: PathIsh) -> str: Json = Dict[str, Any] + + +from typing import TypeVar, Callable, Generic + +_C = TypeVar('_C') +_R = TypeVar('_R') + +# https://stackoverflow.com/a/5192374/706389 +class classproperty(Generic[_R]): + def __init__(self, f: Callable[[_C], _R]) -> None: + self.f = f + + def __get__(self, obj: None, cls: _C) -> _R: + return self.f(cls) + + +# hmm, this doesn't really work with mypy well.. +# https://github.com/python/mypy/issues/6244 +# class staticproperty(Generic[_R]): +# def __init__(self, f: Callable[[], _R]) -> None: +# self.f = f +# +# def __get__(self) -> _R: +# return self.f() diff --git a/tests/config.py b/tests/config.py index 2cee194..508c387 100644 --- a/tests/config.py +++ b/tests/config.py @@ -55,8 +55,7 @@ DAL = None ''') from my.cfg import set_repo - # FIXME meh. hot sure about setting the parent?? - set_repo('hypexport', tmp_path) + set_repo('hypexport', fake_hypexport) # should succeed now! import my.hypothesis