Skip to content

Commit 312ef00

Browse files
authored
Merge branch 'develop' into feature/check_orientations
2 parents 5eedfb7 + 6216bbf commit 312ef00

8 files changed

+41
-10
lines changed

.github/Dockerfiles/C-PAC.develop-jammy.Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /root/.cache/* \
4545
&& chmod 777 $(ls / | grep -v sys | grep -v proc)
4646
ENV PYTHONUSERBASE=/home/c-pac_user/.local
4747
ENV PATH=$PATH:/home/c-pac_user/.local/bin \
48-
PYTHONPATH=$PYTHONPATH:$PYTHONUSERBASE/lib/python3.10/site-packages
48+
PYTHONPATH=$PYTHONPATH:$PYTHONUSERBASE/lib/python3.10/site-packages \
49+
_SHELL=/bin/bash
4950

5051
# set user
5152
WORKDIR /home/c-pac_user

.github/Dockerfiles/C-PAC.develop-lite-jammy.Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /root/.cache/* \
4646
&& chmod 777 $(ls / | grep -v sys | grep -v proc)
4747
ENV PYTHONUSERBASE=/home/c-pac_user/.local
4848
ENV PATH=$PATH:/home/c-pac_user/.local/bin \
49-
PYTHONPATH=$PYTHONPATH:$PYTHONUSERBASE/lib/python3.10/site-packages
49+
PYTHONPATH=$PYTHONPATH:$PYTHONUSERBASE/lib/python3.10/site-packages \
50+
_SHELL=/bin/bash
5051

5152
# set user
5253
WORKDIR /home/c-pac_user

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3535

3636
- A bug in which AWS S3 encryption was looked for in Nipype config instead of pipeline config (only affected uploading logs).
3737
- Restored `bids-validator` functionality.
38+
- Fixed empty `shell` variable in cluster run scripts.
3839
- A bug in which bandpass filters always assumed 1D regressor files have exactly 5 header rows.
3940

4041
### Removed

CPAC/pipeline/cpac_runner.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
# You should have received a copy of the GNU Lesser General Public
1616
# License along with C-PAC. If not, see <https://www.gnu.org/licenses/>.
17+
"""Run C-PAC."""
18+
1719
from multiprocessing import Process
1820
import os
1921
from time import strftime
@@ -23,6 +25,7 @@
2325
import yaml
2426

2527
from CPAC.longitudinal_pipeline.longitudinal_workflow import anat_longitudinal_wf
28+
from CPAC.pipeline.utils import get_shell
2629
from CPAC.utils.configuration import check_pname, Configuration, set_subject
2730
from CPAC.utils.configuration.yaml_template import upgrade_pipeline_to_1_8
2831
from CPAC.utils.ga import track_run
@@ -100,10 +103,7 @@ def run_condor_jobs(c, config_file, subject_list_file, p_name):
100103

101104
# Create and run script for CPAC to run on cluster
102105
def run_cpac_on_cluster(config_file, subject_list_file, cluster_files_dir):
103-
"""
104-
Function to build a SLURM batch job submission script and
105-
submit it to the scheduler via 'sbatch'.
106-
"""
106+
"""Build a batch job submission script and submit to the scheduler."""
107107
# Import packages
108108
import getpass
109109
import re
@@ -137,7 +137,6 @@ def run_cpac_on_cluster(config_file, subject_list_file, cluster_files_dir):
137137
time_limit = "%d:00:00" % hrs_limit
138138

139139
# Batch file variables
140-
shell = subprocess.getoutput("echo $SHELL")
141140
user_account = getpass.getuser()
142141
num_subs = len(sublist)
143142

@@ -174,7 +173,7 @@ def run_cpac_on_cluster(config_file, subject_list_file, cluster_files_dir):
174173
# Set up config dictionary
175174
config_dict = {
176175
"timestamp": timestamp,
177-
"shell": shell,
176+
"shell": get_shell(),
178177
"job_name": "CPAC_" + pipeline_config.pipeline_setup["pipeline_name"],
179178
"num_tasks": num_subs,
180179
"queue": pipeline_config.pipeline_setup["system_config"]["on_grid"]["SGE"][

CPAC/pipeline/test/test_cpac_runner.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
import os
2+
from pathlib import Path
23

34
import pkg_resources as p
45
import pytest
56

67
from CPAC.pipeline.cpac_pipeline import load_cpac_pipe_config
78
from CPAC.pipeline.cpac_runner import run_T1w_longitudinal
9+
from CPAC.pipeline.utils import get_shell
810
from CPAC.utils.bids_utils import create_cpac_data_config
911

1012

13+
def test_shell() -> None:
14+
"""Test that ``get_shell`` returns a path to an executable BASH."""
15+
shell: str = get_shell()
16+
assert shell.lower().endswith("bash"), "Default shell isn't BASH?"
17+
assert Path(shell).exists(), "No default shell found."
18+
assert os.access(shell, os.X_OK), "Default shell not executable."
19+
20+
1121
@pytest.mark.skip(reason="not a pytest test")
1222
def test_run_T1w_longitudinal(bids_dir, cfg, test_dir, part_id):
1323
sub_data_list = create_cpac_data_config(

CPAC/pipeline/utils.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,30 @@
1717
"""C-PAC pipeline engine utilities."""
1818

1919
from itertools import chain
20+
import os
21+
import subprocess
22+
from typing import Optional
2023

2124
from CPAC.func_preproc.func_motion import motion_estimate_filter
2225
from CPAC.utils.bids_utils import insert_entity
2326

2427
MOVEMENT_FILTER_KEYS = motion_estimate_filter.outputs
2528

2629

30+
def get_shell() -> str:
31+
"""Return the path to default shell."""
32+
shell: Optional[str] = subprocess.getoutput(
33+
f"which $(ps -p {os.getppid()} -o comm=)"
34+
)
35+
if not shell:
36+
try:
37+
shell = os.environ["_SHELL"]
38+
except KeyError:
39+
msg = "Shell command not found."
40+
raise EnvironmentError(msg)
41+
return shell
42+
43+
2744
def name_fork(resource_idx, cfg, json_info, out_dct):
2845
"""Create and insert entities for forkpoints.
2946

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /root/.cache/* \
4545
&& chmod 777 $(ls / | grep -v sys | grep -v proc)
4646
ENV PYTHONUSERBASE=/home/c-pac_user/.local
4747
ENV PATH=$PATH:/home/c-pac_user/.local/bin \
48-
PYTHONPATH=$PYTHONPATH:$PYTHONUSERBASE/lib/python3.10/site-packages
48+
PYTHONPATH=$PYTHONPATH:$PYTHONUSERBASE/lib/python3.10/site-packages \
49+
_SHELL=/bin/bash
4950

5051
# set user
5152
WORKDIR /home/c-pac_user

variant-lite.Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /root/.cache/* \
4646
&& chmod 777 $(ls / | grep -v sys | grep -v proc)
4747
ENV PYTHONUSERBASE=/home/c-pac_user/.local
4848
ENV PATH=$PATH:/home/c-pac_user/.local/bin \
49-
PYTHONPATH=$PYTHONPATH:$PYTHONUSERBASE/lib/python3.10/site-packages
49+
PYTHONPATH=$PYTHONPATH:$PYTHONUSERBASE/lib/python3.10/site-packages \
50+
_SHELL=/bin/bash
5051

5152
# set user
5253
WORKDIR /home/c-pac_user

0 commit comments

Comments
 (0)