Skip to content

Commit e05269a

Browse files
authored
Improve build script: Add error handling and DRY cleanup (#688)
1 parent 4ad15bc commit e05269a

File tree

4 files changed

+59
-38
lines changed

4 files changed

+59
-38
lines changed

pydatastructs/trees/binary_trees.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
from pydatastructs.miscellaneous_data_structures import Stack
55
from pydatastructs.linear_data_structures import OneDimensionalArray
66
from pydatastructs.linear_data_structures.arrays import ArrayForTrees
7-
from pydatastructs.utils.misc_util import (
8-
Backend, raise_if_backend_is_not_python)
7+
from pydatastructs.utils.misc_util import Backend
98
from pydatastructs.trees._backend.cpp import _trees
109

1110
__all__ = [

pydatastructs/utils/testing_util.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
try:
2-
import pytest
3-
except ImportError:
4-
raise Exception("pytest must be installed. Use `pip install pytest` "
5-
"to install it.")
6-
71
import os
82
import pathlib
93
import glob
@@ -30,6 +24,12 @@ def test(submodules=None, only_benchmarks=False,
3024
List of submodules test to run. By default runs
3125
all the tests
3226
"""
27+
try:
28+
import pytest
29+
except ImportError:
30+
raise Exception("pytest must be installed. Use `pip install pytest` "
31+
"to install it.")
32+
3333
# set benchmarks size
3434
os.environ["PYDATASTRUCTS_BENCHMARK_SIZE"] = str(benchmarks_size)
3535
test_files = []
@@ -53,7 +53,7 @@ def test(submodules=None, only_benchmarks=False,
5353
raise Exception("Submodule should be of type: str or module")
5454
if sub in path:
5555
if not only_benchmarks:
56-
if not 'benchmarks' in path:
56+
if 'benchmarks' not in path:
5757
test_files.append(path)
5858
else:
5959
if 'benchmarks' in path:
@@ -69,14 +69,14 @@ def test(submodules=None, only_benchmarks=False,
6969
if skip_test:
7070
continue
7171
if not only_benchmarks:
72-
if not 'benchmarks' in path:
72+
if 'benchmarks' not in path:
7373
test_files.append(path)
7474
else:
7575
if 'benchmarks' in path:
7676
test_files.append(path)
7777

7878
extra_args = []
79-
if not kwargs.get("n", False) is False:
79+
if kwargs.get("n", False) is not False:
8080
extra_args.append("-n")
8181
extra_args.append(str(kwargs["n"]))
8282

scripts/build/develop.py

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
1-
import os, argparse
1+
import argparse
2+
import subprocess
3+
import sys
24

3-
parser = argparse.ArgumentParser(description='Process build options.')
4-
parser.add_argument('--clean', type=bool, default=False,
5-
help='Execute `git clean -fdx` (default 0)')
5+
def run_cmd(cmd):
6+
print(f"Running: {cmd}")
7+
result = subprocess.run(cmd, shell=True)
8+
if result.returncode != 0:
9+
print(f"Command failed: {cmd}", file=sys.stderr)
10+
sys.exit(result.returncode)
611

7-
build_options = parser.parse_args()
12+
if __name__ == "__main__":
13+
parser = argparse.ArgumentParser(description='Process build options.')
14+
parser.add_argument('--clean', action='store_true',
15+
help='Execute `git clean -fdx`')
16+
args = parser.parse_args()
817

9-
if build_options.clean:
10-
response = input("Warning: Executing `git clean -fdx` [Y/N]: ")
11-
if response.lower() in ("y", "yes"):
12-
os.system("git clean -fdx")
18+
if args.clean:
19+
response = input("Warning: Executing `git clean -fdx` [Y/N]: ")
20+
if response.lower() in ("y", "yes"):
21+
run_cmd("git clean -fdx")
22+
else:
23+
print("Skipping clean step.")
1324

14-
os.system("python scripts/build/add_dummy_submodules.py")
15-
os.system("pip install -e . --verbose")
16-
os.system("python scripts/build/delete_dummy_submodules.py")
17-
os.system("pip install -e . --verbose --force-reinstall")
25+
run_cmd("python scripts/build/add_dummy_submodules.py")
26+
run_cmd("pip install -e . --verbose")
27+
run_cmd("python scripts/build/delete_dummy_submodules.py")
28+
run_cmd("pip install -e . --verbose --force-reinstall")

scripts/build/install.py

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
1-
import os, argparse
1+
import os
2+
import argparse
3+
import subprocess
4+
import sys
25

3-
parser = argparse.ArgumentParser(description='Process build options.')
4-
parser.add_argument('--clean', type=bool, default=False,
5-
help='Execute `git clean -fdx` (default 0)')
6+
def run_cmd(cmd):
7+
print(f"Running: {cmd}")
8+
result = subprocess.run(cmd, shell=True)
9+
if result.returncode != 0:
10+
print(f"Command failed: {cmd}", file=sys.stderr)
11+
sys.exit(result.returncode)
612

7-
build_options = parser.parse_args()
13+
if __name__ == "__main__":
14+
parser = argparse.ArgumentParser(description="Build and install pydatastructs.")
15+
parser.add_argument("--clean", action="store_true", help="Execute `git clean -fdx`")
16+
args = parser.parse_args()
817

9-
if build_options.clean:
10-
response = input("Warning: Executing `git clean -fdx` [Y/N]: ")
11-
if response.lower() in ("y", "yes"):
12-
os.system("git clean -fdx")
18+
if args.clean:
19+
response = input("Warning: Executing `git clean -fdx` [Y/N]: ")
20+
if response.lower() in ("y", "yes"):
21+
run_cmd("git clean -fdx")
22+
else:
23+
print("Skipping clean step.")
1324

14-
os.system("python scripts/build/add_dummy_submodules.py")
15-
os.system("python setup.py build_ext --inplace")
16-
os.system("pip install .")
17-
os.system("python scripts/build/delete_dummy_submodules.py")
18-
os.system("pip install . --force-reinstall")
25+
run_cmd("python scripts/build/add_dummy_submodules.py")
26+
run_cmd("python setup.py build_ext --inplace")
27+
run_cmd("python -m pip install .")
28+
run_cmd("python scripts/build/delete_dummy_submodules.py")
29+
run_cmd("python -m pip install . --force-reinstall")

0 commit comments

Comments
 (0)