CoreLib
Update to v0.1.4 Add `is_function_in_file` and if the key is "<ORIGINAL>", the `TranslationManager.translate()` will return it directly. (For some strings that don't need to translate in specific language) Launcher Update to 0.1.0a0 Add plugin system support and add some useful apis for plugin. Add "Refresh avatar cache" to account page.
This commit is contained in:
1 parent
deb06f0190
commit
c3662d4cc6
34 files changed
+2192
-57
No files matched your search
@@ -0,0 +1,22 @@
|
||||
import ast
|
||||
|
||||
|
||||
def is_function_in_file(file_path, function_name) -> tuple[bool, bool]:
|
||||
"""
|
||||
Parse a Python file via ast module to check if a function exists.
|
||||
:param file_path:
|
||||
:param function_name:
|
||||
:return:
|
||||
is_check_success: bool
|
||||
is_function_exist: bool
|
||||
"""
|
||||
try:
|
||||
with open(file_path, "r", encoding="utf-8") as f:
|
||||
root = ast.parse(f.read(), filename=file_path)
|
||||
|
||||
for node in ast.iter_child_nodes(root):
|
||||
if isinstance(node, ast.FunctionDef) and node.name == function_name:
|
||||
return True, True
|
||||
return True, False
|
||||
except (FileNotFoundError, SyntaxError):
|
||||
return False, False
|
||||
Reference in new issue
Block a user