From 3f74933c7ffe7b9282ce33834abbe8bac3c09e83 Mon Sep 17 00:00:00 2001 From: sschulz92 Date: Mon, 1 Sep 2025 13:43:47 +0200 Subject: [PATCH] Decouple build steps to be more flexible Signed-off-by: sschulz92 --- build.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/build.py b/build.py index befca3a..29f4205 100644 --- a/build.py +++ b/build.py @@ -38,9 +38,11 @@ def install(): call(install_cmd) sys.exit(exit_code) + def in_venv(): return sys.prefix != sys.base_prefix + def create_setup_file(): with open("setup.tmpl", "r", encoding="utf-8") as tmpl: tmpl_content = tmpl.read() @@ -98,8 +100,10 @@ def copy(src, dest): usage = """ Usage: python build.py --[option] +Example: python build.py --test --install Options: + --dist : creates the distributable. --test : runs unit tests. --install : installs python plugin and generates the pip package """ @@ -112,26 +116,31 @@ def run_tests() -> int: all_python_test_files = glob.glob(f"{ROOT_DIR}/tests/**/test_*.py", recursive=True) for i, file_name_path in enumerate(all_python_test_files): command = ["coverage", "run", file_name_path] - exit_code = call(command) if exit_code == 0 else exit_code + + exit_code = call(command) + if exit_code != 0: + break + # Keep coverage files os.rename(".coverage", f".coverage.{i}") + call(["coverage", "combine"]) return exit_code def main(): - if len(sys.argv) < 2: + if len(sys.argv) < 2 or '--help' in sys.argv: print(usage) else: - if sys.argv[1] == '--dist': - create_zip() - generate_package() - else: + if '--test' in sys.argv: exit_code = run_tests() if exit_code != 0: sys.exit(exit_code) - elif sys.argv[1] == '--install': - install() + if '--dist' in sys.argv: + create_zip() + generate_package() + if '--install' in sys.argv: + install() if __name__ == '__main__':