From 070de451e421bc53f400c0268a456aefe6d8f30b Mon Sep 17 00:00:00 2001 From: Hui Zhou Date: Wed, 3 Jul 2024 14:46:22 +0200 Subject: [PATCH] FIX: edb.configuration to support pathlib (#636) * REFACTOR: minor * FIX: load to support Pathlib * MISC: Auto fixes from pre-commit.com hooks For more information, see https://pre-commit.ci --------- Co-authored-by: ring630 <@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- src/pyedb/configuration/cfg_ports_sources.py | 2 ++ src/pyedb/configuration/configuration.py | 24 ++++++++++---------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/pyedb/configuration/cfg_ports_sources.py b/src/pyedb/configuration/cfg_ports_sources.py index 8e20c6877a..ab413ab9c2 100644 --- a/src/pyedb/configuration/cfg_ports_sources.py +++ b/src/pyedb/configuration/cfg_ports_sources.py @@ -104,6 +104,7 @@ def get_data_from_db(self): negative_terminal=neg_term_info, ) self.sources.append(cfg_src) + return self.export_properties() def export_properties(self): sources = [] @@ -165,6 +166,7 @@ def get_data_from_db(self): ) self.ports.append(cfg_port) + return self.export_properties() def export_properties(self): ports = [] diff --git a/src/pyedb/configuration/configuration.py b/src/pyedb/configuration/configuration.py index 39c6e6fdc9..6d6a55f4b0 100644 --- a/src/pyedb/configuration/configuration.py +++ b/src/pyedb/configuration/configuration.py @@ -65,14 +65,16 @@ def load(self, config_file, append=True, apply_file=False, output_file=None, ope """ if isinstance(config_file, dict): data = config_file - elif os.path.isfile(config_file): - with open(config_file, "r") as f: - if config_file.endswith(".json"): - data = json.load(f) - elif config_file.endswith(".toml"): - data = toml.load(f) - else: # pragma: no cover - return False + else: + config_file = str(config_file) + if os.path.isfile(config_file): + with open(config_file, "r") as f: + if config_file.endswith(".json"): + data = json.load(f) + elif config_file.endswith(".toml"): + data = toml.load(f) + else: # pragma: no cover + return False if not append: # pragma: no cover self.data = {} @@ -270,11 +272,9 @@ def get_data_from_db(self, **kwargs): if kwargs.get("setups", False): data["setups"] = self.cfg_data.setups.get_data_from_db() if kwargs.get("sources", False): - self.cfg_data.sources.get_data_from_db() - data["sources"] = self.cfg_data.sources.export_properties() + data["sources"] = self.cfg_data.sources.get_data_from_db() if kwargs.get("ports", False): - self.cfg_data.ports.get_data_from_db() - data["ports"] = self.cfg_data.ports.export_properties() + data["ports"] = self.cfg_data.ports.get_data_from_db() if kwargs.get("components", False): data["components"] = self.cfg_data.components.get_data_from_db() if kwargs.get("nets", False):