Skip to content

[ENH] update initialisation #213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"contributors": [
{
"login": "CerenB",
"name": "CerenB",
"name": "Ceren Battal",
"avatar_url": "https://avatars1.githubusercontent.com/u/10451654?v=4",
"profile": "https://github.com/CerenB",
"contributions": [
Expand All @@ -21,7 +21,7 @@
},
{
"login": "marcobarilari",
"name": "marcobarilari",
"name": "Marco Barilari",
"avatar_url": "https://avatars3.githubusercontent.com/u/38101692?v=4",
"profile": "https://github.com/marcobarilari",
"contributions": [
Expand Down Expand Up @@ -64,7 +64,7 @@
},
{
"login": "iqrashahzad14",
"name": "iqrashahzad14",
"name": "Iqra Shahzad",
"avatar_url": "https://avatars.githubusercontent.com/u/75671348?v=4",
"profile": "https://github.com/iqrashahzad14",
"contributions": [
Expand Down
67 changes: 9 additions & 58 deletions checkCppBidsDependencies.m
Original file line number Diff line number Diff line change
@@ -1,65 +1,16 @@
% (C) Copyright 2020 CPP_BIDS developers

function checkCppBidsDependencies(cfg)
%
% Adds dependencies to the Matlab / Octave path and make sure we got all of them.
%
% USAGE::
%
% checkCppBidsDependencies(cfg)
%
% :param cfg: Configuration. See ``checkCFG()``.
% :type cfg: structure

if nargin < 1
cfg.verbose = 2;
end

global CPP_BIDS_INITIALIZED

if isempty(CPP_BIDS_INITIALIZED)

GITHUB_WORKSPACE = getenv('GITHUB_WORKSPACE');

if strcmp(GITHUB_WORKSPACE, '/github/workspace')

pth = GITHUB_WORKSPACE;
addpath(genpath(fullfile(pth, 'lib')));

elseif isempty(GITHUB_WORKSPACE) % local
% (C) Copyright 2020 CPP_BIDS developers

pth = fullfile(fileparts(mfilename('fullpath')));

addpath(pth);

checkSubmodule(fullfile(pth, 'lib', 'JSONio'));
checkSubmodule(fullfile(pth, 'lib', 'bids-matlab'));

addpath(genpath(fullfile(pth, 'src')));

end

printCreditsCppBids(cfg);

CPP_BIDS_INITIALIZED = true();

else
if ~isfield(cfg, 'versbose') || cfg.verbose
fprintf(1, '\n\nCPP_BIDS already initialized\n\n');
end
warning(sprintf(['\n\nDEPRECATION WARNING:\n', ...
'"checkCppBidsDependencies" is deprecated ', ...
'and will be removed in a future release.\n', ...
'\nPlease use "cpp_bids(''init'')" instead.'])); %#ok<SPWRN>

verbose = false;
if nargin > 0 && ~isempty(cfg) && isfield(cfg, 'verbose') && ~isempty(cfg.verbose)
verbose = cfg.verbose;
end

end
cpp_bids('init', 'verbose', verbose);

function checkSubmodule(pth)
% If external dir is empty throw an exception
% and ask user to update submodules.
if numel(dir(pth)) <= 2 % Means that the external is empty
error(['Git submodules are not cloned!', ...
'Try this in your terminal:', ...
' git submodule update --recursive ']);
else
addpath(pth);
end
end
171 changes: 171 additions & 0 deletions cpp_bids.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
function cpp_bids(varargin)
%
% General intro function for CPP BIDS
%
% USAGE::
%
% cpp_bids
% cpp_bids('init')
% cpp_bids('uninit')
% cpp_bids('dev')
%
% :param action:
% :type action: string
%
% :returns: - :action: (type) (dimension)
%
% Example::
%
% (C) Copyright 2022 CPP_BIDS developers

p = inputParser;

defaultAction = 'init';

addOptional(p, 'action', defaultAction, @ischar);
addParameter(p, 'verbose', true);

parse(p, varargin{:});

action = p.Results.action;
verbose = p.Results.verbose;

switch lower(action)

case 'init'

initCppBids(verbose);

case 'uninit'

uninitCppBids();

case 'run_tests'

runTests();

end

end

function initCppBids(verbose)
%
% Adds the relevant folders to the path for a given session.
% Has to be run to be able to use CPP_BIDS.
%
% USAGE::
%
% initCppPtb()
%
% (C) Copyright 2022 CPP_BIDS developers

thisDirectory = fileparts(mfilename('fullpath'));

global CPP_BIDS_INITIALIZED
global CPP_BIDS_PATHS

if isempty(CPP_BIDS_INITIALIZED)

pathSep = ':';
if ~isunix
pathSep = ';';
end

CPP_BIDS_PATHS = fullfile(thisDirectory);
CPP_BIDS_PATHS = cat(2, CPP_BIDS_PATHS, ...
pathSep, ...
genpath(fullfile(thisDirectory, 'src')));
assert(isdir(fullfile(thisDirectory, 'lib', 'bids-matlab', '+bids')));
CPP_BIDS_PATHS = cat(2, CPP_BIDS_PATHS, pathSep, ...
fullfile(thisDirectory, 'lib', 'bids-matlab'));
assert(isdir(fullfile(thisDirectory, 'lib', 'JSONio')));
CPP_BIDS_PATHS = cat(2, CPP_BIDS_PATHS, pathSep, ...
fullfile(thisDirectory, 'lib', 'JSONio'));

addpath(CPP_BIDS_PATHS, '-begin');

CPP_BIDS_INITIALIZED = true();

detectCppBids();

if verbose
printCreditsCppBids();
end

else
if verbose
fprintf('\n\nCPP_BIDS already initialized\n\n');
end

end

end

function detectCppBids()

workflowsDir = cellstr(which('saveEventsFile.m', '-ALL'));

if isempty(workflowsDir)
error('CPP_BIDS is not in your MATLAB / Octave path.\n');

elseif numel(workflowsDir) > 1
fprintf('CPP_BIDS seems to appear in several different folders:\n');
for i = 1:numel(workflowsDir)
fprintf(' * %s\n', fullfile(workflowsDir{i}, '..', '..'));
end
error('Remove all but one with ''pathtool'' .\n'); % or ''spm_rmpath

end
end

function uninitCppBids()
%
% Removes the added folders from the path for a given session.
%
% USAGE::
%
% uninitCppPtb()
%
% (C) Copyright 2021 CPP_BIDS developers

global CPP_BIDS_INITIALIZED
global CPP_BIDS_PATHS

if isempty(CPP_BIDS_INITIALIZED) || ~CPP_BIDS_INITIALIZED
fprintf('\n\nCPP_BIDS not initialized\n\n');
return

else
rmpath(CPP_BIDS_PATHS);

if isOctave
clear -g;
else
clearvars -GLOBAL;
end

end

end

function retval = isOctave()
%
% Returns true if the environment is Octave.
%
% USAGE::
%
% retval = isOctave()
%
% :returns: :retval: (boolean)
%
% (C) Copyright 2020 Agah Karakuzu
% (C) Copyright 2022 CPP_BIDS developers

persistent cacheval % speeds up repeated calls

if isempty (cacheval)
cacheval = (exist ('OCTAVE_VERSION', 'builtin') > 0);
end

retval = cacheval;
end
49 changes: 27 additions & 22 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,19 @@
#
import os
import sys
sys.path.insert(0, os.path.abspath('../..'))

sys.path.insert(0, os.path.abspath("../.."))


# -- Project information -----------------------------------------------------

project = 'CPP BIDS'
copyright = '2020, the CPP BIDS dev team'
author = 'the CPP BIDS dev team'
project = "CPP BIDS"
copyright = "2020, the CPP BIDS dev team"
author = "the CPP BIDS dev team"

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


# -- General configuration ---------------------------------------------------
Expand All @@ -31,42 +33,45 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinxcontrib.matlab',
'sphinx.ext.autodoc']
matlab_src_dir = os.path.dirname(os.path.abspath('../../src'))
primary_domain = 'mat'
"sphinxcontrib.matlab",
"sphinx.ext.autodoc",
"myst_parser",
"sphinx_copybutton",
]
matlab_src_dir = os.path.dirname(os.path.abspath("../../src"))
primary_domain = "mat"

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

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

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
source_suffix = ".rst"


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'
html_theme = "sphinx_rtd_theme"

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

html_logo = '_static/cpp_lab_logo.png'
html_logo = "_static/cpp_lab_logo.png"

# html_theme_options = {
# 'github_user': 'cpp-lln-lab',
Expand All @@ -81,11 +86,11 @@
# }

html_sidebars = {
'**': [
'about.html',
'navigation.html',
'relations.html', # needs 'show_related': True theme option to display
'searchbox.html',
'donate.html',
"**": [
"about.html",
"navigation.html",
"relations.html", # needs 'show_related': True theme option to display
"searchbox.html",
"donate.html",
]
}
2 changes: 1 addition & 1 deletion miss_hit.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
project_root

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

exclude_dir: "lib"
Expand Down
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ Sphinx
sphinxcontrib-matlabdomain
sphinxcontrib-napoleon
sphinx_rtd_theme
myst-parser
sphinx-copybutton

miss_hit==0.9.29
pre-commit

notebook
octave_kernel
Loading