Skip to content

Templates

templates

Template path resolution for Copier scaffold templates.

TemplateInfo

Bases: BaseModel

Template metadata.

Note: type: ignore[explicit-any] flags pydantic BaseModel internals (third-party).

Source code in packages/axm-init/src/axm_init/core/templates.py
Python
class TemplateInfo(BaseModel):  # type: ignore[explicit-any]
    """Template metadata.

    Note: ``type: ignore[explicit-any]`` flags pydantic ``BaseModel``
    internals (third-party).
    """

    name: str
    description: str
    path: Path

    model_config = ConfigDict(extra="forbid")

TemplateLayer

Bases: BaseModel

One ordered Copier template application.

Source code in packages/axm-init/src/axm_init/core/templates.py
Python
class TemplateLayer(BaseModel):  # type: ignore[explicit-any]
    """One ordered Copier template application."""

    name: str
    path: Path
    data: dict[str, str]

    model_config = ConfigDict(extra="forbid", frozen=True)

TemplateType

Bases: StrEnum

Available scaffold template types.

Source code in packages/axm-init/src/axm_init/core/templates.py
Python
class TemplateType(StrEnum):
    """Available scaffold template types."""

    STANDALONE = "standalone"
    WORKSPACE = "workspace"
    MEMBER = "member"
    PAPER = "paper"
    EXPERIMENT = "experiment"
    LEARNING = "learning"

get_template_path(template_type=TemplateType.STANDALONE, framework=Framework.PYTHON)

Return path to a bundled Copier template for a template type + framework.

Parameters:

Name Type Description Default
template_type TemplateType

Type of template to look up.

STANDALONE
framework Framework | None

Ecosystem the template targets (default python keeps the historical single-argument behaviour).

PYTHON

Returns:

Type Description
Path

Path to the bundled template directory.

Raises:

Type Description
KeyError

If no template exists for the (type, framework) combination.

Source code in packages/axm-init/src/axm_init/core/templates.py
Python
def get_template_path(
    template_type: TemplateType = TemplateType.STANDALONE,
    framework: Framework | None = Framework.PYTHON,
) -> Path:
    """Return path to a bundled Copier template for a template type + framework.

    Args:
        template_type: Type of template to look up.
        framework: Ecosystem the template targets (default ``python`` keeps the
            historical single-argument behaviour).

    Returns:
        Path to the bundled template directory.

    Raises:
        KeyError: If no template exists for the (type, framework) combination.
    """
    if template_type == TemplateType.PAPER:
        raise ValueError("Paper scaffolding is owned by axm-lab; use paper_scaffold.")
    resolved_framework = framework or Framework.PYTHON
    dir_name = _TEMPLATE_DIRS[(template_type, resolved_framework)]
    return Path(str(TEMPLATES_PKG / dir_name))

template_chain(template_type, framework, *, member, existing=False)

Resolve the ordered Copier layers for a scaffold request.

Source code in packages/axm-init/src/axm_init/core/templates.py
Python
def template_chain(
    template_type: TemplateType,
    framework: Framework | None,
    *,
    member: bool,
    existing: bool = False,
) -> tuple[TemplateLayer, ...]:
    """Resolve the ordered Copier layers for a scaffold request."""
    if template_type in (TemplateType.LEARNING, TemplateType.EXPERIMENT):
        from axm_init.scaffolding import ScaffoldRequest, _provider_layers

        return _provider_layers(
            ScaffoldRequest(template_type.value, framework, member, existing)
        )
    return (
        TemplateLayer(
            name=template_type.value,
            path=get_template_path(template_type, framework),
            data={},
        ),
    )