Skip to content

Commit b4838e4

Browse files
author
Chris Turner
authored
Merge pull request #317 from datajoint/stage-external-storage
Add packaging, support for GHA, and resolve conflicts
2 parents 508f0d1 + 28dc40d commit b4838e4

40 files changed

+759
-500
lines changed

+dj/+config/load.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
function load(fname)
2+
% LOAD(fname)
3+
% Description:
4+
% Updates the setting from config file in JSON format.
5+
% Inputs:
6+
% fname[optional, default=dj.internal.Settings.LOCALFILE]: (string) Config file path.
7+
% Examples:
8+
% dj.config.load('/path/to/dj_local_conf.json')
9+
% dj.config.load
210
switch nargin
311
case 0
412
dj.internal.Settings.load();

+dj/+config/restore.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
function out = restore()
2+
% RESTORE()
3+
% Description:
4+
% Restores the configuration to initial default.
5+
% Examples:
6+
% dj.config.restore
27
out = dj.internal.Settings.restore();
38
end

+dj/+config/save.m

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
function save(fname)
2+
% SAVE(fname)
3+
% Description:
4+
% Saves the settings in JSON format to the given file path.
5+
% Inputs:
6+
% fname[required]: (string) Config file path.
7+
% Examples:
8+
% dj.config.save('/path/to/dj_local_conf.json')
29
switch nargin
3-
case 0
4-
dj.internal.Settings.save();
510
case 1
611
dj.internal.Settings.save(fname);
712
otherwise
8-
error('Exceeded 1 input limit.');
13+
error('Requires 1 input.');
914
end
1015
end

+dj/+config/saveGlobal.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
function saveGlobal()
2+
% SAVEGLOBAL()
3+
% Description:
4+
% Saves the settings in the global config file.
5+
% Examples:
6+
% dj.config.saveGlobal
27
dj.internal.Settings.saveGlobal();
38
end

+dj/+config/saveLocal.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
function saveLocal()
2+
% SAVELOCAL()
3+
% Description:
4+
% Saves the settings in the local config file.
5+
% Examples:
6+
% dj.config.saveLocal
27
dj.internal.Settings.saveLocal();
38
end

+dj/+internal/TableAccessor.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@
3030
tierClass = 'dj.Manual';
3131
for k=1:numel(dj.Schema.tierPrefixes)
3232
tierCharLen = length(dj.Schema.tierPrefixes{k});
33-
if tierCharLen > 0 && ~isempty(regexp(dj.Schema.tierPrefixes{k}, ...
34-
tableName(1:tierCharLen), 'ONCE'))
33+
if tierCharLen > 0 && length(tableName) >= tierCharLen && ...
34+
~isempty(regexp(dj.Schema.tierPrefixes{k}, ...
35+
tableName(1:tierCharLen), 'ONCE'))
3536
tierClass = dj.Schema.tierClasses{k};
3637
break;
3738
end

+dj/+lib/getpass.m

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,15 @@
3535
% wait for password entry
3636
uiwait
3737
pass = get(hpass,'userdata');
38+
if isempty(pass)
39+
pass = '';
40+
end
41+
3842
% remove the figure to prevent passwork leakage
3943
delete(hfig)
40-
4144

45+
end
46+
4247
function keypress_cb(hObj, data, hpass)
4348
% Callback function to handle actual key strokes
4449

@@ -55,4 +60,5 @@ function keypress_cb(hObj, data, hpass)
5560
pass = [pass data.Character];
5661
end
5762
set(hpass, 'userdata', pass)
58-
set(hpass, 'String', char('*' * sign(pass)))
63+
set(hpass, 'String', char('*' * sign(pass)))
64+
end

+dj/Connection.m

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

+dj/Relvar.m

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -409,20 +409,23 @@ function update(self, attrname, value)
409409
% update(v2p.Mice & key, 'mouse_dob', '2011-01-01')
410410
% update(v2p.Scan & key, 'lens') % set the value to NULL
411411

