From 5319e34ad3f5d4434f0c75452451bf31b9751b7c Mon Sep 17 00:00:00 2001 From: Gagandeep Singh Date: Sat, 26 Jul 2025 17:45:35 +0530 Subject: [PATCH 1/2] CI: Fix build scripts --- pydatastructs/trees/binary_trees.py | 3 +-- pydatastructs/utils/testing_util.py | 18 ++++++------- scripts/build/develop.py | 37 +++++++++++++++++---------- scripts/build/install.py | 39 ++++++++++++++++++----------- 4 files changed, 59 insertions(+), 38 deletions(-) diff --git a/pydatastructs/trees/binary_trees.py b/pydatastructs/trees/binary_trees.py index 4dc1fc3c8..48446d1d4 100644 --- a/pydatastructs/trees/binary_trees.py +++ b/pydatastructs/trees/binary_trees.py @@ -4,8 +4,7 @@ from pydatastructs.miscellaneous_data_structures import Stack from pydatastructs.linear_data_structures import OneDimensionalArray from pydatastructs.linear_data_structures.arrays import ArrayForTrees -from pydatastructs.utils.misc_util import ( - Backend, raise_if_backend_is_not_python) +from pydatastructs.utils.misc_util import Backend from pydatastructs.trees._backend.cpp import _trees __all__ = [ diff --git a/pydatastructs/utils/testing_util.py b/pydatastructs/utils/testing_util.py index 6024912ba..e5c0627b5 100644 --- a/pydatastructs/utils/testing_util.py +++ b/pydatastructs/utils/testing_util.py @@ -1,9 +1,3 @@ -try: - import pytest -except ImportError: - raise Exception("pytest must be installed. Use `pip install pytest` " - "to install it.") - import os import pathlib import glob @@ -30,6 +24,12 @@ def test(submodules=None, only_benchmarks=False, List of submodules test to run. By default runs all the tests """ + try: + import pytest + except ImportError: + raise Exception("pytest must be installed. Use `pip install pytest` " + "to install it.") + # set benchmarks size os.environ["PYDATASTRUCTS_BENCHMARK_SIZE"] = str(benchmarks_size) test_files = [] @@ -53,7 +53,7 @@ def test(submodules=None, only_benchmarks=False, raise Exception("Submodule should be of type: str or module") if sub in path: if not only_benchmarks: - if not 'benchmarks' in path: + if 'benchmarks' not in path: test_files.append(path) else: if 'benchmarks' in path: @@ -69,14 +69,14 @@ def test(submodules=None, only_benchmarks=False, if skip_test: continue if not only_benchmarks: - if not 'benchmarks' in path: + if 'benchmarks' not in path: test_files.append(path) else: if 'benchmarks' in path: test_files.append(path) extra_args = [] - if not kwargs.get("n", False) is False: + if kwargs.get("n", False) is not False: extra_args.append("-n") extra_args.append(str(kwargs["n"])) diff --git a/scripts/build/develop.py b/scripts/build/develop.py index 75665829b..c50992330 100644 --- a/scripts/build/develop.py +++ b/scripts/build/develop.py @@ -1,17 +1,28 @@ -import os, argparse +import argparse +import subprocess +import sys -parser = argparse.ArgumentParser(description='Process build options.') -parser.add_argument('--clean', type=bool, default=False, - help='Execute `git clean -fdx` (default 0)') +def run_cmd(cmd): + print(f"➡️ Running: {cmd}") + result = subprocess.run(cmd, shell=True) + if result.returncode != 0: + print(f"❌ Command failed: {cmd}", file=sys.stderr) + sys.exit(result.returncode) -build_options = parser.parse_args() +if __name__ == "__main__": + parser = argparse.ArgumentParser(description='Process build options.') + parser.add_argument('--clean', action='store_true', + help='Execute `git clean -fdx`') + args = parser.parse_args() -if build_options.clean: - response = input("Warning: Executing `git clean -fdx` [Y/N]: ") - if response.lower() in ("y", "yes"): - os.system("git clean -fdx") + if args.clean: + response = input("⚠️ Warning: Executing `git clean -fdx` [Y/N]: ") + if response.lower() in ("y", "yes"): + run_cmd("git clean -fdx") + else: + print("ℹ️ Skipping clean step.") -os.system("python scripts/build/add_dummy_submodules.py") -os.system("pip install -e . --verbose") -os.system("python scripts/build/delete_dummy_submodules.py") -os.system("pip install -e . --verbose --force-reinstall") + run_cmd("python scripts/build/add_dummy_submodules.py") + run_cmd("pip install -e . --verbose") + run_cmd("python scripts/build/delete_dummy_submodules.py") + run_cmd("pip install -e . --verbose --force-reinstall") diff --git a/scripts/build/install.py b/scripts/build/install.py index a96c03824..b3cc337f0 100644 --- a/scripts/build/install.py +++ b/scripts/build/install.py @@ -1,18 +1,29 @@ -import os, argparse +import os +import argparse +import subprocess +import sys -parser = argparse.ArgumentParser(description='Process build options.') -parser.add_argument('--clean', type=bool, default=False, - help='Execute `git clean -fdx` (default 0)') +def run_cmd(cmd): + print(f"➡️ Running: {cmd}") + result = subprocess.run(cmd, shell=True) + if result.returncode != 0: + print(f"❌ Command failed: {cmd}", file=sys.stderr) + sys.exit(result.returncode) -build_options = parser.parse_args() +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Build and install pydatastructs.") + parser.add_argument("--clean", action="store_true", help="Execute `git clean -fdx`") + args = parser.parse_args() -if build_options.clean: - response = input("Warning: Executing `git clean -fdx` [Y/N]: ") - if response.lower() in ("y", "yes"): - os.system("git clean -fdx") + if args.clean: + response = input("⚠️ Warning: Executing `git clean -fdx` [Y/N]: ") + if response.lower() in ("y", "yes"): + run_cmd("git clean -fdx") + else: + print("ℹ️ Skipping clean step.") -os.system("python scripts/build/add_dummy_submodules.py") -os.system("python setup.py build_ext --inplace") -os.system("pip install .") -os.system("python scripts/build/delete_dummy_submodules.py") -os.system("pip install . --force-reinstall") + run_cmd("python scripts/build/add_dummy_submodules.py") + run_cmd("python setup.py build_ext --inplace") + run_cmd("python -m pip install .") + run_cmd("python scripts/build/delete_dummy_submodules.py") + run_cmd("python -m pip install . --force-reinstall") From 9cf3b5a1e37cc69711ea693ef2f540161fa92a38 Mon Sep 17 00:00:00 2001 From: Gagandeep Singh Date: Sat, 26 Jul 2025 17:55:18 +0530 Subject: [PATCH 2/2] Remove special character --- scripts/build/develop.py | 8 ++++---- scripts/build/install.py | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/scripts/build/develop.py b/scripts/build/develop.py index c50992330..86d4027a7 100644 --- a/scripts/build/develop.py +++ b/scripts/build/develop.py @@ -3,10 +3,10 @@ import sys def run_cmd(cmd): - print(f"➡️ Running: {cmd}") + print(f"Running: {cmd}") result = subprocess.run(cmd, shell=True) if result.returncode != 0: - print(f"❌ Command failed: {cmd}", file=sys.stderr) + print(f"Command failed: {cmd}", file=sys.stderr) sys.exit(result.returncode) if __name__ == "__main__": @@ -16,11 +16,11 @@ def run_cmd(cmd): args = parser.parse_args() if args.clean: - response = input("⚠️ Warning: Executing `git clean -fdx` [Y/N]: ") + response = input("Warning: Executing `git clean -fdx` [Y/N]: ") if response.lower() in ("y", "yes"): run_cmd("git clean -fdx") else: - print("ℹ️ Skipping clean step.") + print("Skipping clean step.") run_cmd("python scripts/build/add_dummy_submodules.py") run_cmd("pip install -e . --verbose") diff --git a/scripts/build/install.py b/scripts/build/install.py index b3cc337f0..90a7ee48d 100644 --- a/scripts/build/install.py +++ b/scripts/build/install.py @@ -4,10 +4,10 @@ import sys def run_cmd(cmd): - print(f"➡️ Running: {cmd}") + print(f"Running: {cmd}") result = subprocess.run(cmd, shell=True) if result.returncode != 0: - print(f"❌ Command failed: {cmd}", file=sys.stderr) + print(f"Command failed: {cmd}", file=sys.stderr) sys.exit(result.returncode) if __name__ == "__main__": @@ -16,11 +16,11 @@ def run_cmd(cmd): args = parser.parse_args() if args.clean: - response = input("⚠️ Warning: Executing `git clean -fdx` [Y/N]: ") + response = input("Warning: Executing `git clean -fdx` [Y/N]: ") if response.lower() in ("y", "yes"): run_cmd("git clean -fdx") else: - print("ℹ️ Skipping clean step.") + print("Skipping clean step.") run_cmd("python scripts/build/add_dummy_submodules.py") run_cmd("python setup.py build_ext --inplace")