2
2
import mimetypes
3
3
from enum import Enum
4
4
from pathlib import Path
5
- from typing import Optional , Union
5
+ from typing import Literal , Optional , Union
6
6
7
7
from attr import define
8
8
from pydantic import BaseModel
@@ -28,6 +28,9 @@ class MetaType(str, Enum):
28
28
PDM = "pdm"
29
29
UV = "uv"
30
30
31
+ class JSONDecoder (str , Enum ):
32
+ UJSON = "ujson"
33
+ ORJSON = "orjson"
31
34
32
35
class ConfigFile (BaseModel ):
33
36
"""Contains any configurable values passed via a config file.
@@ -47,6 +50,7 @@ class ConfigFile(BaseModel):
47
50
generate_all_tags : bool = False
48
51
http_timeout : int = 5
49
52
literal_enums : bool = False
53
+ alt_json_decoder : Optional [str ] = None
50
54
51
55
@staticmethod
52
56
def load_from_path (path : Path ) -> "ConfigFile" :
@@ -82,6 +86,7 @@ class Config:
82
86
content_type_overrides : dict [str , str ]
83
87
overwrite : bool
84
88
output_path : Optional [Path ]
89
+ alt_json_decoder : Optional [JSONDecoder ]
85
90
86
91
@staticmethod
87
92
def from_sources (
@@ -104,6 +109,14 @@ def from_sources(
104
109
"ruff check --fix ." ,
105
110
"ruff format ." ,
106
111
]
112
+
113
+ if config_file .alt_json_decoder == "ujson" :
114
+ json_decoder = JSONDecoder .UJSON
115
+ elif config_file .alt_json_decoder == "orjson" :
116
+ json_decoder = JSONDecoder .ORJSON
117
+ else :
118
+ json_decoder = None
119
+
107
120
108
121
config = Config (
109
122
meta_type = meta_type ,
@@ -119,6 +132,7 @@ def from_sources(
119
132
generate_all_tags = config_file .generate_all_tags ,
120
133
http_timeout = config_file .http_timeout ,
121
134
literal_enums = config_file .literal_enums ,
135
+ alt_json_decoder = json_decoder ,
122
136
document_source = document_source ,
123
137
file_encoding = file_encoding ,
124
138
overwrite = overwrite ,
0 commit comments