Skip to content

Commit dd1db09

Browse files
authored
Merge pull request #31 from marcobarilari/marco_fix-#30_uninit-env
fix #30 - enh `initEnv` to also remove form the path cpp-ptb cpp-bids and the experiment sub folders
2 parents 423b2f6 + d031633 commit dd1db09

File tree

4 files changed

+64
-24
lines changed

4 files changed

+64
-24
lines changed

initEnv.m

Lines changed: 59 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,45 @@
1-
%
2-
% 1 - Check if version requirements
3-
% are satisfied and the packages are
4-
% are installed/loaded:
5-
% Octave > 4
6-
% - image
7-
% - optim
8-
% - struct
9-
% - statistics
10-
%
11-
% MATLAB >= R2015b
12-
%
13-
% 2 - Add project to the O/M path
14-
15-
function initEnv
1+
function initEnv(varargin)
2+
%
3+
% 1 - Check if version requirements are satisfied and the packages are are installed/loaded:
4+
% Octave > 4
5+
% - image
6+
% - optim
7+
% - struct
8+
% - statistics
9+
%
10+
% MATLAB >= R2015b
11+
%
12+
% 2 - Add project to the O/M path
13+
%
14+
% USAGE::
15+
%
16+
% initEnv
17+
% initEnv('init')
18+
% initEnv('uninit')
19+
%
20+
% :param action:
21+
% :type action: string
22+
%
23+
% :returns: - :action: (type) (dimension)
24+
%
25+
% Example::
26+
%
27+
28+
% (C) Copyright 2022 CPP_BIDS developers
29+
30+
p = inputParser;
31+
32+
defaultAction = 'init';
33+
34+
addOptional(p, 'action', defaultAction, @ischar);
35+
% addParameter(p, 'verbose', true);
36+
37+
parse(p, varargin{:});
38+
39+
action = p.Results.action;
40+
% verbose = p.Results.verbose;
41+
42+
% Check Matlab and Octave version
1643

1744
octaveVersion = '4.0.3';
1845
matlabVersion = '8.6.0';
@@ -59,7 +86,7 @@
5986
'Try this in your terminal:', ...
6087
' git submodule update --recursive ']);
6188
else
62-
addDependencies();
89+
addDependencies(action);
6390
end
6491

6592
disp('Correct matlab/octave versions and added to the path!');
@@ -96,13 +123,24 @@ function tryInstallFromForge(packageName)
96123

97124
end
98125

99-
function addDependencies()
126+
function addDependencies(action)
100127

101128
pth = fileparts(mfilename('fullpath'));
102-
addpath(fullfile(pth, 'lib', 'CPP_BIDS'));
103-
addpath(genpath(fullfile(pth, 'lib', 'CPP_PTB', 'src')));
104-
addpath(fullfile(pth, 'subfun'));
105129

106-
checkCppBidsDependencies();
130+
switch lower(action)
131+
132+
case 'init'
133+
134+
run(fullfile(pth, 'lib', 'CPP_PTB', 'cpp_ptb'));
135+
run(fullfile(pth, 'lib', 'CPP_BIDS', 'cpp_bids'));
136+
addpath(genpath(fullfile(pth, 'src')));
137+
138+
case 'uninit'
139+
140+
cpp_ptb('uninit');
141+
cpp_bids('uninit');
142+
rmpath(genpath(fullfile(pth, 'src')));
143+
144+
end
107145

108146
end

lib/CPP_PTB

mainScript.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
end
1212

1313
% make sure we got access to all the required functions and inputs
14-
initEnv();
14+
initEnv('init');
1515

1616
% set and load all the parameters to run the experiment
1717
cfg = setParameters;
@@ -125,6 +125,8 @@
125125

126126
cleanUp();
127127

128+
initEnv('uninit');
129+
128130
catch
129131

130132
cleanUp();

0 commit comments

Comments
 (0)