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:
parent
fbaa8e0b44
commit
109edd9da3
8 changed files with 82 additions and 21 deletions
49
my/core/compat.py
Normal file
49
my/core/compat.py
Normal file
|
@ -0,0 +1,49 @@
|
|||
'''
|
||||
Some backwards compatibility stuff/deprecation helpers
|
||||
'''
|
||||
import warnings
|
||||
|
||||
from ..common import LazyLogger
|
||||
|
||||
|
||||
logger = LazyLogger('my.core.compat')
|
||||
|
||||
|
||||
def pre_pip_dal_handler(
|
||||
name: str,
|
||||
e: ModuleNotFoundError,
|
||||
cfg,
|
||||
requires=[],
|
||||
) -> None:
|
||||
'''
|
||||
https://github.com/karlicoss/HPI/issues/79
|
||||
'''
|
||||
if e.name != name:
|
||||
# the module itself was imported, so the problem is with some dependencies
|
||||
raise e
|
||||
try:
|
||||
dal = _get_dal(cfg, name)
|
||||
# todo this is fairly high severity, would be nice to highlight in the terminal or something
|
||||
warnings.warn(f'''
|
||||
Specifying modules' dependencies in the config or in my/config/repos is deprecated!
|
||||
Please install {' '.join(requires)} as PIP packages (see the corresponding README instructions).
|
||||
'''.strip())
|
||||
except ModuleNotFoundError as ee:
|
||||
dal = None
|
||||
|
||||
if dal is None:
|
||||
# probably means there was nothing in the old config in the first place
|
||||
# so we should raise the original exception
|
||||
raise e
|
||||
return dal
|
||||
|
||||
|
||||
def _get_dal(cfg, module_name: str):
|
||||
mpath = getattr(cfg, module_name, None)
|
||||
if mpath is not None:
|
||||
from .common import import_dir
|
||||
return import_dir(mpath, '.dal')
|
||||
else:
|
||||
from importlib import import_module
|
||||
return import_module(f'my.config.repos.{module_name}.dal')
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue