core: deprecate my.cfg, instead my.config can (and should be) used directly
This commit is contained in:
parent
ddbb2e5f23
commit
a3305677b2
2 changed files with 15 additions and 33 deletions
21
my/cfg.py
21
my/cfg.py
|
@ -1,19 +1,8 @@
|
|||
"""
|
||||
A helper to allow configuring the modules dynamically.
|
||||
|
||||
Usage:
|
||||
|
||||
from my.cfg import config
|
||||
|
||||
After that, you can set config attributes:
|
||||
|
||||
class user_config:
|
||||
export_path = '/path/to/twitter/exports'
|
||||
config.twitter = user_config
|
||||
"""
|
||||
# TODO do I really need it?
|
||||
|
||||
# todo why do we bring this into scope? don't remember..
|
||||
import my.config as config
|
||||
|
||||
from .core import __NOT_HPI_MODULE__
|
||||
|
||||
from .core import warnings as W
|
||||
|
||||
# still used in Promnesia, maybe in dashboard?
|
||||
W.high("DEPRECATED! Please import my.config directly instead.")
|
||||
|
|
|
@ -1,25 +1,18 @@
|
|||
from pathlib import Path
|
||||
|
||||
|
||||
def setup_notes_path(notes: Path) -> None:
|
||||
# TODO reuse doc from my.cfg?
|
||||
from my.cfg import config
|
||||
|
||||
class user_config:
|
||||
paths = [notes]
|
||||
config.orgmode = user_config # type: ignore[misc,assignment]
|
||||
# TODO ugh. this belongs to tz provider or global config or someting
|
||||
import pytz
|
||||
class user_config_2:
|
||||
default_timezone = pytz.timezone('Europe/London')
|
||||
config.weight = user_config_2 # type: ignore[attr-defined,assignment]
|
||||
|
||||
|
||||
def test_dynamic_configuration(notes: Path) -> None:
|
||||
setup_notes_path(notes)
|
||||
import pytz
|
||||
from types import SimpleNamespace as NS
|
||||
|
||||
from my.body.weight import from_orgmode
|
||||
weights = [0.0 if isinstance(x, Exception) else x.value for x in from_orgmode()]
|
||||
from my.core.cfg import tmp_config
|
||||
with tmp_config() as C:
|
||||
C.orgmode = NS(paths=[notes])
|
||||
# TODO ugh. this belongs to tz provider or global config or someting
|
||||
C.weight = NS(default_timezone=pytz.timezone('Europe/London'))
|
||||
|
||||
from my.body.weight import from_orgmode
|
||||
weights = [0.0 if isinstance(x, Exception) else x.value for x in from_orgmode()]
|
||||
|
||||
assert weights == [
|
||||
0.0,
|
||||
|
|
Loading…
Add table
Reference in a new issue