Skip to content

Commit 611da2f

Browse files
committed
simplify
1 parent c046870 commit 611da2f

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

datajoint/declare.py

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,12 @@ def build_foreign_key_parser():
114114
return arrow + options + ref_table
115115

116116

117-
def build_attribute_parser(parse_metadata=False):
117+
def build_attribute_parser():
118118
quoted = pp.QuotedString('"') ^ pp.QuotedString("'")
119119
colon = pp.Literal(":").suppress()
120-
attribute_name = pp.Word(
121-
pp.srange(f"[a-z{'_' if parse_metadata else ''}]"), pp.srange("[a-z0-9_]")
122-
).setResultsName("name")
120+
attribute_name = pp.Word(pp.srange("[a-z]"), pp.srange("[a-z0-9_]")).setResultsName(
121+
"name"
122+
)
123123
data_type = (
124124
pp.Combine(pp.Word(pp.alphas) + pp.SkipTo("#", ignore=quoted))
125125
^ pp.QuotedString("<", endQuoteChar=">", unquoteResults=False)
@@ -134,7 +134,6 @@ def build_attribute_parser(parse_metadata=False):
134134
foreign_key_parser_old = build_foreign_key_parser_old()
135135
foreign_key_parser = build_foreign_key_parser()
136136
attribute_parser = build_attribute_parser()
137-
metadata_attribute_parser = build_attribute_parser(parse_metadata=True)
138137

139138

140139
def is_foreign_key(line):
@@ -246,7 +245,6 @@ def prepare_declare(definition, context):
246245
foreign_key_sql = []
247246
index_sql = []
248247
external_stores = []
249-
metadata_attributes = ["_timestamp = CURRENT_TIMESTAMP : timestamp"]
250248

251249
for line in definition:
252250
if not line or line.startswith("#"): # ignore additional comments
@@ -274,12 +272,6 @@ def prepare_declare(definition, context):
274272
if name not in attributes:
275273
attributes.append(name)
276274
attribute_sql.append(sql)
277-
for line in metadata_attributes:
278-
name, sql, store = compile_attribute(
279-
line, in_key, foreign_key_sql, context, is_metadata=True
280-
)
281-
attributes.append(name)
282-
attribute_sql.append(sql)
283275

284276
return (
285277
table_comment,
@@ -316,6 +308,7 @@ def declare(full_table_name, definition, context):
316308
index_sql,
317309
external_stores,
318310
) = prepare_declare(definition, context)
311+
attribute_sql.extend(["`_timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP"])
319312

320313
if not primary_key:
321314
raise DataJointError("Table must have a primary key")
@@ -504,22 +497,18 @@ def substitute_special_type(match, category, foreign_key_sql, context):
504497
assert False, "Unknown special type"
505498

506499

507-
def compile_attribute(line, in_key, foreign_key_sql, context, is_metadata=False):
500+
def compile_attribute(line, in_key, foreign_key_sql, context):
508501
"""
509502
Convert attribute definition from DataJoint format to SQL
510503
511504
:param line: attribution line
512505
:param in_key: set to True if attribute is in primary key set
513506
:param foreign_key_sql: the list of foreign key declarations to add to
514507
:param context: context in which to look up user-defined attribute type adapterss
515-
:param is_metadata: flag to use an alternate parser for metadata attributes
516508
:returns: (name, sql, is_external) -- attribute name and sql code for its declaration
517509
"""
518510
try:
519-
if is_metadata:
520-
match = metadata_attribute_parser.parseString(line + "#", parseAll=True)
521-
else:
522-
match = attribute_parser.parseString(line + "#", parseAll=True)
511+
match = attribute_parser.parseString(line + "#", parseAll=True)
523512
except pp.ParseException as err:
524513
raise DataJointError(
525514
"Declaration error in position {pos} in line:\n {line}\n{msg}".format(

0 commit comments

Comments
 (0)