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
|
@ -150,10 +150,6 @@ for cls, p in modules:
|
||||||
|
|
||||||
# path[s]/glob to the exported JSON data
|
# path[s]/glob to the exported JSON data
|
||||||
export_path: Paths
|
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
|
|
||||||
#+end_src
|
#+end_src
|
||||||
** [[file:../my/pocket.py][my.pocket]]
|
** [[file:../my/pocket.py][my.pocket]]
|
||||||
|
|
||||||
|
@ -167,10 +163,6 @@ for cls, p in modules:
|
||||||
|
|
||||||
# paths[s]/glob to the exported JSON data
|
# paths[s]/glob to the exported JSON data
|
||||||
export_path: Paths
|
export_path: Paths
|
||||||
|
|
||||||
# path to a local clone of pockexport
|
|
||||||
# alternatively, you can put the repository (or a symlink) in $MY_CONFIG/my/config/repos/pockexport
|
|
||||||
pockexport : Optional[PathIsh] = None
|
|
||||||
#+end_src
|
#+end_src
|
||||||
** [[file:../my/twitter/twint.py][my.twitter.twint]]
|
** [[file:../my/twitter/twint.py][my.twitter.twint]]
|
||||||
|
|
||||||
|
@ -247,10 +239,6 @@ for cls, p in modules:
|
||||||
# path[s]/glob to the exported JSON data
|
# path[s]/glob to the exported JSON data
|
||||||
export_path: Paths
|
export_path: Paths
|
||||||
|
|
||||||
# path to a local clone of ghexport
|
|
||||||
# alternatively, you can put the repository (or a symlink) in $MY_CONFIG/my/config/repos/ghexport
|
|
||||||
ghexport : Optional[PathIsh] = None
|
|
||||||
|
|
||||||
# path to a cache directory
|
# path to a cache directory
|
||||||
# if omitted, will use /tmp
|
# if omitted, will use /tmp
|
||||||
cache_dir: Optional[PathIsh] = None
|
cache_dir: Optional[PathIsh] = None
|
||||||
|
|
|
@ -20,23 +20,9 @@ class github(user_config):
|
||||||
# path[s]/glob to the exported JSON data
|
# path[s]/glob to the exported JSON data
|
||||||
export_path: Paths
|
export_path: Paths
|
||||||
|
|
||||||
# path to a local clone of ghexport
|
|
||||||
# alternatively, you can put the repository (or a symlink) in $MY_CONFIG/my/config/repos/ghexport
|
|
||||||
ghexport : Optional[PathIsh] = None
|
|
||||||
|
|
||||||
# path to a cache directory
|
# path to a cache directory
|
||||||
# if omitted, will use /tmp
|
# if omitted, will use /tmp
|
||||||
cache_dir: Optional[PathIsh] = None
|
cache_dir: Optional[PathIsh] = None
|
||||||
|
|
||||||
@property
|
|
||||||
def dal_module(self):
|
|
||||||
rpath = self.ghexport
|
|
||||||
if rpath is not None:
|
|
||||||
from ..core.common import import_dir
|
|
||||||
return import_dir(rpath, '.dal')
|
|
||||||
else:
|
|
||||||
import my.config.repos.ghexport.dal as dal
|
|
||||||
return dal
|
|
||||||
###
|
###
|
||||||
|
|
||||||
# TODO perhaps using /tmp in case of None isn't ideal... maybe it should be treated as if cache is off
|
# TODO perhaps using /tmp in case of None isn't ideal... maybe it should be treated as if cache is off
|
||||||
|
@ -52,11 +38,11 @@ def migration(attrs: Attrs) -> Attrs:
|
||||||
config = make_config(github, migration=migration)
|
config = make_config(github, migration=migration)
|
||||||
|
|
||||||
|
|
||||||
from typing import TYPE_CHECKING
|
try:
|
||||||
if TYPE_CHECKING:
|
from ghexport import dal
|
||||||
import my.config.repos.ghexport.dal as dal
|
except ModuleNotFoundError as e:
|
||||||
else:
|
from ..core.compat import pre_pip_dal_handler
|
||||||
dal = config.dal_module
|
dal = pre_pip_dal_handler('ghexport', e, config, requires=REQUIRES)
|
||||||
|
|
||||||
############################
|
############################
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
"""
|
"""
|
||||||
[[https://hypothes.is][Hypothes.is]] highlights and annotations
|
[[https://hypothes.is][Hypothes.is]] highlights and annotations
|
||||||
"""
|
"""
|
||||||
|
REQUIRES = [
|
||||||
|
'git+https://github.com/karlicoss/hypexport',
|
||||||
|
]
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Optional, Callable
|
from typing import Optional, Callable
|
||||||
|
|
26
my/pocket.py
26
my/pocket.py
|
@ -7,7 +7,7 @@ REQUIRES = [
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from .core import Paths, PathIsh
|
from .core import Paths
|
||||||
|
|
||||||
from my.config import pocket as user_config
|
from my.config import pocket as user_config
|
||||||
|
|
||||||
|
@ -21,30 +21,16 @@ class pocket(user_config):
|
||||||
# paths[s]/glob to the exported JSON data
|
# paths[s]/glob to the exported JSON data
|
||||||
export_path: Paths
|
export_path: Paths
|
||||||
|
|
||||||
# path to a local clone of pockexport
|
|
||||||
# alternatively, you can put the repository (or a symlink) in $MY_CONFIG/my/config/repos/pockexport
|
|
||||||
pockexport : Optional[PathIsh] = None
|
|
||||||
|
|
||||||
@property
|
|
||||||
def dal_module(self):
|
|
||||||
rpath = self.pockexport
|
|
||||||
if rpath is not None:
|
|
||||||
from .core.common import import_dir
|
|
||||||
return import_dir(rpath, '.dal')
|
|
||||||
else:
|
|
||||||
import my.config.repos.pockexport.dal as dal
|
|
||||||
return dal
|
|
||||||
|
|
||||||
|
|
||||||
from .core.cfg import make_config
|
from .core.cfg import make_config
|
||||||
config = make_config(pocket)
|
config = make_config(pocket)
|
||||||
|
|
||||||
|
|
||||||
from typing import TYPE_CHECKING
|
try:
|
||||||
if TYPE_CHECKING:
|
from pockexport import dal
|
||||||
import my.config.repos.pockexport.dal as dal
|
except ModuleNotFoundError as e:
|
||||||
else:
|
from .core.compat import pre_pip_dal_handler
|
||||||
dal = config.dal_module
|
dal = pre_pip_dal_handler('pockexport', e, config, requires=REQUIRES)
|
||||||
|
|
||||||
############################
|
############################
|
||||||
|
|
||||||
|
|
36
my/reddit.py
36
my/reddit.py
|
@ -6,9 +6,8 @@ REQUIRES = [
|
||||||
]
|
]
|
||||||
|
|
||||||
from typing import Optional
|
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 my.config import reddit as uconfig
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
|
||||||
|
@ -21,20 +20,6 @@ class reddit(uconfig):
|
||||||
# path[s]/glob to the exported JSON data
|
# path[s]/glob to the exported JSON data
|
||||||
export_path: Paths
|
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
|
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?
|
# 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...
|
# TODO not sure about the laziness...
|
||||||
|
|
||||||
from typing import TYPE_CHECKING
|
try:
|
||||||
if TYPE_CHECKING:
|
from rexport import dal
|
||||||
# TODO not sure what is the right way to handle this..
|
except ModuleNotFoundError as e:
|
||||||
import my.config.repos.rexport.dal as dal
|
from .core.compat import pre_pip_dal_handler
|
||||||
else:
|
dal = pre_pip_dal_handler('rexport', e, config, requires=REQUIRES)
|
||||||
# TODO ugh. this would import too early
|
# 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!
|
# 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..
|
# 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.
|
# maybe, the config could dynamically detect change and reimport itself? dunno.
|
||||||
dal = config.dal_module
|
|
||||||
###
|
###
|
||||||
|
|
||||||
############################
|
############################
|
||||||
|
|
Loading…
Add table
Reference in a new issue