From 5e8600a0a7ef5b3faa615202bdac4c7ce595a62b Mon Sep 17 00:00:00 2001 From: Jiang Date: Sat, 14 Mar 2026 14:45:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AF=B9=E5=8D=95=E4=B8=AApy?= =?UTF-8?q?thon=E6=96=87=E4=BB=B6=E7=9A=84=E7=BC=96=E8=AF=91=E6=94=AF?= =?UTF-8?q?=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/compile.py | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/scripts/compile.py b/scripts/compile.py index 1662539..b8547e6 100755 --- a/scripts/compile.py +++ b/scripts/compile.py @@ -24,16 +24,26 @@ def build_extensions(target_dirs): for target_dir in target_dirs: # Ensure target directory exists if not os.path.exists(target_dir): - print(f"Warning: Directory '{target_dir}' not found. Skipping.") + print(f"Warning: Path '{target_dir}' not found. Skipping.") continue - # Get the absolute path of the target directory - abs_target_dir = os.path.abspath(target_dir) + # Get the absolute path of the target + abs_target_path = os.path.abspath(target_dir) - print(f"Scanning {abs_target_dir} for Python files...") + # Check if the target is a file or directory + if os.path.isfile(abs_target_path): + if abs_target_path.endswith(".py"): + file_path = abs_target_path + rel_path = os.path.relpath(file_path, project_root) + module_name = os.path.splitext(rel_path)[0].replace(os.sep, ".") + print(f"Found file: {rel_path} -> {module_name}") + extensions.append(Extension(module_name, [file_path])) + continue + + print(f"Scanning {abs_target_path} for Python files...") # Walk through the directory - for root, dirs, files in os.walk(abs_target_dir): + for root, dirs, files in os.walk(abs_target_path): for file in files: if file.endswith(".py"): file_path = os.path.join(root, file) @@ -100,7 +110,12 @@ def build_extensions(target_dirs): if __name__ == "__main__": # Default directories to compile if none provided - DEFAULT_TARGETS = ["app/services", "app/native/wndb", "app/algorithms"] + DEFAULT_TARGETS = [ + "app/services", + "app/native/wndb", + "app/algorithms", + "app/infra/epanet/epanet.py", + ] # Check for help flag if len(sys.argv) > 1 and sys.argv[1] in ["--help", "-h"]: