Skip to content

scene_pipelines.core

Shared core helpers (config + registry / versioning / hash / types).

SyncAuthority

Bases: str, Enum

Which database holds the truth for a table's rows (see module docs).

WriteRole

Bases: str, Enum

Which kind of account may INSERT. Absent means unrestricted (see module docs).

Settings dataclass

Immutable resolved settings. prefix includes the trailing underscore.

db_name

db_name(suffix: str) -> str

Full prefixed database name, e.g. 'scene' → 'dev_scene'.

SchemaRegistry

Track schemas created via make_schema and bind them on demand.

Lazy by default: make_schema returns an unbound dj.Schema but remembers the logical suffix (and create_tables) so activate / activate_all can bind without re-stating the name. When AUTO_ACTIVATE is set, make_schema binds immediately.

Entries are keyed by suffix: a suffix is registered once, so a lab schema cannot silently reuse a shared one (e.g. "mouse"). Reuse a registered schema with get; inspect all with the schemas property.

Attributes:

Name Type Description
name

Label for this registry instance (e.g. "scene").

schemas property

schemas: dict[str, Schema]

Snapshot map of suffix → dj.Schema (mutations do not affect the registry).

get

get(suffix: str) -> Schema | None

Return the registered schema for suffix, or None.

make_schema

make_schema(suffix: str, *, create_tables: bool | None = None) -> Schema

Create a DataJoint schema, unbound unless AUTO_ACTIVATE is set.

Parameters:

Name Type Description Default
suffix str

Logical name without prefix (e.g. "scene").

required
create_tables bool | None

Forwarded when activating; True when omitted.

None

Returns:

Type Description
Schema

A dj.Schema instance (unbound unless AUTO_ACTIVATE).

Raises:

Type Description
ValueError

If suffix is empty or already registered.

activate

activate(suffix: str, *, create_tables: bool | None = None, connection: Any | None = None) -> Schema

Bind a registered schema by suffix using activate_schema.

Any dependency schemas are activated first.

Parameters:

Name Type Description Default
suffix str

Logical name without prefix (e.g. "scene").

required
create_tables bool | None

Forwarded to activate_schema; defaults to the value stored at registration when omitted.

None
connection Any | None

Optional DataJoint connection forwarded to activate.

None

Returns:

Type Description
Schema

The registered dj.Schema instance after activation.

Raises:

Type Description
KeyError

If suffix is not registered.

RuntimeError

If a table is referenced from an unactivated schema. The schema is left unbound.

activate_all

activate_all(*, create_tables: bool | None = None, connection: Any | None = None) -> None

Activate every registered schema that is still unbound.

Skips schemas that already have a database set. Per-schema create_tables from make_schema is used unless overridden here. Dependcency schemas are activated first.

Parameters:

Name Type Description Default
create_tables bool | None

Shared create-tables flag. When omitted, each entry uses the value stored at registration.

None
connection Any | None

Optional DataJoint connection forwarded to each activate call.

None

Raises:

Type Description
RuntimeError

If a referenced schema could not be bound first; see activate.

SchemaVersionError

Bases: RuntimeError

DB schema definition version does not match installed code.

sync_authority_of

sync_authority_of(table: type) -> SyncAuthority

Return the table's sync authority: its marker, its master's, or ORIGIN.

write_role_of

write_role_of(table: type) -> WriteRole | None

Return the table's write role, or None when INSERT is unrestricted.

load_settings

load_settings() -> Settings

Resolve settings from the environment. Pure: no mutation, no caching.

atomic

atomic(connection: Connection)

Open a transaction, or join the one already open (DataJoint cannot nest).

lookup_key

lookup_key(table: type[Manual], restriction: DjKey) -> DjKey | None

Return the primary key of the row matching restriction, or None.

restriction should cover a unique index (e.g. lab_id + a code), so at most one row matches.

activate_schema

activate_schema(schema: Schema, suffix: str, *, create_tables: bool = True, connection: Any | None = None) -> Schema

Run DataJoint Schema.activate() with {DJ_SCHEMA_PREFIX}{suffix}.

Parameters:

Name Type Description Default
schema Schema

Unbound (or rebound) dj.Schema instance.

required
suffix str

Logical schema name without prefix (e.g. "scene").

required
create_tables bool

Forwarded to schema.activate.

True
connection Any | None

Optional DataJoint connection forwarded to activate.

None

Returns:

Type Description
Schema

The same schema instance after activation.

Raises:

Type Description
ValueError

If suffix is empty.

assert_schema_compatible

assert_schema_compatible(expected_version: str, version_table: type[Manual]) -> str

Require DB version to match code; raise SchemaVersionError otherwise.