Skip to content

types.py

Complex types, annotations, validators.

AbsolutePath

Bases: Path

Require absolute paths in an argument.

Source code in copier/types.py
85
86
87
88
89
90
91
class AbsolutePath(Path):
    """Require absolute paths in an argument."""

    @classmethod
    def __get_validators__(cls) -> "CallableGenerator":
        yield path_validator
        yield path_is_absolute

AllowArbitraryTypes

Allow any type for this class.

Source code in copier/types.py
54
55
56
57
class AllowArbitraryTypes:
    """Allow any type for this class."""

    arbitrary_types_allowed = True

RelativePath

Bases: Path

Require relative paths in an argument.

Source code in copier/types.py
93
94
95
96
97
98
99
class RelativePath(Path):
    """Require relative paths in an argument."""

    @classmethod
    def __get_validators__(cls) -> "CallableGenerator":
        yield path_validator
        yield path_is_relative

path_is_absolute(value)

Require absolute paths in an argument.

Source code in copier/types.py
61
62
63
64
65
66
67
def path_is_absolute(value: Path) -> Path:
    """Require absolute paths in an argument."""
    if not value.is_absolute():
        from .errors import PathNotAbsoluteError

        raise PathNotAbsoluteError(path=value)
    return value

path_is_relative(value)

Require relative paths in an argument.

Source code in copier/types.py
70
71
72
73
74
75
76
def path_is_relative(value: Path) -> Path:
    """Require relative paths in an argument."""
    if value.is_absolute():
        from .errors import PathNotRelativeError

        raise PathNotRelativeError(path=value)
    return value