sqlmesh.core.environment API documentation

Edit on GitHub

# sqlmesh.core.environment

View Source

     1from __future__ import annotations
     2
     3import json
     4import typing as t
     5
     6from pydantic import validator
     7
     8from sqlmesh.core.snapshot import SnapshotTableInfo
     9from sqlmesh.utils import word_characters_only
    10from sqlmesh.utils.date import TimeLike
    11from sqlmesh.utils.pydantic import PydanticModel
    12
    13
    14class Environment(PydanticModel):
    15    """Represents an isolated environment.
    16
    17    Environments are isolated workspaces that hold pointers to physical tables.
    18    """
    19
    20    name: str
    21    snapshots: t.List[SnapshotTableInfo]
    22    start_at: TimeLike
    23    end_at: t.Optional[TimeLike]
    24    plan_id: str
    25    previous_plan_id: t.Optional[str]
    26    expiration_ts: t.Optional[int]
    27
    28    @validator("snapshots", pre=True)
    29    @classmethod
    30    def _convert_snapshots(cls, v: str | t.List[SnapshotTableInfo]) -> t.List[SnapshotTableInfo]:
    31        if isinstance(v, str):
    32            return [SnapshotTableInfo.parse_obj(obj) for obj in json.loads(v)]
    33        return v
    34
    35    @validator("name", pre=True)
    36    @classmethod
    37    def _normalize_name(cls, v: str) -> str:
    38        return word_characters_only(v).lower()
    39
    40    @t.overload
    41    @classmethod
    42    def normalize_name(cls, v: str) -> str:
    43        ...
    44
    45    @t.overload
    46    @classmethod
    47    def normalize_name(cls, v: Environment) -> Environment:
    48        ...
    49
    50    @classmethod
    51    def normalize_name(cls, v: str | Environment) -> str | Environment:
    52        """
    53        Normalizes the environment name so we create names that are valid names for database objects.
    54        This means alphanumeric and underscores only. Invalid characters are replaced with underscores.
    55        """
    56        if isinstance(v, Environment):
    57            return v
    58        if not isinstance(v, str):
    59            raise TypeError(f"Expected str or Environment, got {type(v).__name__}")
    60        return cls._normalize_name(v)

class Environment(sqlmesh.utils.pydantic.PydanticModel): View Source

    15class Environment(PydanticModel):
    16    """Represents an isolated environment.
    17
    18    Environments are isolated workspaces that hold pointers to physical tables.
    19    """
    20
    21    name: str
    22    snapshots: t.List[SnapshotTableInfo]
    23    start_at: TimeLike
    24    end_at: t.Optional[TimeLike]
    25    plan_id: str
    26    previous_plan_id: t.Optional[str]
    27    expiration_ts: t.Optional[int]
    28
    29    @validator("snapshots", pre=True)
    30    @classmethod
    31    def _convert_snapshots(cls, v: str | t.List[SnapshotTableInfo]) -> t.List[SnapshotTableInfo]:
    32        if isinstance(v, str):
    33            return [SnapshotTableInfo.parse_obj(obj) for obj in json.loads(v)]
    34        return v
    35
    36    @validator("name", pre=True)
    37    @classmethod
    38    def _normalize_name(cls, v: str) -> str:
    39        return word_characters_only(v).lower()
    40
    41    @t.overload
    42    @classmethod
    43    def normalize_name(cls, v: str) -> str:
    44        ...
    45
    46    @t.overload
    47    @classmethod
    48    def normalize_name(cls, v: Environment) -> Environment:
    49        ...
    50
    51    @classmethod
    52    def normalize_name(cls, v: str | Environment) -> str | Environment:
    53        """
    54        Normalizes the environment name so we create names that are valid names for database objects.
    55        This means alphanumeric and underscores only. Invalid characters are replaced with underscores.
    56        """
    57        if isinstance(v, Environment):
    58            return v
    59        if not isinstance(v, str):
    60            raise TypeError(f"Expected str or Environment, got {type(v).__name__}")
    61        return cls._normalize_name(v)

Represents an isolated environment.

Environments are isolated workspaces that hold pointers to physical tables.

@classmethod
def normalize_name( cls, v: str | sqlmesh.core.environment.Environment) -> str | sqlmesh.core.environment.Environment: View Source

    51    @classmethod
    52    def normalize_name(cls, v: str | Environment) -> str | Environment:
    53        """
    54        Normalizes the environment name so we create names that are valid names for database objects.
    55        This means alphanumeric and underscores only. Invalid characters are replaced with underscores.
    56        """
    57        if isinstance(v, Environment):
    58            return v
    59        if not isinstance(v, str):
    60            raise TypeError(f"Expected str or Environment, got {type(v).__name__}")
    61        return cls._normalize_name(v)

Normalizes the environment name so we create names that are valid names for database objects. This means alphanumeric and underscores only. Invalid characters are replaced with underscores.

##### Inherited Members

pydantic.main.BaseModel
  BaseModel
  parse_obj
  parse_raw
  parse_file
  from_orm
  construct
  copy
  schema
  schema_json
  validate
  update_forward_refs
sqlmesh.utils.pydantic.PydanticModel
  Config
  dict
  json
  missing_required_fields
  extra_fields
  all_fields
  required_fields