Skip to content

Commit

Permalink
general: get rid of example_config & use demo/stub my.config instead
Browse files Browse the repository at this point in the history
  • Loading branch information
karlicoss committed Oct 31, 2020
1 parent c410dc5 commit 9551c89
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 34 deletions.
Empty file.
1 change: 0 additions & 1 deletion doc/example_config/my/config/repos/hypexport

This file was deleted.

17 changes: 13 additions & 4 deletions doc/example_config/my/config/__init__.py → my/config.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -44,7 +53,7 @@ class location:
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 tz:
pass

7 changes: 0 additions & 7 deletions my/config/__init__.py

This file was deleted.

Empty file removed my/config/repos/.gitkeep
Empty file.
5 changes: 1 addition & 4 deletions my/core/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,9 @@ def modules() -> Iterable[HPIModule]:

def ignored(m: str) -> bool:
excluded = [
# legacy stuff left for backwards compatibility
'core.*',
'config.*',
## todo move these to core
'kython.*',
'mycfg_stub',
##
]
exs = '|'.join(excluded)
return re.match(f'^my.({exs})$', m) is not None
Expand Down
5 changes: 3 additions & 2 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
[mypy]
# TODO ugh. I might need to set it dynamically because of macos??
mypy_path=~/.config/my
pretty = True
show_error_context = True
show_error_codes = True
check_untyped_defs = 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..
[mypy-my.config.repos.pdfannots.pdfannots]
Expand Down
6 changes: 0 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ def main():
# for mypy
'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
],
},


Expand Down
3 changes: 2 additions & 1 deletion tests/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def test_dynamic_configuration(notes: Path) -> None:
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
class user_config:
export_path = 'whatever',
Expand Down
17 changes: 8 additions & 9 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ setenv = MY_CONFIG = nonexistent
commands =
pip install -e .[testing]
# 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
pip install geopy ijson
Expand All @@ -27,7 +24,6 @@ commands =
tests/core.py \
tests/misc.py \
tests/get_files.py \
tests/config.py::test_set_repo \
tests/config.py::test_environment_variable \
tests/demo.py \
tests/bluemaestro.py \
Expand All @@ -46,10 +42,8 @@ commands = ./demo.py

# specific modules that are known to be mypy compliant (to avoid false negatives)
[testenv:mypy-modules]
# todo add a stub with all the various configs for mypy/doc
setenv = MYPYPATH=doc/example_config
whitelist_externals = bash
commands =
# TODO ugh. somehow, user installed (editable??) packages leak into this environment??
pip install -e .[testing] .[optional]
pip install git+https://github.com/karlicoss/ghexport
pip install git+https://github.com/karlicoss/hypexport
Expand All @@ -60,7 +54,12 @@ commands =

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 \
-p my.hypothesis \
-p my.instapaper \
Expand All @@ -75,7 +74,7 @@ commands =
-p my.calendar.holidays \
--txt-report .mypy-coverage \
--html-report .mypy-coverage \
{posargs}
{posargs}'
# txt report is a bit more convenient to view on CI


Expand Down

0 comments on commit 9551c89

Please sign in to comment.