Skip to content

Commit 2839d31

Browse files
authored
Merge pull request #213 from Remi-Gau/init
[ENH] update initialisation
2 parents 630702a + 2a90d4a commit 2839d31

16 files changed

+306
-123
lines changed

.all-contributorsrc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"contributors": [
88
{
99
"login": "CerenB",
10-
"name": "CerenB",
10+
"name": "Ceren Battal",
1111
"avatar_url": "https://avatars1.githubusercontent.com/u/10451654?v=4",
1212
"profile": "https://github.com/CerenB",
1313
"contributions": [
@@ -21,7 +21,7 @@
2121
},
2222
{
2323
"login": "marcobarilari",
24-
"name": "marcobarilari",
24+
"name": "Marco Barilari",
2525
"avatar_url": "https://avatars3.githubusercontent.com/u/38101692?v=4",
2626
"profile": "https://github.com/marcobarilari",
2727
"contributions": [
@@ -64,7 +64,7 @@
6464
},
6565
{
6666
"login": "iqrashahzad14",
67-
"name": "iqrashahzad14",
67+
"name": "Iqra Shahzad",
6868
"avatar_url": "https://avatars.githubusercontent.com/u/75671348?v=4",
6969
"profile": "https://github.com/iqrashahzad14",
7070
"contributions": [

checkCppBidsDependencies.m

Lines changed: 9 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,16 @@
1-
% (C) Copyright 2020 CPP_BIDS developers
2-
31
function checkCppBidsDependencies(cfg)
4-
%
5-
% Adds dependencies to the Matlab / Octave path and make sure we got all of them.
6-
%
7-
% USAGE::
8-
%
9-
% checkCppBidsDependencies(cfg)
10-
%
11-
% :param cfg: Configuration. See ``checkCFG()``.
12-
% :type cfg: structure
13-
14-
if nargin < 1
15-
cfg.verbose = 2;
16-
end
17-
18-
global CPP_BIDS_INITIALIZED
19-
20-
if isempty(CPP_BIDS_INITIALIZED)
21-
22-
GITHUB_WORKSPACE = getenv('GITHUB_WORKSPACE');
23-
24-
if strcmp(GITHUB_WORKSPACE, '/github/workspace')
25-
26-
pth = GITHUB_WORKSPACE;
27-
addpath(genpath(fullfile(pth, 'lib')));
28-
29-
elseif isempty(GITHUB_WORKSPACE) % local
2+
% (C) Copyright 2020 CPP_BIDS developers
303

31-
pth = fullfile(fileparts(mfilename('fullpath')));
32-
33-
addpath(pth);
34-
35-
checkSubmodule(fullfile(pth, 'lib', 'JSONio'));
36-
checkSubmodule(fullfile(pth, 'lib', 'bids-matlab'));
37-
38-
addpath(genpath(fullfile(pth, 'src')));
39-
40-
end
41-
42-
printCreditsCppBids(cfg);
43-
44-
CPP_BIDS_INITIALIZED = true();
45-
46-
else
47-
if ~isfield(cfg, 'versbose') || cfg.verbose
48-
fprintf(1, '\n\nCPP_BIDS already initialized\n\n');
49-
end
4+
warning(sprintf(['\n\nDEPRECATION WARNING:\n', ...
5+
'"checkCppBidsDependencies" is deprecated ', ...
6+
'and will be removed in a future release.\n', ...
7+
'\nPlease use "cpp_bids(''init'')" instead.'])); %#ok<SPWRN>
508

9+
verbose = false;
10+
if nargin > 0 && ~isempty(cfg) && isfield(cfg, 'verbose') && ~isempty(cfg.verbose)
11+
verbose = cfg.verbose;
5112
end
5213

53-
end
14+
cpp_bids('init', 'verbose', verbose);
5415

55-
function checkSubmodule(pth)
56-
% If external dir is empty throw an exception
57-
% and ask user to update submodules.
58-
if numel(dir(pth)) <= 2 % Means that the external is empty
59-
error(['Git submodules are not cloned!', ...
60-
'Try this in your terminal:', ...
61-
' git submodule update --recursive ']);
62-
else
63-
addpath(pth);
64-
end
6516
end

cpp_bids.m

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
function cpp_bids(varargin)
2+
%
3+
% General intro function for CPP BIDS
4+
%
5+
% USAGE::
6+
%
7+
% cpp_bids
8+
% cpp_bids('init')
9+
% cpp_bids('uninit')
10+
% cpp_bids('dev')
11+
%
12+
% :param action:
13+
% :type action: string
14+
%
15+
% :returns: - :action: (type) (dimension)
16+
%
17+
% Example::
18+
%
19+
% (C) Copyright 2022 CPP_BIDS developers
20+
21+
p = inputParser;
22+
23+
defaultAction = 'init';
24+
25+
addOptional(p, 'action', defaultAction, @ischar);
26+
addParameter(p, 'verbose', true);
27+
28+
parse(p, varargin{:});
29+
30+
action = p.Results.action;
31+
verbose = p.Results.verbose;
32+
33+
switch lower(action)
34+
35+
case 'init'
36+
37+
initCppBids(verbose);
38+
39+
case 'uninit'
40+
41+
uninitCppBids();
42+
43+
case 'run_tests'
44+
45+
runTests();
46+
47+
end
48+
49+
end
50+
51+
function initCppBids(verbose)
52+
%
53+
% Adds the relevant folders to the path for a given session.
54+
% Has to be run to be able to use CPP_BIDS.
55+
%
56+
% USAGE::
57+
%
58+
% initCppPtb()
59+
%
60+
% (C) Copyright 2022 CPP_BIDS developers
61+
62+
thisDirectory = fileparts(mfilename('fullpath'));
63+
64+
global CPP_BIDS_INITIALIZED
65+
global CPP_BIDS_PATHS
66+
67+
if isempty(CPP_BIDS_INITIALIZED)
68+
69+
pathSep = ':';
70+
if ~isunix
71+
pathSep = ';';
72+
end
73+
74+
CPP_BIDS_PATHS = fullfile(thisDirectory);
75+
CPP_BIDS_PATHS = cat(2, CPP_BIDS_PATHS, ...
76+
pathSep, ...
77+
genpath(fullfile(thisDirectory, 'src')));
78+
assert(isdir(fullfile(thisDirectory, 'lib', 'bids-matlab', '+bids')));
79+
CPP_BIDS_PATHS = cat(2, CPP_BIDS_PATHS, pathSep, ...
80+
fullfile(thisDirectory, 'lib', 'bids-matlab'));
81+
assert(isdir(fullfile(thisDirectory, 'lib', 'JSONio')));
82+
CPP_BIDS_PATHS = cat(2, CPP_BIDS_PATHS, pathSep, ...
83+
fullfile(thisDirectory, 'lib', 'JSONio'));
84+
85+
addpath(CPP_BIDS_PATHS, '-begin');
86+
87+
CPP_BIDS_INITIALIZED = true();
88+
89+
detectCppBids();
90+
91+
if verbose
92+
printCreditsCppBids();
93+
end
94+
95+
else
96+
if verbose
97+
fprintf('\n\nCPP_BIDS already initialized\n\n');
98+
end
99+
100+
end
101+
102+
end
103+
104+
function detectCppBids()
105+
106+
workflowsDir = cellstr(which('saveEventsFile.m', '-ALL'));
107+
108+
if isempty(workflowsDir)
109+
error('CPP_BIDS is not in your MATLAB / Octave path.\n');
110+
111+
elseif numel(workflowsDir) > 1
112+
fprintf('CPP_BIDS seems to appear in several different folders:\n');
113+
for i = 1:numel(workflowsDir)
114+
fprintf(' * %s\n', fullfile(workflowsDir{i}, '..', '..'));
115+
end
116+
error('Remove all but one with ''pathtool'' .\n'); % or ''spm_rmpath
117+
118+
end
119+
end
120+
121+
function uninitCppBids()
122+
%
123+
% Removes the added folders from the path for a given session.
124+
%
125+
% USAGE::
126+
%
127+
% uninitCppPtb()
128+
%
129+
% (C) Copyright 2021 CPP_BIDS developers
130+
131+
global CPP_BIDS_INITIALIZED
132+
global CPP_BIDS_PATHS
133+
134+
if isempty(CPP_BIDS_INITIALIZED) || ~CPP_BIDS_INITIALIZED
135+
fprintf('\n\nCPP_BIDS not initialized\n\n');
136+
return
137+
138+
else
139+
rmpath(CPP_BIDS_PATHS);
140+
141+
if isOctave
142+
clear -g;
143+
else
144+
clearvars -GLOBAL;
145+
end
146+
147+
end
148+
149+
end
150+
151+
function retval = isOctave()
152+
%
153+
% Returns true if the environment is Octave.
154+
%
155+
% USAGE::
156+
%
157+
% retval = isOctave()
158+
%
159+
% :returns: :retval: (boolean)
160+
%
161+
% (C) Copyright 2020 Agah Karakuzu
162+
% (C) Copyright 2022 CPP_BIDS developers
163+
164+
persistent cacheval % speeds up repeated calls
165+
166+
if isempty (cacheval)
167+
cacheval = (exist ('OCTAVE_VERSION', 'builtin') > 0);
168+
end
169+
170+
retval = cacheval;
171+
end

docs/source/conf.py

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,19 @@
1212
#
1313
import os
1414
import sys
15-
sys.path.insert(0, os.path.abspath('../..'))
15+
16+
sys.path.insert(0, os.path.abspath("../.."))
1617

1718

1819
# -- Project information -----------------------------------------------------
1920

20-
project = 'CPP BIDS'
21-
copyright = '2020, the CPP BIDS dev team'
22-
author = 'the CPP BIDS dev team'
21+
project = "CPP BIDS"
22+
copyright = "2020, the CPP BIDS dev team"
23+
author = "the CPP BIDS dev team"
2324

2425
# The full version, including alpha/beta/rc tags
25-
release = 'v2.1.2dev'
26+
with open("../../version.txt", encoding="utf-8") as version_file:
27+
release = version_file.read()
2628

2729

2830
# -- General configuration ---------------------------------------------------
@@ -31,42 +33,45 @@
3133
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
3234
# ones.
3335
extensions = [
34-
'sphinxcontrib.matlab',
35-
'sphinx.ext.autodoc']
36-
matlab_src_dir = os.path.dirname(os.path.abspath('../../src'))
37-
primary_domain = 'mat'
36+
"sphinxcontrib.matlab",
37+
"sphinx.ext.autodoc",
38+
"myst_parser",
39+
"sphinx_copybutton",
40+
]
41+
matlab_src_dir = os.path.dirname(os.path.abspath("../../src"))
42+
primary_domain = "mat"
3843

3944
# Add any paths that contain templates here, relative to this directory.
40-
templates_path = ['_templates']
45+
templates_path = ["_templates"]
4146

4247
# List of patterns, relative to source directory, that match files and
4348
# directories to ignore when looking for source files.
4449
# This pattern also affects html_static_path and html_extra_path.
4550
exclude_patterns = []
4651

4752
# The name of the Pygments (syntax highlighting) style to use.
48-
pygments_style = 'sphinx'
53+
pygments_style = "sphinx"
4954

5055
# The master toctree document.
51-
master_doc = 'index'
56+
master_doc = "index"
5257

5358
# source_suffix = ['.rst', '.md']
54-
source_suffix = '.rst'
59+
source_suffix = ".rst"
5560

5661

5762
# -- Options for HTML output -------------------------------------------------
5863

5964
# The theme to use for HTML and HTML Help pages. See the documentation for
6065
# a list of builtin themes.
6166
#
62-
html_theme = 'sphinx_rtd_theme'
67+
html_theme = "sphinx_rtd_theme"
6368

6469
# Add any paths that contain custom static files (such as style sheets) here,
6570
# relative to this directory. They are copied after the builtin static files,
6671
# so a file named "default.css" will overwrite the builtin "default.css".
67-
html_static_path = ['_static']
72+
html_static_path = ["_static"]
6873

69-
html_logo = '_static/cpp_lab_logo.png'
74+
html_logo = "_static/cpp_lab_logo.png"
7075

7176
# html_theme_options = {
7277
# 'github_user': 'cpp-lln-lab',
@@ -81,11 +86,11 @@
8186
# }
8287

8388
html_sidebars = {
84-
'**': [
85-
'about.html',
86-
'navigation.html',
87-
'relations.html', # needs 'show_related': True theme option to display
88-
'searchbox.html',
89-
'donate.html',
89+
"**": [
90+
"about.html",
91+
"navigation.html",
92+
"relations.html", # needs 'show_related': True theme option to display
93+
"searchbox.html",
94+
"donate.html",
9095
]
9196
}

miss_hit.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
project_root
33

44
line_length: 100
5-
regex_function_name: "[a-z]+(([A-Z]){1}[A-Za-z]+)*"
5+
regex_function_name: "[a-z]+(_*[a-zA-Z0-9]+[a-z]*)*"
66
regex_parameter_name: "[a-z0-9]+(([A-Z]){1}[A-Za-z]+)*"
77

88
exclude_dir: "lib"

requirements.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ Sphinx
22
sphinxcontrib-matlabdomain
33
sphinxcontrib-napoleon
44
sphinx_rtd_theme
5+
myst-parser
6+
sphinx-copybutton
7+
58
miss_hit==0.9.29
9+
pre-commit
10+
611
notebook
712
octave_kernel

0 commit comments

Comments
 (0)