add @classproperty, change set_repo to not require the parent
This commit is contained in:
parent
5f4acfddee
commit
66453cb29b
3 changed files with 30 additions and 4 deletions
|
@ -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)
|
||||
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue