Skip to content

PackageConfigBase API

Bases: BaseModel

Typed view over a package's [tools.<tool_name>] TOML section.

Subclass this and declare typed fields for whatever this package needs. A field typed Annotated[str, RefTo(CDMDatabaseConfig)] (or RefTo(GenericDatabaseConfig)/ RefTo(ModelConfig)/RefTo(ProviderConfig)/RefTo(ConnectionConfig)) names an entry in that section. omop-config configure resolves it interactively: reuse an existing entry, or create one, recursing into any RefTo fields the target itself has (e.g. a database's own connection). :meth:~oa_configurator.Resolver.resolve_package_config validates that it resolves, raising :exc:ConfigurationError if not. There is no separate "required"/"owned" declaration. The field itself is the declaration, and two packages share an entry simply by their fields resolving to the same name.

Attributes:

Name Type Description
tool_name str

Key used in [tools.<name>]. Must be set on every subclass.

extra_logging_namespaces tuple[str, ...]

Logger namespaces of transitive dependencies to configure alongside this package. The package's own tool_name is always included; only list additional roots here, e.g. ("my_extra_package_to_log",). Missing namespaces are harmless.

configure_logging classmethod

configure_logging(
    config=None, *, verbosity: int = 0, console=None
) -> None

Configure logging for this package and its declared transitive dependencies.

get_config classmethod

get_config() -> Self

Load this package's config from the active stack config file.

get_engine classmethod

get_engine(database: str, **engine_kwargs: Any) -> Any

Create a SQLAlchemy engine for a database.

Parameters:

Name Type Description Default
database str

The database name to resolve, typically read off your own resolved config (e.g. MyPackageConfig.get_config().cdm_db).

required
**engine_kwargs Any

Forwarded to :meth:~oa_configurator.resolver.ResolvedDatabase.create_engine.

{}

resolve_fields classmethod

resolve_fields(
    config: StackConfig,
    *,
    set_dict: dict[str, Any],
    interactive: bool,
) -> dict[str, Any]

Resolve this package's own fields: flag (--set or the field's own auto-generated flag), then stored, then an interactive prompt (seeded with the stored value as its default when one exists), recursing into any RefTo-marked field via the generic resolver machinery in :mod:~oa_configurator.resolver.

A RefTo-marked field's set_dict value may also be a nested dict instead of a plain string, built from repeated --set field.subfield=value CLI flags. Using a nested dict creates the target entry from those flags in the same call, instead of requiring it to already exist.

Parameters:

Name Type Description Default
config StackConfig

The current StackConfig, used to read any already-stored extras.

required
set_dict dict[str, Any]

Flag values, keyed by field name. Checked first. A value is either the field's plain string value, or (for a RefTo field only) a nested dict of the target's own field values.

required
interactive bool

Whether to prompt for fields not covered by set_dict or stored config, and whether an already-stored value is offered as a re-promptable default rather than reused silently. Non-interactively, fields covered by neither are simply omitted (they fall back to the field's own pydantic default when the config class is loaded).

required

Returns:

Type Description
dict[str, Any]

Resolved extra field values, keyed by field name.

Raises:

Type Description
Exit

If a nested --set creation (see above) is missing a required field of the target it's creating, non-interactively.

run_configure classmethod

run_configure(
    set_dict: dict[str, Any], *, interactive: bool
) -> None

Run the configure flow for this package: resolve every one of its own fields (see :meth:resolve_fields) and save to the active stack config file.

to_extra_dict

to_extra_dict() -> dict[str, Any]

Serialize back to the dict stored under [tools.<tool_name>].