general: get rid of example_config & use demo/stub my.config instead

This commit is contained in:
Dima Gerasimov 2020-10-31 05:11:03 +00:00 committed by karlicoss
parent 96be32aa51
commit 1849a66f08
10 changed files with 27 additions and 34 deletions

View file

@ -1 +0,0 @@
/tmp/my_demo/hypothesis_repo

View file

@ -1,6 +1,15 @@
""" '''
Feel free to remove this if you don't need it/add your own custom settings and use them See https://github.com/karlicoss/HPI/blob/master/doc/SETUP.org#setting-up-modules for info on creating your own config
"""
This file is used for:
- documentation (as an example of the config structure)
- mypy: this file provides some type annotations
- for loading the actual user config
'''
#### vvvv you won't need this VVV in your personal config
from my.core import init
###
from my.core import Paths, PathIsh from my.core import Paths, PathIsh
@ -44,7 +53,7 @@ class location:
home: Union[LatLon, Sequence[Tuple[DateIsh, LatLon]]] = (1.0, -1.0) home: Union[LatLon, Sequence[Tuple[DateIsh, LatLon]]] = (1.0, -1.0)
# todo hmm it's getting out of hand.. perhaps better to keep stubs in the actual my.config presetn in the repository instead
class time: class time:
class tz: class tz:
pass pass

View file

@ -1,7 +0,0 @@
# TODO ok, this thing should trigger .cfg import presumably??
from ..core import init
# TODO maybe, reuse example_config here?
class stub:
key = 'value'

View file

@ -21,12 +21,9 @@ def modules() -> Iterable[HPIModule]:
def ignored(m: str) -> bool: def ignored(m: str) -> bool:
excluded = [ excluded = [
# legacy stuff left for backwards compatibility
'core.*', 'core.*',
'config.*', 'config.*',
## todo move these to core
'kython.*',
'mycfg_stub',
##
] ]
exs = '|'.join(excluded) exs = '|'.join(excluded)
return re.match(f'^my.({exs})$', m) is not None return re.match(f'^my.({exs})$', m) is not None

View file

@ -1,11 +1,12 @@
[mypy] [mypy]
# TODO ugh. I might need to set it dynamically because of macos??
mypy_path=~/.config/my
pretty = True pretty = True
show_error_context = True show_error_context = True
show_error_codes = True show_error_codes = True
check_untyped_defs = True check_untyped_defs = True
namespace_packages = True namespace_packages = True
# TODO ok, maybe it wasn't such a good idea..
# mainly because then tox picks it up and running against the user config, not the repository config
# mypy_path=~/.config/my
# it's not controlled by me, so for now just ignore.. # it's not controlled by me, so for now just ignore..
[mypy-my.config.repos.pdfannots.pdfannots] [mypy-my.config.repos.pdfannots.pdfannots]

View file

@ -32,12 +32,6 @@ def main():
# for mypy # for mypy
'py.typed', 'py.typed',
], ],
# todo not sure if need py.typed for all subpackages??
'my.config': [
'repos/.gitkeep',
# TODO meh, get rid of this. If I remove, hypothesis tests (messing with config) might break though
# not sure why it's not reproducing locally underr tox
],
}, },

View file

@ -33,7 +33,8 @@ def test_dynamic_configuration(notes: Path) -> None:
import pytest # type: ignore import pytest # type: ignore
def test_set_repo(tmp_path: Path) -> None: # TODO doublt I need it anymore.. keeping for now just for the sake of demonstration
def _test_set_repo(tmp_path: Path) -> None:
from my.cfg import config from my.cfg import config
class user_config: class user_config:
export_path = 'whatever', export_path = 'whatever',

17
tox.ini
View file

@ -10,9 +10,6 @@ setenv = MY_CONFIG = nonexistent
commands = commands =
pip install -e .[testing] pip install -e .[testing]
# python -m pytest {posargs} # python -m pytest {posargs}
# todo these are probably not necessary anymore?
python3 -c 'from my.config import stub as config; print(config.key)'
python3 -c 'import my.config; import my.config.repos' # shouldn't fail at least
# my.location.google deps # my.location.google deps
pip install geopy ijson pip install geopy ijson
@ -27,7 +24,6 @@ commands =
tests/core.py \ tests/core.py \
tests/misc.py \ tests/misc.py \
tests/get_files.py \ tests/get_files.py \
tests/config.py::test_set_repo \
tests/config.py::test_environment_variable \ tests/config.py::test_environment_variable \
tests/demo.py \ tests/demo.py \
tests/bluemaestro.py \ tests/bluemaestro.py \
@ -46,10 +42,8 @@ commands = ./demo.py
# specific modules that are known to be mypy compliant (to avoid false negatives) # specific modules that are known to be mypy compliant (to avoid false negatives)
[testenv:mypy-modules] [testenv:mypy-modules]
# todo add a stub with all the various configs for mypy/doc whitelist_externals = bash
setenv = MYPYPATH=doc/example_config
commands = commands =
# TODO ugh. somehow, user installed (editable??) packages leak into this environment??
pip install -e .[testing] .[optional] pip install -e .[testing] .[optional]
pip install git+https://github.com/karlicoss/ghexport pip install git+https://github.com/karlicoss/ghexport
pip install git+https://github.com/karlicoss/hypexport pip install git+https://github.com/karlicoss/hypexport
@ -60,7 +54,12 @@ commands =
pip install git+https://github.com/karlicoss/porg pip install git+https://github.com/karlicoss/porg
# todo I guess use a script... # ugh fuck. soo... need to reset HOME, otherwise user's site-packages are somehow leaking into mypy's path...
# see https://github.com/python/mypy/blob/f6fb60ef69738cbfe2dfe56c747eca8f03735d8e/mypy/modulefinder.py#L487
# this is particularly annoying when user's config is leaking and mypy isn't running against the repository config
# maybe this issue... https://github.com/tox-dev/tox/issues/838
# and also since it's Tox, we can't just set an env variable for a single command, have to spawn a subshell. jeez.
bash -c 'HOME= \
python3 -m mypy -p my.github.ghexport \ python3 -m mypy -p my.github.ghexport \
-p my.hypothesis \ -p my.hypothesis \
-p my.instapaper \ -p my.instapaper \
@ -75,7 +74,7 @@ commands =
-p my.calendar.holidays \ -p my.calendar.holidays \
--txt-report .mypy-coverage \ --txt-report .mypy-coverage \
--html-report .mypy-coverage \ --html-report .mypy-coverage \
{posargs} {posargs}'
# txt report is a bit more convenient to view on CI # txt report is a bit more convenient to view on CI