2
2
3
3
import json
4
4
from abc import ABC , abstractmethod
5
- from collections .abc import Mapping
6
5
from pathlib import Path
7
- from typing import Any , ClassVar
6
+ from typing import ClassVar
8
7
9
8
import tomlkit
10
9
@@ -56,19 +55,14 @@ class JsonProvider(FileProvider):
56
55
indent : ClassVar [int ] = 2
57
56
58
57
def get_version (self ) -> str :
59
- document = json .loads (self .file .read_text ())
60
- return self .get (document )
58
+ version = json .loads (self .file .read_text ())["version" ]
59
+ assert isinstance (version , str )
60
+ return version
61
61
62
62
def set_version (self , version : str ) -> None :
63
63
document = json .loads (self .file .read_text ())
64
- self .set (document , version )
65
- self .file .write_text (json .dumps (document , indent = self .indent ) + "\n " )
66
-
67
- def get (self , document : Mapping [str , str ]) -> str :
68
- return document ["version" ]
69
-
70
- def set (self , document : dict [str , Any ], version : str ) -> None :
71
64
document ["version" ] = version
65
+ self .file .write_text (json .dumps (document , indent = self .indent ) + "\n " )
72
66
73
67
74
68
class TomlProvider (FileProvider ):
@@ -77,16 +71,11 @@ class TomlProvider(FileProvider):
77
71
"""
78
72
79
73
def get_version (self ) -> str :
80
- document = tomlkit .parse (self .file .read_text ())
81
- return self .get (document )
74
+ version = tomlkit .parse (self .file .read_text ())["project" ]["version" ] # type: ignore[index]
75
+ assert isinstance (version , str )
76
+ return version
82
77
83
78
def set_version (self , version : str ) -> None :
84
79
document = tomlkit .parse (self .file .read_text ())
85
- self .set (document , version )
86
- self .file .write_text (tomlkit .dumps (document ))
87
-
88
- def get (self , document : tomlkit .TOMLDocument ) -> str :
89
- return document ["project" ]["version" ] # type: ignore[index,return-value]
90
-
91
- def set (self , document : tomlkit .TOMLDocument , version : str ) -> None :
92
80
document ["project" ]["version" ] = version # type: ignore[index]
81
+ self .file .write_text (tomlkit .dumps (document ))
0 commit comments