Source code for dartfx.cdif.codegen.config

"""Configuration and profile specifications for the CDIF code generator."""

from __future__ import annotations

import os
from dataclasses import dataclass
from pathlib import Path


[docs] @dataclass(frozen=True) class ProfileSpec: """Metadata describing a CDIF profile and its upstream artifact paths.""" key: str module_name: str root_class_name: str | None mixin_class_name: str | None profile_uris: tuple[str, ...] schema_path: str frame_path: str shacl_path: str base_classes: tuple[str, ...] = ("CdifBaseModel",) description: str = ""
PROFILE_SPECS: tuple[ProfileSpec, ...] = ( ProfileSpec( key="core", module_name="core", root_class_name="CdifCoreDataset", mixin_class_name=None, profile_uris=( "https://w3id.org/cdif/core/2.0", "https://w3id.org/cdif/core/1.1", "https://w3id.org/cdif/core/1.0", ), schema_path="profile-core/cdifCoreStructuredSchema.json", frame_path="profile-core/cdifCore-frame.jsonld", shacl_path="validation/ShaclValidation/CDIF-Discovery-Shapes.ttl", base_classes=("CdifBaseModel",), description="CDIF Core metadata profile (schema:Dataset).", ), ProfileSpec( key="discovery", module_name="discovery", root_class_name="CdifDiscoveryDataset", mixin_class_name="CdifDiscoveryMixin", profile_uris=( "https://w3id.org/cdif/discovery/2.0", "https://w3id.org/cdif/discovery/1.1", "https://w3id.org/cdif/discovery/1.0", ), schema_path="profile-discovery/cdifDiscoveryStructuredSchema.json", frame_path="profile-discovery/cdifDiscovery-frame.jsonld", shacl_path="validation/ShaclValidation/CDIF-Discovery-Shapes.ttl", base_classes=("CdifCoreDataset", "CdifDiscoveryMixin"), description=( "CDIF Discovery profile extending Core with measurement, variable, spatial, temporal, and quality." ), ), ProfileSpec( key="data_description", module_name="datadescription", root_class_name="CdifDataDescriptionDataset", mixin_class_name="CdifDataDescriptionMixin", profile_uris=( "https://w3id.org/cdif/data_description/2.0", "https://w3id.org/cdif/data_description/1.1", "https://w3id.org/cdif/data_description/1.0", ), schema_path="profile-datadescription/cdifDataDescriptionStructuredSchema.json", frame_path="profile-datadescription/cdifDataDescription-frame.jsonld", shacl_path="validation/ShaclValidation/CDIF-DataDescription-Shapes.ttl", base_classes=("CdifDiscoveryDataset", "CdifDataDescriptionMixin"), description=( "CDIF Data Description profile extending Discovery with variableMeasured, physical mapping, and stats." ), ), ProfileSpec( key="data_structure", module_name="datastructure", root_class_name=None, mixin_class_name=None, profile_uris=( "https://w3id.org/cdif/data_structure/2.0", "https://w3id.org/cdif/data_structure/1.1", "https://w3id.org/cdif/data_structure/1.0", ), schema_path="profile-datastructure/cdifDataStructureStructuredSchema.json", frame_path="profile-datastructure/CDIFDataStructure-frame.jsonld", shacl_path="validation/ShaclValidation/CDIF-DataStructure-Shapes.ttl", base_classes=(), description="CDIF Data Structure profile (DDI-CDI structural components, keys, and represented variables).", ), ProfileSpec( key="provenance", module_name="provenance", root_class_name="CdifProvenanceDataset", mixin_class_name="CdifProvenanceMixin", profile_uris=( "https://w3id.org/cdif/provenance/2.0", "https://w3id.org/cdif/provenance/1.1", "https://w3id.org/cdif/provenance/1.0", ), schema_path="profile-provenance/cdifProvenanceStructuredSchema.json", frame_path="profile-provenance/cdifProvenance-frame.jsonld", shacl_path="validation/ShaclValidation/CDIF-Provenance-Shapes.ttl", base_classes=("CdifCoreDataset", "CdifProvenanceMixin"), description=( "CDIF Provenance profile extending Core with prov:wasGeneratedBy activities, instruments, and HowTo plans." ), ), ProfileSpec( key="manifest", module_name="manifest", root_class_name="CdifManifestDataset", mixin_class_name="CdifManifestMixin", profile_uris=( "https://w3id.org/cdif/manifest/2.0", "https://w3id.org/cdif/manifest/1.1", "https://w3id.org/cdif/manifest/1.0", ), schema_path="profile-manifest/cdifManifestStructuredSchema.json", frame_path="profile-manifest/cdifManifest-frame.jsonld", shacl_path="validation/ShaclValidation/CDIF-Manifest-Shapes.ttl", base_classes=("CdifCoreDataset", "CdifManifestMixin"), description="CDIF Manifest profile extending Core with package schema:hasPart resources and archive parts.", ), ProfileSpec( key="codelist", module_name="codelist", root_class_name="CdifCodelist", mixin_class_name=None, profile_uris=( "https://w3id.org/cdif/codelist/2.0", "https://w3id.org/cdif/codelist/1.1", "https://w3id.org/cdif/codelist/1.0", ), schema_path="profile-codelist/CDIFCodelistProfileStructuredSchema.json", frame_path="profile-codelist/CDIFCodelist-frame.jsonld", shacl_path="profile-codelist/rules.shacl", base_classes=("CdifBaseModel",), description="CDIF Codelist profile (skos:ConceptScheme / schema:DefinedTermSet).", ), ProfileSpec( key="complete", module_name="complete", root_class_name="CdifCompleteDataset", mixin_class_name=None, profile_uris=( "https://w3id.org/cdif/complete/2.0", "https://w3id.org/cdif/complete/1.1", "https://w3id.org/cdif/complete/1.0", "https://w3id.org/cdif/bbr/metadata/profiles/cdifCompositeProfile/cdifComplete", ), schema_path="validation/CDIFCompleteSchema.json", frame_path="validation/CDIF-frame-2026.jsonld", shacl_path="validation/ShaclValidation/CDIF-Complete-Shapes.ttl", base_classes=( "CdifDataDescriptionDataset", "CdifProvenanceMixin", "CdifManifestMixin", ), description=( "CDIF Complete composite profile combining Core, Discovery, Data Description, Provenance, and Manifest." ), ), ) PROFILE_SPECS_BY_KEY: dict[str, ProfileSpec] = {spec.key: spec for spec in PROFILE_SPECS} CONTEXT_PATH = "validation/CDIF-context-2026.jsonld" DISCOVERY_COMPOSITE_SCHEMA_PATH = "validation/CDIFDiscoverySchema.json" DATA_DESCRIPTION_COMPOSITE_SCHEMA_PATH = "validation/CDIFDataDescriptionSchema.json" PROVENANCE_ACTIVITIES_TTL_PATH = "profile-provenance/vocabularies/CDIF_Activities.ttl"
[docs] def resolve_cdif_root(cdif_root: Path | str | None = None) -> Path: """Resolve the local ``git-cdif`` directory path. Resolution order: 1. Explicit ``cdif_root`` argument. 2. ``CDIF_ROOT`` environment variable. 3. Sibling ``git-cdif`` directory next to ``git-dartfx`` (monorepo layout). """ if cdif_root is not None: return Path(cdif_root).expanduser().resolve() env_val = os.environ.get("CDIF_ROOT") if env_val: return Path(env_val).expanduser().resolve() # Check common monorepo sibling locations here = Path(__file__).resolve() for parent in here.parents: candidate = parent / "git-cdif" if candidate.is_dir(): return candidate return Path("/Users/pascal/Library/CloudStorage/Dropbox/git-cdif")
[docs] def default_models_output_dir() -> Path: """Return the default ``src/dartfx/cdif/models`` output directory.""" return Path(__file__).resolve().parent.parent / "models"
__all__ = [ "CONTEXT_PATH", "DATA_DESCRIPTION_COMPOSITE_SCHEMA_PATH", "DISCOVERY_COMPOSITE_SCHEMA_PATH", "PROFILE_SPECS", "PROFILE_SPECS_BY_KEY", "PROVENANCE_ACTIVITIES_TTL_PATH", "ProfileSpec", "default_models_output_dir", "resolve_cdif_root", ]