From bbd9a406e72d13404b3c8595499abaa31857d9ae Mon Sep 17 00:00:00 2001 From: Ganesh Kathiresan Date: Wed, 11 Feb 2026 10:44:54 +0530 Subject: [PATCH 1/2] ENH: Added `-j auto` for `build` cmd --- spin/cmds/meson.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/spin/cmds/meson.py b/spin/cmds/meson.py index ca47801..bd37285 100644 --- a/spin/cmds/meson.py +++ b/spin/cmds/meson.py @@ -252,8 +252,7 @@ def _check_coverage_tool_installation(coverage_type: GcovReportFormat, build_dir "-j", "--jobs", metavar="N_JOBS", - help="Number of parallel tasks to launch", - type=int, + help="Number of parallel tasks to launch. Can be set to `auto` to use all cores.", ) @click.option("--clean", is_flag=True, help="Clean build directory before build") @click.option( @@ -364,9 +363,24 @@ def build( # Any other conditions that warrant a reconfigure? + if jobs is not None: + if jobs == "auto": + jobs = str(os.cpu_count() or 1) + else: + try: + jobs = str(int(jobs)) + except ValueError as err: + raise click.BadParameter( + f"Expected an integer or 'auto', got '{jobs}'", param_hint="'-j'" + ) from err + compile_flags = ["-v"] if verbose else [] if jobs: - compile_flags += ["-j", str(jobs)] + if not quiet: + click.secho( + f"Building with {jobs} parallel jobs", bold=True, fg="bright_blue" + ) + compile_flags += ["-j", jobs] p = _run( _meson_cli() From 4527b4f5179a5900d7a183bb09c55b56076ce122 Mon Sep 17 00:00:00 2001 From: Ganesh Kathiresan Date: Wed, 11 Feb 2026 11:04:53 +0530 Subject: [PATCH 2/2] TST: Tests for `build -j auto` --- spin/tests/test_build_cmds.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/spin/tests/test_build_cmds.py b/spin/tests/test_build_cmds.py index a966346..e3148c1 100644 --- a/spin/tests/test_build_cmds.py +++ b/spin/tests/test_build_cmds.py @@ -36,6 +36,20 @@ def test_debug_builds(example_pkg): assert len(list(debug_files)) != 0, "debug files not generated for gcov build" +def test_build_jobs_auto(example_pkg): + """Does `spin build -j auto` work?""" + p = spin("build", "-j", "auto") + assert b"Building with" in p.stdout + assert b"parallel jobs" in p.stdout + + +def test_build_jobs_invalid(example_pkg): + """Does `spin build -j nan` fail with a clear error?""" + p = spin("build", "-j", "nan", sys_exit=False) + assert p.returncode != 0 + assert b"Expected an integer or 'auto'" in p.stderr + + def test_prefix_builds(example_pkg): """does spin build --prefix create a build-install directory with the correct structure?""" spin("build", "--prefix=/foobar/")