Use symlink for hypexport
This commit is contained in:
parent
90f4587cc8
commit
af810eb325
4 changed files with 56 additions and 44 deletions
13
README.md
13
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.
|
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
|
||||||
|
```
|
||||||
|
|
35
misc.org
Normal file
35
misc.org
Normal file
|
@ -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..
|
||||||
|
|
|
@ -1,47 +1,8 @@
|
||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from . import paths
|
from my_configuration import paths
|
||||||
from .common import import_file
|
import my_configuration.repos.hypexport.model as hypexport
|
||||||
|
|
||||||
# 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
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
def get_model() -> hypexport.Model:
|
def get_model() -> hypexport.Model:
|
||||||
export_dir = Path(paths.hypexport.export_dir)
|
export_dir = Path(paths.hypexport.export_dir)
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
#!/bin/bash -eu
|
#!/bin/bash -eu
|
||||||
|
|
||||||
# set path to my_configuration.py file here
|
# set path to directory containing my_configuration.py file here
|
||||||
MY_CONFIGURATION_PATH=
|
# it can also be directory containing my_configuration package with __init__.py inside etc.
|
||||||
|
MY_CONFIGURATION_DIR=
|
||||||
|
|
||||||
|
|
||||||
if [[ -n "${PYTHONPATH:=}" ]]; then
|
if [[ -n "${PYTHONPATH:=}" ]]; then
|
||||||
|
@ -11,7 +12,9 @@ else
|
||||||
fi
|
fi
|
||||||
|
|
||||||
MY_DIR="$(dirname "$(readlink -f "$0")")"
|
MY_DIR="$(dirname "$(readlink -f "$0")")"
|
||||||
MY_CONFIGURATION_DIR="$(dirname "$(readlink -f "$MY_CONFIGURATION_PATH")")"
|
|
||||||
export PYTHONPATH="$MY_CONFIGURATION_DIR:$MY_DIR""$PREV"
|
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 "$@"
|
exec "$@"
|
||||||
|
|
Loading…
Add table
Reference in a new issue