Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions dlccore/project/validation/baseline/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#
# DeepLabCut Toolbox (deeplabcut.org)
# © A. & M.W. Mathis Labs
# https://github.com/DeepLabCut/dlccore
#
# Contributors:
# https://github.com/DeepLabCut/dlccore/graphs/contributors
#
# Licensed under GNU Lesser General Public License v3.0
#

from .api import (
iter_baseline_check_registrations,
run_baseline_checks,
)
from .base import (
BaselineValidator,
)

__all__ = [
"BaselineValidator",
"iter_baseline_check_registrations",
"run_baseline_checks",
]
44 changes: 44 additions & 0 deletions dlccore/project/validation/baseline/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#
# DeepLabCut Toolbox (deeplabcut.org)
# © A. & M.W. Mathis Labs
# https://github.com/DeepLabCut/dlccore
#
# Contributors:
# https://github.com/DeepLabCut/dlccore/graphs/contributors
#
# Licensed under GNU Lesser General Public License v3.0
#

from __future__ import annotations

from dlccore.project.schemas.base.findings import Finding
from dlccore.project.schemas.snapshots import ProjectSnapshot
from dlccore.project.validation.context import ValidationContext

from .base import BaselineCheckRegistration
from .checklist import BASELINE_CHECKS


def iter_baseline_check_registrations() -> tuple[BaselineCheckRegistration, ...]:
"""Return built-in baseline checks in execution order."""

return BASELINE_CHECKS


def run_baseline_checks(
snapshot: ProjectSnapshot,
context: ValidationContext | None,
) -> tuple[Finding, ...]:
"""Run all built-in baseline checks in execution order."""

findings: list[Finding] = []

for registration in BASELINE_CHECKS:
findings.extend(
registration.validator(
snapshot,
context,
)
)

return tuple(findings)
36 changes: 36 additions & 0 deletions dlccore/project/validation/baseline/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#
# DeepLabCut Toolbox (deeplabcut.org)
# © A. & M.W. Mathis Labs
# https://github.com/DeepLabCut/dlccore
#
# Contributors:
# https://github.com/DeepLabCut/dlccore/graphs/contributors
#
# Licensed under GNU Lesser General Public License v3.0
#

from __future__ import annotations

from collections.abc import Callable
from dataclasses import dataclass

from dlccore.project.schemas.base.findings import Finding
from dlccore.project.schemas.snapshots import ProjectSnapshot
from dlccore.project.validation.context import ValidationContext

BaselineValidator = Callable[
[
ProjectSnapshot,
ValidationContext | None,
],
tuple[Finding, ...],
]


@dataclass(frozen=True)
class BaselineCheckRegistration:
"""One automatic, lightweight project-level check."""

code: str
description: str
validator: BaselineValidator
92 changes: 92 additions & 0 deletions dlccore/project/validation/baseline/checklist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#
# DeepLabCut Toolbox (deeplabcut.org)
# © A. & M.W. Mathis Labs
# https://github.com/DeepLabCut/dlccore
#
# Contributors:
# https://github.com/DeepLabCut/dlccore/graphs/contributors
#
# Licensed under GNU Lesser General Public License v3.0
#

from __future__ import annotations

from dlccore.project.schemas.base.findings import Finding
from dlccore.project.schemas.snapshots import ProjectSnapshot
from dlccore.project.validation.baseline.base import (
BaselineCheckRegistration,
)
from dlccore.project.validation.context import ValidationContext
from dlccore.project.validation.deeplabcut.project_path import (
validate_project_path,
)
from dlccore.project.validation.structure import (
validate_project_structure,
)


def _config_validation_already_applied(
snapshot: ProjectSnapshot,
context: ValidationContext | None,
) -> tuple[Finding, ...]:
"""No-op empty validator: config is validated eagerly, before a snapshot exists.

This registration exists only so ``get_project_manager_capabilities()``
accurately advertises that config validation always happens.

``inspect_project`` reads and validates the config file via
``validate_project_config`` before ``ProjectSnapshot.from_project`` runs,
so its findings are already present in ``snapshot.findings`` by the time
baseline checks run here.
"""

del snapshot, context

return ()


def _validate_structure(
snapshot: ProjectSnapshot,
context: ValidationContext | None,
) -> tuple[Finding, ...]:
"""Run baseline structural validation."""

del context

return validate_project_structure(
snapshot.project,
project_root=snapshot.project_root,
)


def _validate_config_project_path(
snapshot: ProjectSnapshot,
context: ValidationContext | None,
) -> tuple[Finding, ...]:
"""Compare declared and inspected project paths when applicable."""

del snapshot

if context is None:
return ()

return validate_project_path(context)


BASELINE_CHECKS = (
BaselineCheckRegistration(
code="PROJECT_CONFIG_VALIDATION",
description=("Reads and validates config.yaml against the canonical schema."),
validator=_config_validation_already_applied,
),
BaselineCheckRegistration(
code="PROJECT_STRUCTURE",
description=("Checks required-node presence, filesystem type, and readability."),
validator=_validate_structure,
),
BaselineCheckRegistration(
code="PROJECT_CONFIG_PATH_RELATIONSHIP",
description=("Compares the project path declared by a valid config with the inspected project root."),
validator=_validate_config_project_path,
),
)
28 changes: 28 additions & 0 deletions tests/project/validation/test_baseline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#
# DeepLabCut Toolbox (deeplabcut.org)
# © A. & M.W. Mathis Labs
# https://github.com/DeepLabCut/dlccore
#
# Contributors:
# https://github.com/DeepLabCut/dlccore/graphs/contributors
#
# Licensed under GNU Lesser General Public License v3.0
#


from dlccore.project.validation.baseline import (
iter_baseline_check_registrations,
)


def test_baseline_check_registrations_are_well_formed() -> None:
registrations = iter_baseline_check_registrations()
codes = tuple(registration.code for registration in registrations)

assert registrations
assert len(codes) == len(set(codes))

for registration in registrations:
assert registration.code
assert registration.description
assert callable(registration.validator)
Loading