general: use module dependencies as proper PIP packages + fallback
This commit is contained in:
parent
c68d81a8ca
commit
0682919449
5 changed files with 24 additions and 77 deletions
36
my/reddit.py
36
my/reddit.py
|
@ -6,9 +6,8 @@ REQUIRES = [
|
|||
]
|
||||
|
||||
from typing import Optional
|
||||
from .core.common import Paths, PathIsh
|
||||
from .core.common import Paths
|
||||
|
||||
from types import ModuleType
|
||||
from my.config import reddit as uconfig
|
||||
from dataclasses import dataclass
|
||||
|
||||
|
@ -21,20 +20,6 @@ class reddit(uconfig):
|
|||
# path[s]/glob to the exported JSON data
|
||||
export_path: Paths
|
||||
|
||||
# path to a local clone of rexport
|
||||
# alternatively, you can put the repository (or a symlink) in $MY_CONFIG/my/config/repos/rexport
|
||||
rexport : Optional[PathIsh] = None
|
||||
|
||||
@property
|
||||
def dal_module(self) -> ModuleType:
|
||||
rpath = self.rexport
|
||||
if rpath is not None:
|
||||
from .core.common import import_dir
|
||||
return import_dir(rpath, '.dal')
|
||||
else:
|
||||
import my.config.repos.rexport.dal as dal
|
||||
return dal
|
||||
|
||||
|
||||
from .core.cfg import make_config, Attrs
|
||||
# hmm, also nice thing about this is that migration is possible to test without the rest of the config?
|
||||
|
@ -50,16 +35,15 @@ config = make_config(reddit, migration=migration)
|
|||
###
|
||||
# TODO not sure about the laziness...
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
if TYPE_CHECKING:
|
||||
# TODO not sure what is the right way to handle this..
|
||||
import my.config.repos.rexport.dal as dal
|
||||
else:
|
||||
# TODO ugh. this would import too early
|
||||
# but on the other hand we do want to bring the objects into the scope for easier imports, etc. ugh!
|
||||
# ok, fair enough I suppose. It makes sense to configure something before using it. can always figure it out later..
|
||||
# maybe, the config could dynamically detect change and reimport itself? dunno.
|
||||
dal = config.dal_module
|
||||
try:
|
||||
from rexport import dal
|
||||
except ModuleNotFoundError as e:
|
||||
from .core.compat import pre_pip_dal_handler
|
||||
dal = pre_pip_dal_handler('rexport', e, config, requires=REQUIRES)
|
||||
# TODO ugh. this would import too early
|
||||
# but on the other hand we do want to bring the objects into the scope for easier imports, etc. ugh!
|
||||
# ok, fair enough I suppose. It makes sense to configure something before using it. can always figure it out later..
|
||||
# maybe, the config could dynamically detect change and reimport itself? dunno.
|
||||
###
|
||||
|
||||
############################
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue