From 110a2dc92de715cea4f635474eed19d2259ad967 Mon Sep 17 00:00:00 2001 From: Toon Verstraelen Date: Sat, 24 Aug 2024 14:24:39 +0200 Subject: [PATCH] Stop earlier when there is not plan.py (do not create .stepup/) --- stepup/core/tui.py | 15 +++++++++++---- tests/cases/no_plan/expected_stdout.txt | 12 ------------ 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/stepup/core/tui.py b/stepup/core/tui.py index 574e12fd..e813d4cd 100644 --- a/stepup/core/tui.py +++ b/stepup/core/tui.py @@ -45,9 +45,13 @@ def main(): async def async_main(): args = parse_args() - if Path(args.root).absolute() != Path.cwd(): + if args.root.absolute() != Path.cwd(): print("Changing to", args.root) - os.chdir(args.root) + args.root.cd() + + # Sanity check before creating a subdirectory + if not args.plan_py.is_file(): + raise RuntimeError(f"File {args.plan_py} does not exist.") # Create dir dir_stepup = Path(".stepup") @@ -207,10 +211,13 @@ async def keyboard( def parse_args(): """Parse command-line arguments.""" parser = argparse.ArgumentParser(prog="stepup", description="The StepUp build tool") - parser.add_argument("plan_py", default="plan.py", help="Top-level build script", nargs="?") + parser.add_argument( + "plan_py", type=Path, default=Path("plan.py"), help="Top-level build script", nargs="?" + ) parser.add_argument( "--root", - default=os.getenv("STEPUP_ROOT", os.getcwd()), + type=Path, + default=Path(os.getenv("STEPUP_ROOT", os.getcwd())), help="Directory containing top-level plan.py [default=%(default)s]", ) parser.add_argument( diff --git a/tests/cases/no_plan/expected_stdout.txt b/tests/cases/no_plan/expected_stdout.txt index be4a0a4b..e69de29b 100644 --- a/tests/cases/no_plan/expected_stdout.txt +++ b/tests/cases/no_plan/expected_stdout.txt @@ -1,12 +0,0 @@ - ERROR │ The director raised an exception. -────────────────────────────────── Traceback ─────────────────────────────────── -Traceback (most recent call last): - File "${PWD}/stepup/core/director.py", line ---, in async_main - await serve( - File "${PWD}/stepup/core/director.py", line ---, in serve - check_plan(path_plan) - File "${PWD}/stepup/core/utils.py", line ---, in check_plan - raise ValueError(f"Is not a file: {path_plan}") -ValueError: Is not a file: plan.py -──────────────────────────────────────────────────────────────────────────────── - DIRECTOR │ See you!