File tree Expand file tree Collapse file tree 2 files changed +26
-18
lines changed Expand file tree Collapse file tree 2 files changed +26
-18
lines changed Original file line number Diff line number Diff line change 7
7
import traceback
8
8
import typing as t
9
9
10
- import yaml
11
10
from colorama import Fore , Style
12
11
12
+ from vcspull ._internal .config_reader import ConfigReader
13
13
from vcspull .config import find_home_config_files , save_config_yaml
14
14
15
15
if t .TYPE_CHECKING :
@@ -95,19 +95,23 @@ def add_repo(
95
95
raw_config : dict [str , t .Any ] = {}
96
96
if config_file_path .exists () and config_file_path .is_file ():
97
97
try :
98
- with config_file_path .open (encoding = "utf-8" ) as f :
99
- raw_config = yaml .safe_load (f ) or {}
100
- if not isinstance (raw_config , dict ):
101
- log .error (
102
- "Config file %s is not a valid YAML dictionary. " ,
103
- config_file_path ,
104
- )
105
- return
98
+ loaded_config = ConfigReader ._from_file (config_file_path )
106
99
except Exception :
107
100
log .exception ("Error loading YAML from %s. Aborting." , config_file_path )
108
101
if log .isEnabledFor (logging .DEBUG ):
109
102
traceback .print_exc ()
110
103
return
104
+
105
+ if loaded_config is None :
106
+ raw_config = {}
107
+ elif isinstance (loaded_config , dict ):
108
+ raw_config = loaded_config
109
+ else :
110
+ log .error (
111
+ "Config file %s is not a valid YAML dictionary." ,
112
+ config_file_path ,
113
+ )
114
+ return
111
115
else :
112
116
log .info (
113
117
"Config file %s not found. A new one will be created." ,
Original file line number Diff line number Diff line change 9
9
import traceback
10
10
import typing as t
11
11
12
- import yaml
13
12
from colorama import Fore , Style
14
13
14
+ from vcspull ._internal .config_reader import ConfigReader
15
15
from vcspull .config import expand_dir , find_home_config_files , save_config_yaml
16
16
17
17
if t .TYPE_CHECKING :
@@ -134,19 +134,23 @@ def add_from_filesystem(
134
134
raw_config : dict [str , t .Any ] = {}
135
135
if config_file_path .exists () and config_file_path .is_file ():
136
136
try :
137
- with config_file_path .open (encoding = "utf-8" ) as f :
138
- raw_config = yaml .safe_load (f ) or {}
139
- if not isinstance (raw_config , dict ):
140
- log .error (
141
- "Config file %s is not a valid YAML dictionary. " ,
142
- config_file_path ,
143
- )
144
- return
137
+ loaded_config = ConfigReader ._from_file (config_file_path )
145
138
except Exception :
146
139
log .exception ("Error loading YAML from %s. Aborting." , config_file_path )
147
140
if log .isEnabledFor (logging .DEBUG ):
148
141
traceback .print_exc ()
149
142
return
143
+
144
+ if loaded_config is None :
145
+ raw_config = {}
146
+ elif isinstance (loaded_config , dict ):
147
+ raw_config = loaded_config
148
+ else :
149
+ log .error (
150
+ "Config file %s is not a valid YAML dictionary." ,
151
+ config_file_path ,
152
+ )
153
+ return
150
154
else :
151
155
log .info (
152
156
"%si%s Config file %s%s%s not found. A new one will be created." ,
You can’t perform that action at this time.
0 commit comments