Skip to content

Commit da6c5f2

Browse files
committed
use json_dump_wrapper
1 parent 40bc1d0 commit da6c5f2

3 files changed

Lines changed: 11 additions & 4 deletions

File tree

src/somesy/codemeta/writer.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from somesy.core.models import Person, ProjectMetadata
1111
from somesy.core.writer import ProjectMetadataWriter
12+
from somesy.utils import json_dump_wrapper
1213

1314
logger = logging.getLogger("somesy")
1415

@@ -73,6 +74,7 @@ def _validate(self) -> None:
7374
f"No validation for codemeta.json files {Codemeta.__name__}: {pretty_repr(config)}"
7475
)
7576

77+
@json_dump_wrapper
7678
def _init_new_file(self) -> None:
7779
data = {
7880
"@context": [
@@ -87,8 +89,9 @@ def _init_new_file(self) -> None:
8789
}
8890
# dump to file
8991
with self.path.open("w+") as f:
90-
json.dump(data, f, indent=2, ensure_ascii=False)
92+
json.dump(data, f)
9193

94+
@json_dump_wrapper
9295
def save(self, path: Optional[Path] = None) -> None:
9396
"""Save the codemeta.json file."""
9497
path = path or self.path
@@ -107,7 +110,7 @@ def save(self, path: Optional[Path] = None) -> None:
107110

108111
with path.open("w") as f:
109112
# codemeta.json indentation is 2 spaces
110-
json.dump(data, f, indent=2, ensure_ascii=False)
113+
json.dump(data, f)
111114

112115
@staticmethod
113116
def _from_person(person: Person):

src/somesy/package_json/writer.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from somesy.core.models import Person, ProjectMetadata
1111
from somesy.core.writer import ProjectMetadataWriter
1212
from somesy.package_json.models import PackageJsonConfig
13+
from somesy.utils import json_dump_wrapper
1314

1415
logger = logging.getLogger("somesy")
1516

@@ -65,14 +66,15 @@ def _validate(self) -> None:
6566
)
6667
PackageJsonConfig(**config)
6768

69+
@json_dump_wrapper
6870
def save(self, path: Optional[Path] = None) -> None:
6971
"""Save the package.json file."""
7072
path = path or self.path
7173
logger.debug(f"Saving package.json to {path}")
7274

7375
with path.open("w") as f:
7476
# package.json indentation is 2 spaces
75-
json.dump(self._data, f, indent=2, ensure_ascii=False)
77+
json.dump(self._data, f)
7678

7779
@staticmethod
7880
def _from_person(person: Person):

tests/output/test_codemeta.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
from somesy.codemeta import Codemeta
2+
from somesy.utils import json_dump_wrapper
23
import json
34

45

6+
@json_dump_wrapper
57
def test_update_codemeta(somesy_input, tmp_path):
68
codemeta_file = tmp_path / "codemeta.json"
79

@@ -35,7 +37,7 @@ def test_update_codemeta(somesy_input, tmp_path):
3537
with open(codemeta_file, "w") as f:
3638
codemeta = json.loads(dat3)
3739
codemeta["version"] = "0.0.2"
38-
json.dump(codemeta, f, ensure_ascii=False)
40+
json.dump(codemeta, f)
3941
cm.sync(somesy_input.project)
4042
cm.save()
4143
assert codemeta_file.is_file()

0 commit comments

Comments
 (0)