@@ -68,15 +68,33 @@ def parse_key(dotted_name: str):
6868
6969 @staticmethod
7070 def from_path (path : Optional [Path ]) -> Optional ['_InternalCF' ]:
71- return _InternalCF (path ) if path and path .exists () else None
71+ config = _InternalCF (path ) if path and path .exists () else None
72+ if not config :
73+ return None
74+ path_d = Path (f'{ path } .d' )
75+ if path_d .exists ():
76+ # update config with values from config files under .d in
77+ # lexicographic order
78+ for conf in sorted (path_d .iterdir ()):
79+ config .cp .read (path_d / conf , encoding = 'utf-8' )
80+ # finally overwrite with values from actual config again
81+ config .cp .read (path , encoding = 'utf-8' )
82+ return config
7283
7384 def __init__ (self , path : Path ):
7485 self .path = path
7586 self .cp = _configparser ()
87+ self ._read (path )
88+
89+ def _read (self , path : Path ):
7690 read_files = self .cp .read (path , encoding = 'utf-8' )
7791 if len (read_files ) != 1 :
7892 raise FileNotFoundError (path )
7993
94+ def _write (self ):
95+ with open (self .path , 'w' , encoding = 'utf-8' ) as f :
96+ self .cp .write (f )
97+
8098 def __contains__ (self , option : str ) -> bool :
8199 section , key = _InternalCF .parse_key (option )
82100
@@ -110,8 +128,7 @@ def set(self, option: str, value: Any):
110128
111129 self .cp [section ][key ] = value
112130
113- with open (self .path , 'w' , encoding = 'utf-8' ) as f :
114- self .cp .write (f )
131+ self ._write ()
115132
116133 def delete (self , option : str ):
117134 section , key = _InternalCF .parse_key (option )
@@ -123,8 +140,7 @@ def delete(self, option: str):
123140 if not self .cp [section ].items ():
124141 del self .cp [section ]
125142
126- with open (self .path , 'w' , encoding = 'utf-8' ) as f :
127- self .cp .write (f )
143+ self ._write ()
128144
129145class ConfigFile (Enum ):
130146 '''Types of west configuration file.
0 commit comments