55import re
66import subprocess
77from pathlib import Path
8- from typing import List , Union
8+ from typing import List , Sequence , Union
99
1010
1111class NormalizeFormula :
12- def __init__ (
13- self ,
14- ):
12+ def __init__ (self ):
1513 self .root_dir = Path (__file__ ).resolve ().parent
1614
1715 def __call__ (
1816 self ,
19- input_content : Union [str , Path , List [ str ]],
17+ input_content : Union [str , Path , Sequence [ Union [ str , Path ] ]],
2018 out_path : Union [str , Path , None ] = None ,
2119 mode : str = "normalize" ,
2220 ) -> List [str ]:
23- input_data : List [ str ] = self .load_data (input_content )
21+ input_data = self .load_data (input_content )
2422
2523 # 将hskip 替换为hspace{}
2624 after_content = [
27- self .replace_hskip_to_hspace (v ).replace ("\r " , " " ).strip ()
25+ self .replace_hskip_to_hspace (str ( v ) ).replace ("\r " , " " ).strip ()
2826 for v in input_data
2927 ]
3028
@@ -41,7 +39,9 @@ def __call__(
4139 self .write_txt (out_path , final_content )
4240 return final_content
4341
44- def load_data (self , input_content : Union [str , Path , List [str ]]) -> List [str ]:
42+ def load_data (
43+ self , input_content : Union [str , Path , Sequence [Union [str , Path ]]]
44+ ) -> Sequence [Union [str , Path ]]:
4545 if isinstance (input_content , list ):
4646 return input_content
4747
@@ -55,9 +55,7 @@ def load_data(self, input_content: Union[str, Path, List[str]]) -> List[str]:
5555
5656 raise NormalizeFormulaError ("The format of input content is not supported!" )
5757
58- def check_node (
59- self ,
60- ) -> bool :
58+ def check_node (self ) -> bool :
6159 if self .run_cmd ("node -v" ):
6260 return True
6361 return False
@@ -95,12 +93,14 @@ def get_normalize_formulas(self, after_content, mode) -> List[str]:
9593 input = "\n " .join (after_content ),
9694 capture_output = True ,
9795 text = True ,
98- check = True
96+ check = True ,
9997 )
10098 return result .stdout .splitlines ()
10199 except subprocess .CalledProcessError as e :
102100 print (f"Error occurred: { e .stderr } " )
103- raise NormalizeFormulaError ("Error occurred while normalizing formulas." )
101+ raise NormalizeFormulaError (
102+ "Error occurred while normalizing formulas."
103+ ) from e
104104
105105 def remove_invalid_symbols (self , normalized_formulas : List [str ]) -> List [str ]:
106106 final_content = []
@@ -136,12 +136,6 @@ def run_cmd(cmd: str) -> bool:
136136 return False
137137 return True
138138
139- @staticmethod
140- def del_file (file_path : Union [str , Path ]):
141- file_path = Path (file_path )
142- if file_path .exists () and file_path .is_file ():
143- file_path .unlink ()
144-
145139
146140class NormalizeFormulaError (Exception ):
147141 pass
0 commit comments