Skip to content

Commit c2bd6b3

Browse files
Merge pull request #338 from datajoint/stage
Patch virtual classes regression bug, attribute comment parsing bug, initial config load bug, and add issue templates
2 parents 892f736 + d09858e commit c2bd6b3

File tree

21 files changed

+205
-40
lines changed

21 files changed

+205
-40
lines changed

+dj/+internal/Declare.m

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,24 @@
5454
if isa(table_instance, 'dj.Part')
5555
tableInfo.tier = 'part';
5656
elseif ~isa(table_instance, 'dj.internal.ExternalTable')
57-
specialClass = find(cellfun(@(c) isa(table_instance, c), ...
58-
dj.Schema.tierClasses));
59-
assert(length(specialClass)==1, ...
60-
'Unknown type of UserRelation in %s', class(table_instance))
61-
tableInfo.tier = dj.Schema.allowedTiers{specialClass};
57+
try
58+
specialClass = find(cellfun(@(c) isa(table_instance, c), ...
59+
dj.Schema.tierClasses));
60+
assert(length(specialClass)==1, ...
61+
'DataJoint:TableType:Unknown', ...
62+
'Unknown type of UserRelation in %s', class(table_instance))
63+
tableInfo.tier = dj.Schema.allowedTiers{specialClass};
64+
catch ME
65+
if ~strcmp(ME.identifier,'DataJoint:TableType:Unknown')
66+
rethrow(ME);
67+
else
68+
tier = dj.ERD.getTier(table_instance.plainTableName);
69+
assert(~isempty(tier), ...
70+
'DataJoint:TableType:Unknown', ...
71+
'Unknown type of UserRelation in %s',class(table_instance))
72+
tableInfo.tier = tier;
73+
end
74+
end
6275
end
6376
% remove empty lines
6477
def(cellfun(@(x) isempty(x), def)) = [];
@@ -368,8 +381,8 @@ case regexp(line, ['^[a-z][a-z\d_]*\s*' ... % name
368381
end
369382
end
370383
end
371-
assert(~any(ismember(field.comment, '"\')), ... % TODO: escape isntead
372-
'illegal characters in attribute comment "%s"', field.comment)
384+
% Escape characters: "/
385+
field.comment = regexprep(field.comment, '(["\/])', '\\\\$1');
373386

374387
category = dj.internal.Declare.matchType(field.type);
375388
store = [];

+dj/+internal/Header.m

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,11 @@
9292
attrs.database{i} = schema.dbname;
9393
attrs.sqlType{i} = attrs.type{i};
9494
attrs.sqlComment{i} = attrs.comment{i};
95-
special = regexp(attrs.comment{i}, ':([^:]+):(.*)', 'tokens');
95+
special = regexp(attrs.comment{i}, ...
96+
'^:(?<type>[^:]+):(?<comment>.*)', 'names');
9697
if ~isempty(special)
97-
attrs.type{i} = special{1}{1};
98-
attrs.comment{i} = special{1}{2};
98+
attrs.type{i} = special.type;
99+
attrs.comment{i} = special.comment;
99100
category = dj.internal.Declare.matchType(attrs.type{i});
100101
assert(any(strcmpi(category, dj.internal.Declare.SPECIAL_TYPES)));
101102
else

+dj/+internal/Settings.m

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,14 @@ function envVarUpdate()
147147
% return STATE prior to change
148148
out = STATE;
149149
if any(strcmpi(operation, {'set', 'load'}))
150-
% merge with existing STATE
151-
STATE = rmfield(STATE, intersect(fieldnames(STATE), fieldnames(new)));
152-
names = [fieldnames(STATE); fieldnames(new)];
153-
STATE = orderfields(cell2struct([struct2cell(STATE); struct2cell(new)], names, 1));
150+
if isempty(STATE)
151+
STATE = new;
152+
else
153+
% merge with existing STATE
154+
STATE = rmfield(STATE, intersect(fieldnames(STATE), fieldnames(new)));
155+
names = [fieldnames(STATE); fieldnames(new)];
156+
STATE = orderfields(cell2struct([struct2cell(STATE); struct2cell(new)], names, 1));
157+
end
154158
if strcmpi(operation, 'load')
155159
envVarUpdate();
156160
end

+dj/+internal/TableAccessor.m

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,7 @@
2626
splitName = strsplit(className{1}, '.');
2727
name = splitName{2};
2828
addprop(self, name);
29-
tableName = schema.tableNames(className{1});
30-
tierClass = 'dj.Manual';
31-
for k=1:numel(dj.Schema.tierPrefixes)
32-
tierCharLen = length(dj.Schema.tierPrefixes{k});
33-
if tierCharLen > 0 && length(tableName) >= tierCharLen && ...
34-
~isempty(regexp(dj.Schema.tierPrefixes{k}, ...
35-
tableName(1:tierCharLen), 'ONCE'))
36-
tierClass = dj.Schema.tierClasses{k};
37-
break;
38-
end
39-
end
40-
tierClass = strsplit(tierClass, '.');
41-
self.(name) = dj.(tierClass{2})(className{1});
29+
self.(name) = dj.internal.UserRelation(className{1});
4230
end
4331
end
4432
end

+dj/Computed.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
classdef Computed < dj.internal.AutoPopulate
22
% defines a computed table
3+
properties(Constant)
4+
tierRegexp = sprintf('(?<computed>%s%s)', ...
5+
dj.Schema.tierPrefixes{strcmp(dj.Schema.allowedTiers, 'computed')}, ...
6+
dj.Schema.baseRegexp)
7+
end
38
methods
49
function self = Computed(varargin)
510
[email protected](varargin{:})

+dj/ERD.m

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,12 @@ function draw(self)
118118

119119
self.makeGraph
120120

121-
rege = cellfun(@(s) sprintf('^`[a-z]\\w*`\\.`%s[a-z]\\w*`$',s), dj.Schema.tierPrefixes, 'uni', false);
121+
rege = cellfun(@(s) sprintf('^`[a-z]\\w*`\\.`%s[a-z]\\w*`$',s), ...
122+
dj.Schema.tierPrefixes, 'uni', false);
122123
rege{end+1} = '^`[a-z]\w*`\.`\W?\w+__\w+`$'; % for part tables
123124
rege{end+1} = '^\d+$'; % for numbered nodes
124-
tiers = cellfun(@(l) find(~cellfun(@isempty, regexp(l, rege)), 1, 'last'), self.graph.Nodes.Name);
125+
tiers = cellfun(@(l) find(~cellfun(@isempty, regexp(l, rege)), 1, 'last'), ...
126+
self.graph.Nodes.Name);
125127
colormap(0.3+0.7*[
126128
0.3 0.3 0.3
127129
0.0 0.5 0.0
@@ -180,8 +182,10 @@ function makeGraph(self)
180182
ref = [];
181183
from = [];
182184
else
183-
from = arrayfun(@(item) find(strcmp(item.from, list)), self.conn.foreignKeys, 'uni', false);
184-
ref = arrayfun(@(item) find(strcmp(item.ref, list)), self.conn.foreignKeys, 'uni', false);
185+
from = arrayfun(@(item) find(strcmp(item.from, list)), ...
186+
self.conn.foreignKeys, 'uni', false);
187+
ref = arrayfun(@(item) find(strcmp(item.ref, list)), ...
188+
self.conn.foreignKeys, 'uni', false);
185189
ix = ~cellfun(@isempty, from) & ~cellfun(@isempty, ref);
186190
if ~isempty(ref)
187191
primary = [self.conn.foreignKeys(ix).primary];
@@ -212,6 +216,18 @@ function makeGraph(self)
212216
end
213217
end
214218
end
215-
216-
219+
methods(Static)
220+
function tier = getTier(tableName)
221+
tier = [];
222+
for pattern = cellfun(@(x) dj.(x(4:end)).tierRegexp, dj.Schema.tierClasses, ...
223+
'uni', false)
224+
fieldInfo = regexp(tableName, pattern{1}, 'names');
225+
if ~isempty(fieldInfo)
226+
tier = fieldnames(fieldInfo);
227+
tier = tier{1};
228+
break
229+
end
230+
end
231+
end
232+
end
217233
end

+dj/Imported.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
classdef Imported < dj.internal.AutoPopulate
22
% defines an imported table
3+
properties(Constant)
4+
tierRegexp = sprintf('(?<imported>%s%s)', ...
5+
dj.Schema.tierPrefixes{strcmp(dj.Schema.allowedTiers, 'imported')}, ...
6+
dj.Schema.baseRegexp)
7+
end
38
methods
49
function self = Imported(varargin)
510
[email protected](varargin{:})

+dj/Jobs.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
classdef Jobs < dj.Relvar
2+
properties(Constant)
3+
tierRegexp = sprintf('(?<job>%s%s)', ...
4+
dj.Schema.tierPrefixes{strcmp(dj.Schema.allowedTiers, 'job')}, ...
5+
dj.Schema.baseRegexp)
6+
end
27
methods
38
function self = Jobs(varargin)
49
[email protected](varargin{:})

+dj/Lookup.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
classdef Lookup < dj.internal.UserRelation
22
% defines a lookup table
3-
3+
properties(Constant)
4+
tierRegexp = sprintf('(?<lookup>%s%s)', ...
5+
dj.Schema.tierPrefixes{strcmp(dj.Schema.allowedTiers, 'lookup')}, ...
6+
dj.Schema.baseRegexp)
7+
end
48
methods
59
function self = Lookup(varargin)
610
[email protected](varargin{:})

+dj/Manual.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
classdef Manual < dj.internal.UserRelation
22
% Defines a manual table
3+
properties(Constant)
4+
tierRegexp = sprintf('(?<manual>%s%s)', ...
5+
dj.Schema.tierPrefixes{strcmp(dj.Schema.allowedTiers, 'manual')}, ...
6+
dj.Schema.baseRegexp)
7+
end
38
methods
49
function self = Manual(varargin)
510
[email protected](varargin{:})

0 commit comments

Comments
 (0)