Skip to content

Commit

Permalink
run nipype.spm path init from a temp dir in order to avoid writing py…
Browse files Browse the repository at this point in the history
…script.m file in the current directory

Fixes: #175
Could also be a solution for populse/mia_processes#52
  • Loading branch information
denisri committed Oct 6, 2023
1 parent a139c8a commit e64de08
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions capsul/in_context/nipype.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import print_function

import os
import os.path as osp
import tempfile


def configure_all():
Expand Down Expand Up @@ -34,9 +33,16 @@ def configure_spm():
from nipype.interfaces import spm

spm_cmd = spmc.spm_command(None)
spm.SPMCommand.set_mlab_paths(
matlab_cmd=' '.join(spm_cmd + ['script']),
use_mcr=True)
# set_mlab_paths() writes a file "pyscript.m" in the current directory.
# This is bad but we cannot do anything about it. So let's run it
# from a temp directory.
cwd = os.getcwd()
with tempfile.TemporaryDirectory() as tmpdir:
os.chdir(tmpdir)
spm.SPMCommand.set_mlab_paths(
matlab_cmd=' '.join(spm_cmd + ['script']),
use_mcr=True)
os.chdir(cwd)

else:
# Matlab spm version
Expand All @@ -48,9 +54,17 @@ def configure_spm():
from nipype.interfaces import matlab
from nipype.interfaces import spm

matlab.MatlabCommand.set_default_paths(
[spm_directory]) # + add_to_default_matlab_path)
spm.SPMCommand.set_mlab_paths(matlab_cmd="", use_mcr=False)
# set_mlab_paths() writes a file "pyscript.m" in the current
# directory.
# This is bad but we cannot do anything about it. So let's run it
# from a temp directory.
cwd = os.getcwd()
with tempfile.TemporaryDirectory() as tmpdir:
os.chdir(tmpdir)
matlab.MatlabCommand.set_default_paths(
[spm_directory]) # + add_to_default_matlab_path)
spm.SPMCommand.set_mlab_paths(matlab_cmd="", use_mcr=False)
os.chdir(cwd)


def configure_matlab():
Expand Down

0 comments on commit e64de08

Please sign in to comment.