Skip to content

Commit 6bd74a1

Browse files
committed
Improve handling around config.
1 parent 9888bcb commit 6bd74a1

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

PyFunceble/config/compare.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
██║ ██║ ██║ ╚██████╔╝██║ ╚████║╚██████╗███████╗██████╔╝███████╗███████╗
1212
╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═════╝╚══════╝╚═════╝ ╚══════╝╚══════╝
1313
14-
Provides the configuration comparision interface.
14+
Provides the configuration comparison interface.
1515
1616
Author:
1717
Nissar Chababy, @funilrys, contactTATAfunilrysTODTODcom
@@ -175,7 +175,7 @@ class ConfigComparison:
175175
}
176176

177177
_local_config: dict = {}
178-
_upsteam_config: dict = {}
178+
_upstream_config: dict = {}
179179

180180
dict_helper: DictHelper = DictHelper()
181181

@@ -228,12 +228,12 @@ def upstream_config(self) -> dict:
228228
Provides the current state of the :code:`_upstream_config`.
229229
"""
230230

231-
return self._upsteam_config
231+
return self._upstream_config
232232

233233
@upstream_config.setter
234234
def upstream_config(self, value: dict) -> None:
235235
"""
236-
Sets the upstram configuration to work with.
236+
Sets the upstream configuration to work with.
237237
238238
:raise TypeError:
239239
When :code:`value` is not a :py:class:`dict`
@@ -242,11 +242,11 @@ def upstream_config(self, value: dict) -> None:
242242
if not isinstance(value, dict):
243243
raise TypeError(f"<value> should be {dict}, {type(value)} given.")
244244

245-
self._upsteam_config = copy.deepcopy(value)
245+
self._upstream_config = copy.deepcopy(value)
246246

247247
def set_upstream_config(self, value: dict) -> "ConfigComparison":
248248
"""
249-
Sets the upstram configuration to work with.
249+
Sets the upstream configuration to work with.
250250
"""
251251

252252
self.upstream_config = value
@@ -265,6 +265,7 @@ def is_local_identical(self) -> bool:
265265
)
266266
or "user_agent" not in self.local_config
267267
or not isinstance(self.local_config["user_agent"], dict)
268+
or "http_codes" not in self.local_config
268269
or "active" in self.local_config["http_codes"]
269270
or "not_found_default" in self.local_config["http_codes"]
270271
or "self_managed" not in self.local_config["http_codes"]
@@ -281,7 +282,7 @@ def is_local_identical(self) -> bool:
281282
if index in self.DELETED_CORE:
282283
return False
283284

284-
for index in self.local_config["links"]:
285+
for index in self.local_config.get("links", {}):
285286
if index in self.DELETED_LINKS:
286287
return False
287288

@@ -369,10 +370,10 @@ def get_merged(self) -> dict:
369370
del merged[index]
370371

371372
for index in self.DELETED_LINKS:
372-
if index in merged["links"]:
373+
if index in merged.get("links", {}):
373374
del merged["links"][index]
374375

375-
if not bool(merged["http_codes"]["self_managed"]):
376+
if "http_codes" in merged and not bool(merged["http_codes"]["self_managed"]):
376377
for index, values in PyFunceble.storage.STD_HTTP_CODES.list.items():
377378
merged["http_codes"]["list"][index] = list(values)
378379

PyFunceble/config/loader.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ class ConfigLoader:
9999
_config_dir: Optional[str] = None
100100
__config_loaded: bool = False
101101

102-
file_helper: FileHelper = FileHelper()
103-
dict_helper: DictHelper = DictHelper()
102+
file_helper: Optional[FileHelper] = None
103+
dict_helper: Optional[DictHelper] = None
104104

105105
def __init__(
106106
self, merge_upstream: Optional[bool] = None, *, config_dir: Optional[str] = None
@@ -123,6 +123,9 @@ def __init__(
123123
elif EnvironmentVariableHelper("PYFUNCEBLE_AUTO_CONFIGURATION").exists():
124124
self.merge_upstream = True
125125

126+
self.file_helper = FileHelper()
127+
self.dict_helper = DictHelper()
128+
126129
def __del__(self) -> None:
127130
self.destroy()
128131

@@ -451,7 +454,7 @@ def download_dynamic_infrastructure_files(
451454
self,
452455
) -> "ConfigLoader":
453456
"""
454-
Downloads all the dynamicly (generated) infrastructure files.
457+
Downloads all the dynamically (generated) infrastructure files.
455458
456459
.. note::
457460
Downloaded if missing:
@@ -532,7 +535,7 @@ def download_remote_config(src: str, dest: str = None) -> None:
532535
or self.merge_upstream
533536
or is_3_x_version(config)
534537
or not config_comparer.is_local_identical()
535-
): # pragma: no cover ## Testing the underlying comparison method is sufficent
538+
): # pragma: no cover ## Testing the underlying comparison method is sufficient
536539
config = config_comparer.get_merged()
537540

538541
self.dict_helper.set_subject(config).to_yaml_file(self.path_to_config)

0 commit comments

Comments
 (0)