From d27890d98ddedfd86f23c9aef12ab422b413f1a2 Mon Sep 17 00:00:00 2001 From: krahets Date: Mon, 23 Oct 2023 16:06:33 +0800 Subject: [PATCH] Fix automating build workflow for Python --- .github/workflows/python.yml | 1 - codes/python/build.py | 27 +++++++++++++++------------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index fdaef5a67..f77c7d60c 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -32,7 +32,6 @@ jobs: run: | python -m pip install --upgrade pip pip install black - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - name: Lint with black run: | black codes/python diff --git a/codes/python/build.py b/codes/python/build.py index 6c721f389..98523f2c0 100644 --- a/codes/python/build.py +++ b/codes/python/build.py @@ -1,17 +1,20 @@ import glob import py_compile as pyc -src_paths = sorted(glob.glob("codes/python/**/*.py")) -num_src = len(src_paths) -num_src_error = 0 +if __name__ == "__main__": + # find source code files + src_paths = sorted(glob.glob("codes/python/**/*.py")) + num_src = len(src_paths) + num_src_error = 0 -for src_path in src_paths: - try: - pyc.compile(src_path, doraise=True) - except pyc.PyCompileError as e: - num_src_error += 1 - print(e) + # compile python code + for src_path in src_paths: + try: + pyc.compile(src_path, doraise=True) + except pyc.PyCompileError as e: + num_src_error += 1 + print(e) -print(f"===== Build Summary =====") -print(f"Total: {num_src}") -print(f"Error: {num_src - num_src_error}") + print(f"===== Build Complete =====") + print(f"Total: {num_src}") + print(f"Error: {num_src_error}")