Skip to content

Commit

Permalink
add -j -1 option to use all cores, closes #8
Browse files Browse the repository at this point in the history
  • Loading branch information
perrygeo committed Apr 18, 2016
1 parent bb41010 commit 74591a4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
8 changes: 7 additions & 1 deletion rio_color/scripts/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@click.command('color')
@click.option('--jobs', '-j', type=int, default=1,
help="Number of jobs to run simultaneously, default: 1")
help="Number of jobs to run simultaneously, Use -1 for all cores, default: 1")
@click.option('--out-dtype', '-d', type=click.Choice(['uint8', 'uint16']),
help="Integer data type for output data, default: same as input")
@click.argument('src_path', type=click.Path(exists=True))
Expand Down Expand Up @@ -73,6 +73,12 @@ def color(ctx, jobs, out_dtype, src_path, dst_path, operations):
'out_dtype': out_dtype
}

if jobs == 0:
raise click.UsageError("Jobs must be >= 1 or == -1")
elif jobs < 0:
import multiprocessing
jobs = multiprocessing.cpu_count()

if jobs > 1:
with riomucho.RioMucho(
[src_path],
Expand Down
15 changes: 15 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,18 @@ def test_bad_op(tmpdir):
assert result.exit_code == 2
assert "foob is not a valid operation" in result.output
assert not os.path.exists(output)


def test_color_jobsn1(tmpdir):
output = str(tmpdir.join('colorj1.tif'))
runner = CliRunner()
result = runner.invoke(
color,
[
'-d', 'uint8',
'-j', '-1',
'tests/rgb8.tif',
output,
"gamma 1,2,3 1.85"])
assert result.exit_code == 0
assert os.path.exists(output)

0 comments on commit 74591a4

Please sign in to comment.