Improve documentation for some modules

This commit is contained in:
Dima Gerasimov 2020-05-17 21:56:58 +01:00
parent c07ea0a600
commit 2a9fd54c12
7 changed files with 198 additions and 66 deletions

View file

@ -1,26 +1,63 @@
"""
[[https://hypothes.is][Hypothes.is]] highlights and annotations
"""
from .common import get_files
from .error import Res, sort_res_by
from dataclasses import dataclass
from typing import Optional
import my.config.repos.hypexport.dal as hypexport
from my.config import hypothesis as config
from .core import Paths, PathIsh
###
from my.config import hypothesis as user_config
@dataclass
class hypothesis(user_config):
'''
Uses [[https://github.com/karlicoss/hypexport][hypexport]] outputs
'''
# 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/repos/hypexport
hypexport : Optional[PathIsh] = None
@property
def dal_module(self):
rpath = self.hypexport
if rpath is not None:
from .cfg import set_repo
set_repo('hypexport', rpath)
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
############################
from typing import List
from .core.error import Res, sort_res_by
Highlight = dal.Highlight
Page = dal.Page
# TODO weird. not sure why e.g. from dal import Highlight doesn't work..
Highlight = hypexport.Highlight
Page = hypexport.Page
def _dal() -> dal.DAL:
from .core import get_files
sources = get_files(config.export_path)
return dal.DAL(sources)
# TODO eh. not sure if I should rename everything to dao/DAO or not...
def _dal() -> hypexport.DAL:
sources = get_files(config.export_path, '*.json')
return hypexport.DAL(sources)
def highlights() -> List[Res[Highlight]]:
@ -32,12 +69,6 @@ def pages() -> List[Res[Page]]:
return sort_res_by(_dal().pages(), key=lambda h: h.created)
# TODO move to side tests?
def test():
list(pages())
list(highlights())
def _main():
for page in get_pages():
print(page)