adjust demo.py and the config template to use my.config
This commit is contained in:
parent
4d33416696
commit
2bcde388d7
7 changed files with 38 additions and 24 deletions
26
demo.py
26
demo.py
|
@ -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:
|
||||||
|
|
||||||
|
|
|
@ -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..
|
||||||
|
|
13
my/init.py
13
my/init.py
|
@ -13,11 +13,18 @@ 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
|
||||||
|
|
||||||
# TODO use appdir??
|
# not sure if that's necessary, i.e. could rely on PYTHONPATH instead
|
||||||
cfg_dir = Path('~/.config').expanduser()
|
# on the other hand, by using MY_CONFIG we are guaranteed to load it from the desired path?
|
||||||
mycfg_dir = cfg_dir / 'my'
|
mvar = os.environ.get('MY_CONFIG')
|
||||||
|
if mvar is not None:
|
||||||
|
mycfg_dir = Path(mvar)
|
||||||
|
else:
|
||||||
|
# TODO use appdir??
|
||||||
|
cfg_dir = Path('~/.config').expanduser()
|
||||||
|
mycfg_dir = cfg_dir / 'my'
|
||||||
|
|
||||||
# TODO maybe try importing first and if it's present, don't do anything?
|
# TODO maybe try importing first and if it's present, don't do anything?
|
||||||
|
|
||||||
|
|
8
mycfg_template/my/config/__init__.py
Normal file
8
mycfg_template/my/config/__init__.py
Normal 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'
|
|
@ -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'
|
|
Loading…
Add table
Reference in a new issue