@@ -43,7 +43,8 @@ def dynamic_load_module(module_path: Path) -> Any:
4343
4444@app .command ()
4545def main (
46- input_file : typer .FileText = typer .Option (..., "--input" , "-i" ),
46+ encoding : str = typer .Option ("utf-8" , "--encoding" , "-e" ),
47+ input_file : str = typer .Option (..., "--input" , "-i" ),
4748 output_dir : Path = typer .Option (..., "--output" , "-o" ),
4849 model_file : str = typer .Option (None , "--model-file" , "-m" ),
4950 template_dir : Optional [Path ] = typer .Option (None , "--template-dir" , "-t" ),
@@ -57,8 +58,12 @@ def main(
5758 ),
5859 disable_timestamp : bool = typer .Option (False , "--disable-timestamp" ),
5960) -> None :
60- input_name : str = input_file .name
61- input_text : str = input_file .read ()
61+ input_name : str = input_file
62+ input_text : str
63+
64+ with open (input_file , encoding = encoding ) as f :
65+ input_text = f .read ()
66+
6267 if model_file :
6368 model_path = Path (model_file ).with_suffix ('.py' )
6469 else :
@@ -68,6 +73,7 @@ def main(
6873 return generate_code (
6974 input_name ,
7075 input_text ,
76+ encoding ,
7177 output_dir ,
7278 template_dir ,
7379 model_path ,
@@ -80,6 +86,7 @@ def main(
8086 return generate_code (
8187 input_name ,
8288 input_text ,
89+ encoding ,
8390 output_dir ,
8491 template_dir ,
8592 model_path ,
@@ -103,6 +110,7 @@ def _get_most_of_reference(data_type: DataType) -> Optional[Reference]:
103110def generate_code (
104111 input_name : str ,
105112 input_text : str ,
113+ encoding : str ,
106114 output_dir : Path ,
107115 template_dir : Optional [Path ],
108116 model_path : Optional [Path ] = None ,
@@ -219,7 +227,9 @@ def generate_code(
219227 header += f"\n # timestamp: { timestamp } "
220228
221229 for path , code in results .items ():
222- with output_dir .joinpath (path .with_suffix (".py" )).open ("wt" ) as file :
230+ with output_dir .joinpath (path .with_suffix (".py" )).open (
231+ "wt" , encoding = encoding
232+ ) as file :
223233 print (header , file = file )
224234 print ("" , file = file )
225235 print (code .rstrip (), file = file )
0 commit comments