diff --git a/README.md b/README.md index 20941a8..2d72f68 100644 --- a/README.md +++ b/README.md @@ -37,3 +37,16 @@ with_my python3 -c 'import my.books.kobo as kobo; print(kobo.get_todos())' ``` Also read/run [demo.py](demo.py) for a full demonstration of setting up Hypothesis. + + +# Linting + +``` +# see https://github.com/python/mypy/issues/1645 for --namespace-packages explanation +with_my --namespace-packages my/hypothesis.py +``` +or, set up as `mypy.ini` file: +``` +[mypy] +mypy_path=/path/to/my_configuration_dir +``` diff --git a/misc.org b/misc.org new file mode 100644 index 0000000..6a113dd --- /dev/null +++ b/misc.org @@ -0,0 +1,35 @@ +Various thoughts on organizing + +* Importing external models +- First alternative: + @lru_cache() + def hypexport(): + ... import_file + + # doesn't really work either.. + # hypexport = import_file(Path(paths.hypexport.repo) / 'model.py') + + + TODO check pytest friendliness if some paths are missing? Wonder if still easier to control by manually excluding... + - not mypy/pylint friendly at all? + +- Second alternative: + symlinks in my_configuration and direct import? + + + mypy/pylint friendly + ? keeping a symlink to model.py is not much worse than hardcoding path. so it's ok I guess + +* Thoughts on organizing imports +- First way: + import my_configuration.hypexport_model as hypexport + works, but my_configuration is scattered across the repository? + +Second way: + from . import my_configuration? + doesn't seem to work with subpackages? + right, perhaps symlinking is a good idea after all?... + +Third way: + import my_configuration.repos.hypexport.model as hypexport + works, but MYPYPATH doesn't seem to be happy... + ok, --namespace-packages solves it.. + diff --git a/my/hypothesis.py b/my/hypothesis.py index 3e2c4e9..e34b9fb 100644 --- a/my/hypothesis.py +++ b/my/hypothesis.py @@ -1,47 +1,8 @@ from functools import lru_cache from pathlib import Path -from . import paths -from .common import import_file - -# from . import my_configuration # import hypexport_model as hypexport - -import my_configuration.hypexport_model as hypexport - -""" -First way: - import my_configuration.hypexport_model as hypexport - works, but my_configuration is scattered across the repository? - -Second way: - from . import my_configuration? - doesn't seem to work with subpackages? - right, perhaps symlinking is a good idea after all?... -""" - - -""" -First alternative: - @lru_cache() - def hypexport(): - ... import_file - - --- - doesn't really work either.. - hypexport = import_file(Path(paths.hypexport.repo) / 'model.py') - --- - - + TODO check pytest friendliness if some paths are missing? Wonder if still easier to control by manually excluding... - - not mypy/pylint friendly at all? - -Second: - symlinks and direct import? - - + TODO - - TODO ???? - ? keeping a symlink to model.py is not much worse than harding path. so it's ok I guess - -""" +from my_configuration import paths +import my_configuration.repos.hypexport.model as hypexport def get_model() -> hypexport.Model: export_dir = Path(paths.hypexport.export_dir) diff --git a/with_my.example b/with_my.example index f3d3900..b58d1d8 100755 --- a/with_my.example +++ b/with_my.example @@ -1,7 +1,8 @@ #!/bin/bash -eu -# set path to my_configuration.py file here -MY_CONFIGURATION_PATH= +# set path to directory containing my_configuration.py file here +# it can also be directory containing my_configuration package with __init__.py inside etc. +MY_CONFIGURATION_DIR= if [[ -n "${PYTHONPATH:=}" ]]; then @@ -11,7 +12,9 @@ else fi MY_DIR="$(dirname "$(readlink -f "$0")")" -MY_CONFIGURATION_DIR="$(dirname "$(readlink -f "$MY_CONFIGURATION_PATH")")" export PYTHONPATH="$MY_CONFIGURATION_DIR:$MY_DIR""$PREV" +# TODO wonder why py.typed file in my_configuration didn't help? +export MYPYPATH="$MY_CONFIGURATION_DIR" + exec "$@"