Skip to content

Commit c567c8b

Browse files
authored
Merge pull request #1341 from catalystneuro/expose_number_of_jobs_to_organize
Expose number of jobs to organize
2 parents e99ee62 + 579d108 commit c567c8b

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

dandi/cli/cmd_organize.py

+3
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
),
6060
)
6161
@click.argument("paths", nargs=-1, type=click.Path(exists=True))
62+
@click.option("-J", "--jobs", type=int, help="Number of jobs during organization")
6263
@devel_debug_option()
6364
@map_to_click_exceptions
6465
def organize(
@@ -70,6 +71,7 @@ def organize(
7071
devel_debug=False,
7172
update_external_file_paths=False,
7273
media_files_mode=None,
74+
jobs=None,
7375
):
7476
"""(Re)organize files according to the metadata.
7577
@@ -115,4 +117,5 @@ def organize(
115117
update_external_file_paths=update_external_file_paths,
116118
media_files_mode=media_files_mode,
117119
required_fields=required_fields,
120+
jobs=jobs,
118121
)

dandi/organize.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -721,8 +721,10 @@ def organize(
721721
update_external_file_paths=False,
722722
media_files_mode=None,
723723
required_fields=None,
724+
jobs=None,
724725
):
725726
in_place = False # If we deduce that we are organizing in-place
727+
jobs = jobs or -1
726728

727729
# will come handy when dry becomes proper separate option
728730
def dry_print(msg):
@@ -812,12 +814,12 @@ def _get_metadata(path):
812814
meta["path"] = path
813815
return meta
814816

815-
if not devel_debug:
817+
if not devel_debug and jobs != 1: # Do not use joblib at all if number_of_jobs=1
816818
# Note: It is Python (pynwb) intensive, not IO, so ATM there is little
817819
# to no benefit from Parallel without using multiproc! But that would
818820
# complicate progress bar indication... TODO
819821
metadata = list(
820-
Parallel(n_jobs=-1, verbose=10)(
822+
Parallel(n_jobs=jobs, verbose=10)(
821823
delayed(_get_metadata)(path) for path in paths
822824
)
823825
)

dandi/tests/test_organize.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ def c() -> Any: # shortcut
110110

111111
@pytest.mark.integration
112112
@pytest.mark.parametrize("mode", no_move_modes)
113-
def test_organize_nwb_test_data(nwb_test_data: Path, tmp_path: Path, mode: str) -> None:
113+
@pytest.mark.parametrize("jobs", (1, -1))
114+
def test_organize_nwb_test_data(nwb_test_data: Path, tmp_path: Path, mode: str, jobs: int) -> None:
114115
outdir = tmp_path / "organized"
115116

116117
relative = False
@@ -152,7 +153,7 @@ def test_organize_nwb_test_data(nwb_test_data: Path, tmp_path: Path, mode: str)
152153

153154
input_files = nwb_test_data / "v2.0.1"
154155

155-
cmd = ["-d", str(outdir), "--files-mode", mode, str(input_files)]
156+
cmd = ["-d", str(outdir), "--files-mode", mode, str(input_files), "--jobs", str(jobs)]
156157
r = CliRunner().invoke(organize, cmd)
157158

158159
# with @map_to_click_exceptions we loose original str of message somehow

0 commit comments

Comments
 (0)