412-
assert(count(self)==1, 'Update is only allowed on one tuple at a time')
413-
isNull = nargin<3;
412+
assert(count(self)==1, 'Update is only allowed on one tuple at a time');
414413
header = self.header;
415414
ix = find(strcmp(attrname,header.names));
416-
assert(numel(ix)==1, 'invalid attribute name')
415+
assert(numel(ix)==1, 'invalid attribute name');
417416
assert(~header.attributes(ix).iskey, ...
418-
'cannot update a key value. Use insert(..,''REPLACE'') instead')
417+
'cannot update a key value. Use insert(..,''REPLACE'') instead');
418+
isNull = nargin<3 || (header.attributes(ix).isNumeric && isnan(value)) || ...
419+
(~header.attributes(ix).isNumeric && ~ischar(value) && isempty(value));
419420

420421
switch true
421422
case isNull
423+
assert(header.attributes(ix).isnullable, ...
424+
'attribute `%s` is not nullable.', attrname);
422425
valueStr = 'NULL';
423426
value = {};
424427
case header.attributes(ix).isString
425-
assert(dj.lib.isString(value), 'Value must be a string')
428+
assert(dj.lib.isString(value), 'Value must be a string');
426429
valueStr = '"{S}"';
427430
value = {char(value)};
428431
case header.attributes(ix).isAttachment || header.attributes(ix).isFilepath
@@ -434,24 +437,12 @@ function update(self, attrname, value)
434437
'DataJoint:DataType:Mismatch', ...
435438
'Sparse matrix in blob field `%s` is currently not supported', ...
436439
attrname);
437-
if isempty(value) && header.attributes(ix).isnullable
438-
valueStr = 'NULL';
439-
value = {};
440-
else
441-
valueStr = '"{M}"';
442-
value = {value};
443-
end
440+
valueStr = '"{M}"';
441+
value = {value};
444442
case header.attributes(ix).isNumeric
445443
assert(isscalar(value) && isnumeric(value), 'Numeric value must be scalar')
446-
if isnan(value)
447-
assert(header.attributes(ix).isnullable, ...
448-
'attribute `%s` is not nullable. NaNs not allowed', attrname)
449-
valueStr = 'NULL';
450-
value = {};
451-
else
452-
valueStr = sprintf('%1.16g',value);
453-
value = {};
454-
end
444+
valueStr = sprintf('%1.16g',value);
445+
value = {};
455446
otherwise
456447
error 'invalid update command'
457448
end

+dj/Schema.m

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
end
7878

7979

80-
function makeClass(self, className)
80+
function makeClass(self, className, tableTierChoice)
8181
% create a base relvar class for the new className in schema directory.
8282
%
8383
% Example:
@@ -115,17 +115,19 @@ function makeClass(self, className)
115115
tierClass = tierClassMap.(existingTable.info.tier(1));
116116
else
117117
existingTable = [];
118-
choice = dj.internal.ask(...
119-
['\nChoose table tier:\n L=lookup\n M=manual\n I=imported\n ' ...
120-
'C=computed\n P=part\n'],...
121-
{'L','M','I','C','P'});
122-
tierClass = tierClassMap.(choice);
118+
if nargin < 3
119+
tableTierChoice = dj.internal.ask(...
120+
['\nChoose table tier:\n L=lookup\n M=manual\n I=imported\n ' ...
121+
'C=computed\n P=part\n'],...
122+
{'L','M','I','C','P'});
123+
end
124+
tierClass = tierClassMap.(lower(tableTierChoice));
123125
isAuto = ismember(tierClass, {'dj.Imported', 'dj.Computed'});
124126
end
125-
127+
126128
f = fopen(filename,'wt');
127129
assert(-1 ~= f, 'Could not open %s', filename)
128-
130+
129131
% table declaration
130132
if numel(existingTable)
131133
fprintf(f, '%s', existingTable.describe);

0 commit comments

Comments
 (0)