Skip to content

Commit ea1c494

Browse files
author
Chris Turner
authored
Merge pull request #285 from datajoint/stage2
Add Toolbox packaging
2 parents 34c51d0 + f6c6888 commit ea1c494

21 files changed

+246
-315
lines changed

+dj/+lib/compareVersions.m

-100
This file was deleted.

+dj/Connection.m

+1-10
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,7 @@
2727
% specify the connection to the database.
2828
% initQuery is the SQL query to be executed at the start
2929
% of each new session.
30-
setupDJ(true);
31-
try
32-
mymVersion = mym('version');
33-
assert(mymVersion.major > 2 || mymVersion.major==2 && mymVersion.minor>=6)
34-
catch
35-
error 'Outdated version of mYm. Please upgrade to version 2.6 or later'
36-
end
37-
if verLessThan('matlab', '8.6')
38-
error 'MATLAB version 8.6 (R2015b) or greater is required'
39-
end
30+
dj.setup('prompt', ~dj.set('suppressPrompt'));
4031
self.host = host;
4132
self.user = username;
4233
self.password = password;

+dj/conn.m

-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
end
4646
end
4747
else
48-
% invoke setupDJ
4948
% optional environment variables specifying the connection.
5049
env = struct(...
5150
'host', 'DJ_HOST', ...

+dj/setup.m

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
function setup(varargin)
2+
p = inputParser;
3+
addOptional(p, 'force', false);
4+
addOptional(p, 'prompt', true);
5+
parse(p, varargin{:});
6+
force = p.Results.force;
7+
prompt = p.Results.prompt;
8+
persistent INVOKED
9+
if ~isempty(INVOKED) && ~force
10+
return
11+
end
12+
% check MATLAB
13+
if verLessThan('matlab', '9.1')
14+
error('DataJoint:System:UnsupportedMatlabVersion', ...
15+
'MATLAB version 9.1 (R2016b) or greater is required');
16+
end
17+
% require certain toolboxes
18+
requiredToolboxes = {...
19+
struct(...
20+
'Name', 'GHToolbox', ...
21+
'ResolveTarget', 'datajoint/GHToolbox'...
22+
), ...
23+
struct(...
24+
'Name', 'mym', ...
25+
'ResolveTarget', 'datajoint/mym', ...
26+
'Version', @(v) compareVersions(v, '2.7.3', @(v_actual,v_ref) v_actual>=v_ref)...
27+
)...
28+
};
29+
try
30+
ghtb.require(requiredToolboxes, 'prompt', prompt);
31+
catch ME
32+
installPromptMsg = {
33+
'Toolbox ''%s'' did not meet the minimum requirements.'
34+
'Would you like to proceed with an upgrade?'
35+
};
36+
if strcmp(ME.identifier, 'MATLAB:undefinedVarOrClass') && (~prompt || strcmpi('yes',...
37+
dj.internal.ask(sprintf(sprintf('%s\n', installPromptMsg{:}), 'GHToolbox'))))
38+
% fetch
39+
tmp_toolbox = [tempname '.mltbx'];
40+
websave(tmp_toolbox, ['https://github.com/' requiredToolboxes{1}.ResolveTarget ...
41+
'/releases/download/' ...
42+
subsref(webread(['https://api.github.com/repos/' ...
43+
requiredToolboxes{1}.ResolveTarget ...
44+
'/releases/latest'], ...
45+
weboptions('Timeout', 60)), ...
46+
substruct('.', 'tag_name')) ...
47+
'/GHToolbox.mltbx'], weboptions('Timeout', 60));
48+
% install
49+
try
50+
matlab.addons.install(tmp_toolbox, 'overwrite');
51+
catch ME
52+
if strcmp(ME.identifier, 'MATLAB:undefinedVarOrClass')
53+
matlab.addons.toolbox.installToolbox(tmp_toolbox);
54+
else
55+
rethrow(ME);
56+
end
57+
end
58+
% remove temp toolbox file
59+
delete(tmp_toolbox);
60+
% retrigger dependency validation
61+
ghtb.require(requiredToolboxes, 'prompt', prompt);
62+
elseif strcmp(ME.identifier, 'MATLAB:undefinedVarOrClass')
63+
GHToolboxMsg = {
64+
'Toolbox ''GHToolbox'' did not meet the minimum requirements.'
65+
'Please proceed to install it.'
66+
};
67+
error('DataJoint:verifyGHToolbox:Failed', ...
68+
sprintf('%s\n', GHToolboxMsg{:}));
69+
else
70+
rethrow(ME)
71+
end
72+
end
73+
% check mym
74+
mymVersion = mym('version');
75+
assert(mymVersion.major > 2 || mymVersion.major==2 && mymVersion.minor>=6, ...
76+
'DataJoint:System:mYmIncompatible', ...
77+
'Outdated version of mYm. Please upgrade to version 2.6 or later');
78+
% set cache
79+
INVOKED = true;
80+
end

+dj/version.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
function varargout = version
22
% report DataJoint version
33

4-
v = struct('major',3,'minor',3,'bugfix',1);
4+
v = struct('major',3,'minor',3,'bugfix',2);
55

66
if nargout
77
varargout{1}=v;

+tests/+lib/compareVersions.m

-100
This file was deleted.

+tests/Main.m

-5
This file was deleted.

.gitignore

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
*.m~
22
mym/
3-
*.mltbx
43
*.env
54
notebook
65
*getSchema.m
76
docker-compose.yml
87
.vscode
98
matlab.prf
109
win.*
11-
macos.*
10+
macos.*
11+
*.prj
12+
*.mltbx

.gitmodules

Whitespace-only changes.

.travis.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
- <<: *slim
2525
env:
2626
- MATLAB_VERSION: R2019a
27-
- MYSQL_TAG: 8.0
27+
- MYSQL_TAG: 8.0.18
2828
- <<: *slim
2929
env:
3030
- MATLAB_VERSION: R2019a
@@ -36,4 +36,8 @@ jobs:
3636
- <<: *slim
3737
env:
3838
- MATLAB_VERSION: R2018b
39+
- MYSQL_TAG: 5.7
40+
- <<: *slim
41+
env:
42+
- MATLAB_VERSION: R2016b
3943
- MYSQL_TAG: 5.7

0 commit comments

Comments
 (0)