Skip to content

Commit 151b048

Browse files
committed
Merge branch 'main' of github.com:swerik-project/swedish-de-hyphenator
2 parents 1130f0f + 2eba6dd commit 151b048

1 file changed

Lines changed: 36 additions & 1 deletion

File tree

swedish_dehyphenator/config.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88

99
def fetch_config():
10+
"""
11+
Fetch the config (dict) and config location (str)
12+
"""
1013
try:
1114
with open(f"{os.path.dirname(os.path.abspath(__file__))}/config-loc.txt", 'r') as loc:
1215
config_loc = loc.read().strip()
@@ -22,6 +25,9 @@ def fetch_config():
2225

2326

2427
def _fetch_defaults():
28+
"""
29+
Return dict of default config values.
30+
"""
2531
return {
2632
"config_path":"~/.config/swedish_dehyphenator/config.json",
2733
"wf_path": "~/.config/swedish_dehyphenator/wf.json",
@@ -33,6 +39,16 @@ def _fetch_defaults():
3339

3440

3541
def init(args):
42+
"""
43+
Initiate a config file.
44+
45+
Args:
46+
- args: dict of values
47+
- config_path: path to config file. default `~/.config/swedish_dehyphenator/config.json`
48+
- wf_path: path to word frequency json file. default `~/.config/swedish_dehyphenator/wf.json`
49+
- autojoined_path: path to previoiusly autojoined words. default `~/.config/swedish_dehyphenator/autojoined.pickle`
50+
- selected_path: path to previously selected corrections. default `~/.config/swedish_dehyphenator/autojoined.pickle`
51+
"""
3652
to_write = _fetch_defaults()
3753
for k, v in args.items():
3854
if v is not None:
@@ -52,6 +68,16 @@ def init(args):
5268

5369

5470
def show_opts(args):
71+
"""
72+
Print config dict
73+
74+
Args:
75+
- args: dict of values
76+
- config_path: path to config file. default `~/.config/swedish_dehyphenator/config.json`
77+
- wf_path: path to word frequency json file. default `~/.config/swedish_dehyphenator/wf.json`
78+
- autojoined_path: path to previoiusly autojoined words. default `~/.config/swedish_dehyphenator/autojoined.pickle`
79+
- selected_path: path to previously selected corrections. default `~/.config/swedish_dehyphenator/autojoined.pickle`
80+
"""
5581
config, loc = fetch_config()
5682
print("\nConfig file located at:", loc, "\n")
5783
for k, v in config.items():
@@ -63,6 +89,16 @@ def show_opts(args):
6389

6490

6591
def edit(args):
92+
"""
93+
Edit config dict. Unset keys, or keys set to None are ignored.
94+
95+
Args:
96+
- args: dict of values
97+
- config_path: path to config file. default `~/.config/swedish_dehyphenator/config.json`
98+
- wf_path: path to word frequency json file. default `~/.config/swedish_dehyphenator/wf.json`
99+
- autojoined_path: path to previoiusly autojoined words. default `~/.config/swedish_dehyphenator/autojoined.pickle`
100+
- selected_path: path to previously selected corrections. default `~/.config/swedish_dehyphenator/autojoined.pickle`
101+
"""
66102
config, _path = fetch_config()
67103
for k, v in args.items():
68104
if k not in ["program", "config_path"]:
@@ -80,7 +116,6 @@ def cli():
80116
programs = {
81117
"init": init,
82118
"edit": edit,
83-
84119
"show_opts": show_opts,
85120
}
86121
parser = argparse.ArgumentParser(description=__doc__)

0 commit comments

Comments
 (0)