general: add compat module and helper for easy backwards compatibiltity for pre-PIP dependencies

my.hypothesis: use hypexport as a proper PIP package + fallback
This commit is contained in:
Dima Gerasimov 2020-09-29 17:40:16 +01:00 committed by karlicoss
parent fbaa8e0b44
commit 109edd9da3
8 changed files with 82 additions and 21 deletions

View file

@ -4,10 +4,15 @@
from dataclasses import dataclass
from typing import Optional
from .core import Paths, PathIsh
from .core import Paths
from my.config import hypothesis as user_config
REQUIRES = [
'git+https://github.com/karlicoss/hypexport',
]
@dataclass
class hypothesis(user_config):
@ -18,30 +23,16 @@ class hypothesis(user_config):
# paths[s]/glob to the exported JSON data
export_path: Paths
# path to a local clone of hypexport
# alternatively, you can put the repository (or a symlink) in $MY_CONFIG/my/config/repos/hypexport
hypexport : Optional[PathIsh] = None
@property
def dal_module(self):
rpath = self.hypexport
if rpath is not None:
from .core.common import import_dir
return import_dir(rpath, '.dal')
else:
import my.config.repos.hypexport.dal as dal
return dal
from .core.cfg import make_config
config = make_config(hypothesis)
from typing import TYPE_CHECKING
if TYPE_CHECKING:
import my.config.repos.hypexport.dal as dal
else:
dal = config.dal_module
try:
from hypexport import dal
except ModuleNotFoundError as e:
from .core.compat import pre_pip_dal_handler
dal = pre_pip_dal_handler('hypexport', e, config, requires=REQUIRES)
############################