Skip to content

Commit 67c6b5a

Browse files
Merge branch 'master' into cli-1095-continued
2 parents cb14a08 + 0a49595 commit 67c6b5a

File tree

9 files changed

+47
-5
lines changed

9 files changed

+47
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
### 0.14.3 -- TBD
44
- Fixed - Added encapsulating double quotes to comply with [DOT language](https://graphviz.org/doc/info/lang.html) - PR [#1177](https://github.com/datajoint/datajoint-python/pull/1177)
55
- Added - Datajoint python CLI ([#940](https://github.com/datajoint/datajoint-python/issues/940)) PR [#1095](https://github.com/datajoint/datajoint-python/pull/1095)
6+
- Added - Ability to set hidden attributes on a table - PR [#1091](https://github.com/datajoint/datajoint-python/pull/1091)
67

78
### 0.14.2 -- Aug 19, 2024
89
- Added - Migrate nosetests to pytest - PR [#1142](https://github.com/datajoint/datajoint-python/pull/1142)

datajoint/autopopulate.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
def _initialize_populate(table, jobs, populate_kwargs):
2525
"""
26-
Initialize the process for mulitprocessing.
26+
Initialize the process for multiprocessing.
2727
Saves the unpickled copy of the table to the current process and reconnects.
2828
"""
2929
process = mp.current_process()
@@ -153,6 +153,7 @@ def _jobs_to_do(self, restrictions):
153153
def populate(
154154
self,
155155
*restrictions,
156+
keys=None,
156157
suppress_errors=False,
157158
return_exception_objects=False,
158159
reserve_jobs=False,
@@ -169,6 +170,8 @@ def populate(
169170
170171
:param restrictions: a list of restrictions each restrict
171172
(table.key_source - target.proj())
173+
:param keys: The list of keys (dicts) to send to self.make().
174+
If None (default), then use self.key_source to query they keys.
172175
:param suppress_errors: if True, do not terminate execution.
173176
:param return_exception_objects: return error objects instead of just error messages
174177
:param reserve_jobs: if True, reserve jobs to populate in asynchronous fashion
@@ -206,7 +209,10 @@ def handler(signum, frame):
206209

207210
old_handler = signal.signal(signal.SIGTERM, handler)
208211

209-
keys = (self._jobs_to_do(restrictions) - self.target).fetch("KEY", limit=limit)
212+
if keys is None:
213+
keys = (self._jobs_to_do(restrictions) - self.target).fetch(
214+
"KEY", limit=limit
215+
)
210216

211217
# exclude "error", "ignore" or "reserved" jobs
212218
if reserve_jobs:
@@ -295,6 +301,7 @@ def _populate1(
295301
:return: (key, error) when suppress_errors=True,
296302
True if successfully invoke one `make()` call, otherwise False
297303
"""
304+
# use the legacy `_make_tuples` callback.
298305
make = self._make_tuples if hasattr(self, "_make_tuples") else self.make
299306

300307
if jobs is not None and not jobs.reserve(

datajoint/declare.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import re
77
import pyparsing as pp
88
import logging
9+
from hashlib import sha1
910
from .errors import DataJointError, _support_filepath_types, FILEPATH_FEATURE_SWITCH
1011
from .attribute_adapter import get_adapter
1112
from .condition import translate_attribute
@@ -310,6 +311,18 @@ def declare(full_table_name, definition, context):
310311
external_stores,
311312
) = prepare_declare(definition, context)
312313

314+
metadata_attr_sql = [
315+
"`_{full_table_name}_timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP"
316+
]
317+
attribute_sql.extend(
318+
attr.format(
319+
full_table_name=sha1(
320+
full_table_name.replace("`", "").encode("utf-8")
321+
).hexdigest()
322+
)
323+
for attr in metadata_attr_sql
324+
)
325+
313326
if not primary_key:
314327
raise DataJointError("Table must have a primary key")
315328

datajoint/heading.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
is_attachment=False,
3434
is_filepath=False,
3535
is_external=False,
36+
is_hidden=False,
3637
adapter=None,
3738
store=None,
3839
unsupported=False,
@@ -120,7 +121,7 @@ def table_status(self):
120121
def attributes(self):
121122
if self._attributes is None:
122123
self._init_from_database() # lazy loading from database
123-
return self._attributes
124+
return {k: v for k, v in self._attributes.items() if not v.is_hidden}
124125

125126
@property
126127
def names(self):
@@ -300,6 +301,7 @@ def _init_from_database(self):
300301
store=None,
301302
is_external=False,
302303
attribute_expression=None,
304+
is_hidden=attr["name"].startswith("_"),
303305
)
304306

305307
if any(TYPE_PATTERN[t].match(attr["type"]) for t in ("INTEGER", "FLOAT")):

datajoint/table.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,8 @@ def cascade(table):
644644
logger.warn("Nothing to delete.")
645645
if transaction:
646646
self.connection.cancel_transaction()
647+
elif not transaction:
648+
logger.info("Delete completed")
647649
else:
648650
if not safemode or user_choice("Commit deletes?", default="no") == "yes":
649651
if transaction:

tests/test_blob_matlab.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def insert_blobs(schema):
3434

3535
schema.connection.query(
3636
"""
37-
INSERT INTO {table_name} VALUES
37+
INSERT INTO {table_name} (`id`, `comment`, `blob`) VALUES
3838
(1,'simple string',0x6D596D00410200000000000000010000000000000010000000000000000400000000000000630068006100720061006300740065007200200073007400720069006E006700),
3939
(2,'1D vector',0x6D596D0041020000000000000001000000000000000C000000000000000600000000000000000000000000F03F00000000000030400000000000003F4000000000000047400000000000804E4000000000000053400000000000C056400000000000805A400000000000405E4000000000000061400000000000E062400000000000C06440),
4040
(3,'string array',0x6D596D00430200000000000000010000000000000002000000000000002F0000000000000041020000000000000001000000000000000700000000000000040000000000000073007400720069006E00670031002F0000000000000041020000000000000001000000000000000700000000000000040000000000000073007400720069006E0067003200),

tests/test_declare.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,3 +360,11 @@ class Table_With_Underscores(dj.Manual):
360360
dj.DataJointError, match="must be alphanumeric in CamelCase"
361361
) as e:
362362
schema_any(Table_With_Underscores)
363+
364+
365+
def test_hidden_attributes(schema_any):
366+
assert (
367+
list(Experiment().heading._attributes.keys())[-1].split("_")[2] == "timestamp"
368+
)
369+
assert any(a.is_hidden for a in Experiment().heading._attributes.values())
370+
assert not any(a.is_hidden for a in Experiment().heading.attributes.values())

tests_old/test_blob_matlab.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def insert_blobs():
4040

4141
schema.connection.query(
4242
"""
43-
INSERT INTO {table_name} VALUES
43+
INSERT INTO {table_name} (`id`, `comment`, `blob`) VALUES
4444
(1,'simple string',0x6D596D00410200000000000000010000000000000010000000000000000400000000000000630068006100720061006300740065007200200073007400720069006E006700),
4545
(2,'1D vector',0x6D596D0041020000000000000001000000000000000C000000000000000600000000000000000000000000F03F00000000000030400000000000003F4000000000000047400000000000804E4000000000000053400000000000C056400000000000805A400000000000405E4000000000000061400000000000E062400000000000C06440),
4646
(3,'string array',0x6D596D00430200000000000000010000000000000002000000000000002F0000000000000041020000000000000001000000000000000700000000000000040000000000000073007400720069006E00670031002F0000000000000041020000000000000001000000000000000700000000000000040000000000000073007400720069006E0067003200),

tests_old/test_declare.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,3 +341,12 @@ class WithSuchALongPartNameThatItCrashesMySQL(dj.Part):
341341
definition = """
342342
-> (master)
343343
"""
344+
345+
@staticmethod
346+
def test_hidden_attributes():
347+
assert (
348+
list(Experiment().heading._attributes.keys())[-1].split("_")[2]
349+
== "timestamp"
350+
)
351+
assert any(a.is_hidden for a in Experiment().heading._attributes.values())
352+
assert not any(a.is_hidden for a in Experiment().heading.attributes.values())

0 commit comments

Comments
 (0)