Skip to content

Commit

Permalink
feat: remove use_shell option
Browse files Browse the repository at this point in the history
This PR fixes issue #30
  • Loading branch information
christian-monch authored Nov 23, 2024
2 parents 4a6f8a4 + 61b1611 commit ac5cda0
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 49 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ Create a template and place it in the `.datalad/make/methods` directory:
> cat > .datalad/make/methods/one-to-many <<EOF
parameters = ['first', 'second', 'output']
use_shell = 'true'
command = [
"bash",
"-c",
"echo content: {first} > '{output}-1.txt'; echo content: {second} > '{output}-2.txt'",
]
EOF
Expand Down
40 changes: 21 additions & 19 deletions datalad_remake/annexremotes/tests/test_hierarchies.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,28 @@
create_simple_computation_dataset,
)

test_method = """
parameters = ['first', 'second', 'third']
use_shell = 'true'
command = [
"echo content: {first} > 'a.txt';",
"mkdir -p 'd2_subds0/d2_subds1/d2_subds2';",
"echo content: {second} > 'b.txt';",
"echo content: {third} > 'new.txt';",
"echo content: {first} > 'd2_subds0/a0.txt';",
"echo content: {second} > 'd2_subds0/b0.txt';",
"echo content: {third} > 'd2_subds0/new.txt';",
"echo content: {first} > 'd2_subds0/d2_subds1/a1.txt';",
"echo content: {second} > 'd2_subds0/d2_subds1/b1.txt';",
"echo content: {third} > 'd2_subds0/d2_subds1/new.txt';",
"echo content: {first} > 'd2_subds0/d2_subds1/d2_subds2/a2.txt';",
"echo content: {second} > 'd2_subds0/d2_subds1/d2_subds2/b2.txt';",
"echo content: {third} > 'd2_subds0/d2_subds1/d2_subds2/new.txt';",
]
"""
script = (
"echo content: {first} > 'a.txt';"
"mkdir -p 'd2_subds0/d2_subds1/d2_subds2';"
"echo content: {second} > 'b.txt';"
"echo content: {third} > 'new.txt';"
"echo content: {first} > 'd2_subds0/a0.txt';"
"echo content: {second} > 'd2_subds0/b0.txt';"
"echo content: {third} > 'd2_subds0/new.txt';"
"echo content: {first} > 'd2_subds0/d2_subds1/a1.txt';"
"echo content: {second} > 'd2_subds0/d2_subds1/b1.txt';"
"echo content: {third} > 'd2_subds0/d2_subds1/new.txt';"
"echo content: {first} > 'd2_subds0/d2_subds1/d2_subds2/a2.txt';"
"echo content: {second} > 'd2_subds0/d2_subds1/d2_subds2/b2.txt';"
"echo content: {third} > 'd2_subds0/d2_subds1/d2_subds2/new.txt'"
)

test_method = '\n'.join(
[
"parameters = ['first', 'second', 'third']",
'command = ["bash", "-c", "' + script + '"]',
]
)

output_pattern_static = [
'a.txt',
Expand Down
3 changes: 1 addition & 2 deletions datalad_remake/annexremotes/tests/test_priority.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
# priority code.
template = """
parameters = ['content']
use_shell = 'true'
command = ["echo from {label}: {{content}} > 'a.txt'"]
command = ["bash", "-c", "echo from {label}: {{content}} > 'a.txt'"]
"""


Expand Down
5 changes: 1 addition & 4 deletions datalad_remake/annexremotes/tests/test_remake_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@

template = """
parameters = ['content']
use_shell = 'true'
command = ["echo content: {content} > 'a.txt'"]
command = ["bash", "-c", "echo content: {content} > 'a.txt'"]
"""


Expand Down
3 changes: 1 addition & 2 deletions datalad_remake/commands/tests/test_make.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@

test_method = """
parameters = ['name', 'file']
use_shell = 'true'
command = ["echo Hello {name} > {file}"]
command = ["bash", "-c", "echo Hello {name} > {file}"]
"""

output_pattern = ['a.txt']
Expand Down
11 changes: 3 additions & 8 deletions datalad_remake/tests/test_complex_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,17 @@

template = """
parameters = ['line']
use_shell = 'true'
command = ["echo {line} >> 'a.txt'"]
command = ["bash", "-c", "echo {line} >> 'a.txt'"]
"""

template_c1 = """
parameters = ['line']
use_shell = 'true'
command = ["cat a.txt > c1.txt; echo {line} >> c1.txt"]
command = ["bash", "-c", "cat a.txt > c1.txt; echo {line} >> c1.txt"]
"""

template_c2 = """
parameters = ['line']
use_shell = 'true'
command = ["cat c1.txt > c2.txt; echo {line} >> c2.txt"]
command = ["bash", "-c", "cat c1.txt > c2.txt; echo {line} >> c2.txt"]
"""


Expand Down
9 changes: 2 additions & 7 deletions datalad_remake/utils/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,5 @@ def compute(
substituted_command = substitute_arguments(template, substitutions, 'command')

with chdir(root_directory):
if template.get('use_shell', 'false') == 'true':
cmd = ' '.join(substituted_command)
lgr.debug(f'compute: RUNNING: with shell=True: {cmd}')
subprocess.run(cmd, shell=True, check=True) # noqa: S602
else:
lgr.debug(f'compute: RUNNING: {substituted_command}')
subprocess.run(substituted_command, check=True)
lgr.debug(f'compute: RUNNING: {substituted_command}')
subprocess.run(substituted_command, check=True)
2 changes: 0 additions & 2 deletions examples/fmriprep-docker/fmriprep-docker
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

parameters = ['input_dir', 'output_dir', 'participant_label', 'license_file']

use_shell = 'false'

# Note: `{root_directory}` resolves to the directory of the dataset in which the
# computation was started with `datalad make`.

Expand Down
2 changes: 0 additions & 2 deletions examples/fmriprep-singularity/fmriprep-singularity
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

parameters = ['container', 'input_dir', 'output_dir', 'participant_label', 'license_file']

use_shell = 'false'

# Note: `{root_directory}` resolves to the directory of the dataset in which the
# computation was started with `datalad make`.

Expand Down
4 changes: 2 additions & 2 deletions examples/one-to-many
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

parameters = ['first', 'second', 'output']

use_shell = 'true'

# The command line that should be executed. The curly braces are placeholders
# for the parameters that were defined above. They will be replaced with
# the values provided in the parameter arguments of `datalad make`.
#
command = [
"bash",
"-c",
"echo content: {first} > '{output}-1.txt'; echo content: {second} > '{output}-2.txt'",
]

0 comments on commit ac5cda0

Please sign in to comment.