Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ENH: Added -j auto for build cmd #314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ganesh-k13 wants to merge 2 commits into scientific-python:main
base: main
Choose a base branch
Loading
from ganesh-k13:auto_jobs
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions spin/cmds/meson.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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()
Expand Down
14 changes: 14 additions & 0 deletions spin/tests/test_build_cmds.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -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/")
Expand Down
Loading

AltStyle によって変換されたページ (->オリジナル) /