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..86d4027a7 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..90a7ee48d 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")