path
¶
ExistingPathRelativeToInput = Annotated[pathlib.Path, pydantic.AfterValidator(lambda path, info: resolve_relative_path(path, info, must_exist=True))]
¶
PlannedPathRelativeToInput = Annotated[pathlib.Path, pydantic.AfterValidator(lambda path, info: resolve_relative_path(path, info, must_exist=False)), pydantic.PlainSerializer(serialize_path)]
¶
resolve_relative_path(path, info, *, must_exist=True)
¶
Convert relative path to absolute path based on input file location.
Why
Users reference files like photo: profile.jpg relative to their CV
YAML. This validator resolves such paths to absolute form and validates
existence, enabling file access during rendering.
Example
Parameters:
-
path(Path) –Path to resolve (may be relative or absolute).
-
info(ValidationInfo) –Validation context containing input file path.
-
must_exist(bool, default:True) –Whether to raise error if path doesn't exist.
Returns:
-
Path–Absolute path.