Skip to content

Commit ae23402

Browse files
committed
WIP: Introduced yaml configuration
#10
1 parent b5d2ef1 commit ae23402

File tree

1 file changed

+41
-4
lines changed

1 file changed

+41
-4
lines changed

core/cnn.py

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@
1515
from collections import defaultdict, namedtuple
1616
import warnings
1717
import random
18-
# import json # unused
18+
import json # unused
19+
import yaml
1920
from functools import wraps
2021
import time
2122
import pickle
2223
import tempfile
24+
import copy
2325
from pathlib import Path
2426
from configparser import ConfigParser
2527
from typing import List, Dict, Tuple, Sequence
@@ -44,15 +46,50 @@
4446
# pyximport.install()
4547
# import .c.cfit
4648

49+
defaults = {
50+
'record_points': "points"
51+
}
52+
53+
settings = copy.copy(defaults)
54+
55+
56+
def configure(reset: bool = False):
57+
"""Configuration file parsing
58+
59+
Read a configuration file .corerc from one of the standard locations
60+
in the following order of priority:
61+
62+
- current working directory
63+
- user home directory
64+
"""
65+
66+
global defaults
67+
global settings
68+
69+
if reset:
70+
settings.update(defaults)
71+
else:
72+
cwd_rc = Path.cwd() / ".corerc"
73+
if cwd_rc.is_file():
74+
# load yaml
75+
# update settings
76+
return
77+
78+
home_rc = Path.home() / ".corerc"
79+
if home_rc.is_file():
80+
return
81+
82+
# print("No configuration file found. Using defaults.")
83+
4784

48-
def configure():
85+
def configure_deprecated():
4986
"""Read options from configuration file
5087
"""
5188

5289
CWD = Path.cwd()
53-
CWD_CONFIG = Path(f"{CWD}/.cnnrc")
90+
CWD_CONFIG = Path(f"{CWD}/.corerc")
5491
HOME = Path.home()
55-
HOME_CONFIG = Path(f"{HOME}/.cnnrc")
92+
HOME_CONFIG = Path(f"{HOME}/.corerc")
5693

5794
config_ = ConfigParser(default_section="settings")
5895
config_template = ConfigParser(

0 commit comments

Comments
 (0)