@@ -62,16 +62,33 @@ class QSettings(BaseSettings):
6262
6363class Config :
6464 def __init__ (self , default_conf ):
65- self .__dict__ ["_default_config" ] = copy .deepcopy (default_conf ) # avoiding conflicts with __getattr__
65+ self .__dict__ ["_default_config" ] = copy .deepcopy (default_conf )
6666 self .reset ()
6767
68+ def validate (self ):
69+ errors = []
70+
71+ if not self .get ("provider_uri" ):
72+ errors .append (
73+ "provider_uri must be set (e.g. ~/.qlib/qlib_data or a valid path)"
74+ )
75+
76+ if not self .get ("region" ):
77+ errors .append (
78+ "region must be specified (e.g. 'cn', 'us')"
79+ )
80+
81+ if errors :
82+ raise ValueError (
83+ "Invalid Qlib configuration:\n - " + "\n - " .join (errors )
84+ )
85+
6886 def __getitem__ (self , key ):
6987 return self .__dict__ ["_config" ][key ]
7088
7189 def __getattr__ (self , attr ):
7290 if attr in self .__dict__ ["_config" ]:
7391 return self .__dict__ ["_config" ][attr ]
74-
7592 raise AttributeError (f"No such `{ attr } ` in self._config" )
7693
7794 def get (self , key , default = None ):
@@ -109,14 +126,20 @@ def set_conf_from_C(self, config_c):
109126
110127 @staticmethod
111128 def register_from_C (config , skip_register = True ):
112- from .utils import set_log_with_config # pylint: disable=C0415
129+ from .utils import set_log_with_config
113130
114131 if C .registered and skip_register :
115132 return
116133
134+
117135 C .set_conf_from_C (config )
136+
137+
138+ C .validate ()
139+
118140 if C .logging_config :
119141 set_log_with_config (C .logging_config )
142+
120143 C .register ()
121144
122145
@@ -523,4 +546,4 @@ def registered(self):
523546
524547
525548# global config
526- C = QlibConfig (_default_config )
549+ C = QlibConfig (_default_config )
0 commit comments