Skip to content
Merged
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
39 changes: 2 additions & 37 deletions src/usethis/_file/yaml/io_.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,47 +37,12 @@
from collections.abc import Generator, Sequence
from io import TextIOWrapper
from pathlib import Path
from types import NoneType
from typing import TypeAlias

from ruamel.yaml.comments import (
CommentedOrderedMap,
CommentedSeq,
CommentedSet,
TaggedScalar,
)
from ruamel.yaml.scalarbool import ScalarBoolean
from ruamel.yaml.scalarfloat import ScalarFloat
from ruamel.yaml.scalarint import BinaryInt, HexCapsInt, HexInt, OctalInt, ScalarInt
from ruamel.yaml.scalarstring import FoldedScalarString, LiteralScalarString
from ruamel.yaml.timestamp import TimeStamp

from typing_extensions import Self

from usethis._file.yaml.typing_ import YAMLLiteral
from usethis._io import Key

YAMLLiteral: TypeAlias = (
NoneType
| bool
| float
| int
| str
| BinaryInt
| FoldedScalarString
| HexInt
| HexCapsInt
| LiteralScalarString
| OctalInt
| ScalarBoolean
| ScalarFloat
| ScalarInt
| TaggedScalar
| TimeStamp
| CommentedSeq
| CommentedSet
| CommentedOrderedMap
| CommentedMap
)


class YAMLFileManager(KeyValueFileManager):
"""An abstract class for managing YAML files."""
Expand Down
38 changes: 38 additions & 0 deletions src/usethis/_file/yaml/typing_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from types import NoneType
from typing import TypeAlias

from ruamel.yaml.comments import (
CommentedMap,
CommentedOrderedMap,
CommentedSeq,
CommentedSet,
TaggedScalar,
)
from ruamel.yaml.scalarbool import ScalarBoolean
from ruamel.yaml.scalarfloat import ScalarFloat
from ruamel.yaml.scalarint import BinaryInt, HexCapsInt, HexInt, OctalInt, ScalarInt
from ruamel.yaml.scalarstring import FoldedScalarString, LiteralScalarString
from ruamel.yaml.timestamp import TimeStamp

YAMLLiteral: TypeAlias = (
NoneType
| bool
| float
| int
| str
| BinaryInt
| FoldedScalarString
| HexInt
| HexCapsInt
| LiteralScalarString
| OctalInt
| ScalarBoolean
| ScalarFloat
| ScalarInt
| TaggedScalar
| TimeStamp
| CommentedSeq
| CommentedSet
| CommentedOrderedMap
| CommentedMap
)
2 changes: 1 addition & 1 deletion src/usethis/_file/yaml/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
if TYPE_CHECKING:
from typing import Any

from usethis._file.yaml.io_ import YAMLLiteral
from usethis._file.yaml.typing_ import YAMLLiteral


def update_ruamel_yaml_map(
Expand Down
3 changes: 2 additions & 1 deletion src/usethis/_integrations/ci/bitbucket/yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
if TYPE_CHECKING:
from pydantic import BaseModel

from usethis._integrations.pydantic.dump import ModelRepresentation
from usethis._integrations.pydantic.typing_ import ModelRepresentation


ORDER_BY_CLS: dict[type[BaseModel], list[str]] = {
schema.PipelinesConfiguration: ["image", "clone", "definitions"],
Expand Down
2 changes: 1 addition & 1 deletion src/usethis/_integrations/pre_commit/yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
if TYPE_CHECKING:
from pydantic import BaseModel

from usethis._integrations.pydantic.dump import ModelRepresentation
from usethis._integrations.pydantic.typing_ import ModelRepresentation

ORDER_BY_CLS: dict[type[BaseModel], list[str]] = {}

Expand Down
13 changes: 1 addition & 12 deletions src/usethis/_integrations/pydantic/dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,7 @@
from pydantic import BaseModel, RootModel

if TYPE_CHECKING:
from typing import TypeAlias

from usethis._file.yaml.io_ import YAMLLiteral

ModelLiteral: TypeAlias = bool | int | float | str
ModelRepresentation: TypeAlias = (
ModelLiteral
| dict[str, "ModelRepresentation"]
| list["ModelRepresentation"]
| BaseModel
| YAMLLiteral
)
from usethis._integrations.pydantic.typing_ import ModelLiteral, ModelRepresentation


class _FillValue:
Expand Down
14 changes: 14 additions & 0 deletions src/usethis/_integrations/pydantic/typing_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from typing import TypeAlias

from pydantic import BaseModel

from usethis._file.yaml.typing_ import YAMLLiteral

ModelLiteral: TypeAlias = bool | int | float | str
ModelRepresentation: TypeAlias = (
ModelLiteral
| dict[str, "ModelRepresentation"]
| list["ModelRepresentation"]
| BaseModel
| YAMLLiteral
)