Skip to content

Commit 4f468d4

Browse files
perf: lazy-load deepdiff and tqdm in autopopulate
Move imports inside methods where they're used to avoid loading these dependencies at module import time. This speeds up `import datajoint` for users who don't call populate(). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent a8b0734 commit 4f468d4

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/datajoint/autopopulate.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
import traceback
1212
from typing import TYPE_CHECKING, Any, Generator
1313

14-
import deepdiff
15-
from tqdm import tqdm
16-
1714
from .errors import DataJointError, LostConnectionError
1815
from .expression import AndList, QueryExpression
1916

@@ -401,6 +398,8 @@ def _populate_direct(
401398
Computes keys directly from key_source, suitable for single-worker
402399
execution, development, and debugging.
403400
"""
401+
from tqdm import tqdm
402+
404403
keys = (self._jobs_to_do(restrictions) - self).keys()
405404

406405
logger.debug("Found %d keys to populate" % len(keys))
@@ -473,6 +472,8 @@ def _populate_distributed(
473472
Uses job table for multi-worker coordination, priority scheduling,
474473
and status tracking.
475474
"""
475+
from tqdm import tqdm
476+
476477
from .settings import config
477478

478479
# Define a signal handler for SIGTERM
@@ -581,6 +582,8 @@ def _populate1(
581582
"""
582583
import time
583584

585+
import deepdiff
586+
584587
# use the legacy `_make_tuples` callback.
585588
make = self._make_tuples if hasattr(self, "_make_tuples") else self.make
586589

0 commit comments

Comments
 (0)