Skip to content

Commit 4c3c8d0

Browse files
committed
refactor: create utils module, move read_json to utils
1 parent c793744 commit 4c3c8d0

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

arho_feature_template/core/feature_template_library.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
from __future__ import annotations
22

3-
import json
43
from typing import TYPE_CHECKING, Sequence
54

65
from qgis.core import QgsMapLayer, QgsProject, QgsVectorLayer
76
from qgis.utils import iface
87

98
from arho_feature_template.core.feature_template import FeatureTemplate
109
from arho_feature_template.core.json_config import JsonKeys
10+
from arho_feature_template.core.utils import read_json
1111

1212
if TYPE_CHECKING:
1313
from os import PathLike
@@ -18,16 +18,11 @@ class FeatureTemplateLibrary:
1818

1919
def __init__(self, json_path: str | PathLike):
2020
self.templates = []
21-
library_dict = self.read_json(json_path)
21+
library_dict = read_json(json_path)
2222
self.name = library_dict.get(JsonKeys.NAME)
2323
self.version = library_dict.get(JsonKeys.VERSION)
2424
self.build_templates(library_dict)
2525

26-
def read_json(self, json_path: str | PathLike) -> dict:
27-
self.source_json = json_path
28-
with open(json_path) as f:
29-
return json.load(f)
30-
3126
def build_templates(self, library_dict: dict):
3227
"""Build feature templates from input `library_dict` and update `templates` attribute."""
3328
all_templates_count = 0

arho_feature_template/core/utils.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import json
2+
3+
from typing import TYPE_CHECKING
4+
5+
if TYPE_CHECKING:
6+
from os import PathLike
7+
8+
9+
def read_json(json_path: str | PathLike) -> dict:
10+
with open(json_path) as f:
11+
return json.load(f)

0 commit comments

Comments
 (0)