Skip to content

Commit 4b83bc4

Browse files
committed
raise RuntimeError from scripts with invalid arguments
slips in changes to `clean_build_dir`
1 parent f3eb33a commit 4b83bc4

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

scripts/_build_helper.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def capture_cmd_output(cmd: list[str], cwd: str = None):
7979

8080

8181
def err(msg: str, script: str):
82-
print(f"[{script}][error] {msg}", file=sys.stderr)
82+
raise RuntimeError(f"[{script}] error: {msg}")
8383

8484

8585
def log_cmake_args(cmake_args: list[str], script: str):
@@ -150,8 +150,18 @@ def install_editable(setup_dir: str, env: dict[str, str]):
150150
)
151151

152152

153-
def clean_build_dir(setup_dir: str = None):
154-
target = os.path.join(setup_dir or os.getcwd(), "_skbuild")
153+
def clean_build_dir(setup_dir: str):
154+
if (
155+
not isinstance(setup_dir, str)
156+
or not setup_dir
157+
or not os.path.isdir(setup_dir)
158+
):
159+
raise RuntimeError(f"Invalid setup directory provided: '{setup_dir}'")
160+
target = os.path.join(setup_dir, "_skbuild")
155161
if os.path.exists(target):
156162
print(f"Cleaning build directory: {target}")
157-
shutil.rmtree(target)
163+
try:
164+
shutil.rmtree(target)
165+
except Exception as e:
166+
print(f"Failed to remove build directory '{target}'")
167+
raise e

0 commit comments

Comments
 (0)