adjust demo.py and the config template to use my.config

This commit is contained in:
Dima Gerasimov 2020-04-11 22:04:22 +01:00
parent 4d33416696
commit 2bcde388d7
7 changed files with 38 additions and 24 deletions

26
demo.py
View file

@ -30,20 +30,19 @@ def run():
], stderr=DEVNULL) ], stderr=DEVNULL)
# #
# 4. point my.config to the Hypothesis data
# 4. create private with_my file and set path to private configuration
with_my = 'my_repo/with_my'
copy('my_repo/with_my.example', with_my)
mycfg_root = abspath('my_repo/mycfg_template') mycfg_root = abspath('my_repo/mycfg_template')
# edit the config and set path to private configuration init_file = Path(mycfg_root) / 'my/config/__init__.py'
my = Path(with_my).read_text().replace("MYCFG_DIR = ''", "MYCFG_DIR = '{}'".format(mycfg_root)) init_file.write_text(init_file.read_text().replace(
Path(with_my).write_text(my) '/path/to/hypothesis/data',
hypothesis_backups,
))
# #
# 5. now we can use it! # 4. now we can use it!
os.chdir(my_repo)
check_call(['my_repo/with_my', 'python3', '-c', ''' check_call(['python3', '-c', '''
import my.hypothesis import my.hypothesis
pages = my.hypothesis.get_pages() pages = my.hypothesis.get_pages()
@ -54,7 +53,12 @@ for page in islice(pages, 0, 8):
print('Title: ' + page.title) print('Title: ' + page.title)
print('{} annotations'.format(len(page.highlights))) print('{} annotations'.format(len(page.highlights)))
print() print()
''']) '''], env={
# this is just to prevent demo.py from using real data
# normally, it will rely on having my.config in ~/.config/my
'MY_CONFIG': mycfg_root,
**os.environ,
})
# that should result in something like this: # that should result in something like this:

View file

@ -1,13 +1,15 @@
""" """
Hypothes.is highlights and annotations Hypothes.is highlights and annotations
""" """
from . import init
from .common import PathIsh from .common import PathIsh
import mycfg.repos.hypexport as hypexport import my.config.repos.hypexport as hypexport
from my.config.repos.hypexport import dal
from mycfg import paths from my.config import hypothesis as config
export_path: PathIsh = paths.hypothesis.export_path export_path: PathIsh = config.export_path
### ###
@ -17,7 +19,6 @@ from .common import get_files, cproperty, group_by_key
from .error import Res, sort_res_by from .error import Res, sort_res_by
from mycfg.repos.hypexport import dal
# TODO weird. not sure why e.g. from dal import Highlight doesn't work.. # TODO weird. not sure why e.g. from dal import Highlight doesn't work..

View file

@ -13,8 +13,15 @@ A hook to insert user's config directory into Python's search path.
def setup_config(): def setup_config():
from pathlib import Path from pathlib import Path
import sys import sys
import os
import warnings import warnings
# not sure if that's necessary, i.e. could rely on PYTHONPATH instead
# on the other hand, by using MY_CONFIG we are guaranteed to load it from the desired path?
mvar = os.environ.get('MY_CONFIG')
if mvar is not None:
mycfg_dir = Path(mvar)
else:
# TODO use appdir?? # TODO use appdir??
cfg_dir = Path('~/.config').expanduser() cfg_dir = Path('~/.config').expanduser()
mycfg_dir = cfg_dir / 'my' mycfg_dir = cfg_dir / 'my'

View file

@ -0,0 +1,8 @@
"""
Feel free to remove this if you don't need it/add your own custom settings and use them
"""
class hypothesis:
# expects outputs from https://github.com/karlicoss/hypexport
# (it's just the standard Hypothes.is export format)
export_path = '/path/to/hypothesis/data'

View file

@ -1,6 +0,0 @@
class paths:
"""
Feel free to remove this if you don't need it/add your own custom settings and use them
"""
class hypothesis:
export_path = '/tmp/my_demo/backups/hypothesis'