Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore(deps): bump pydantic from 1.10.9 to 2.6.2 #234

Merged
merged 3 commits into from
Mar 3, 2024
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,4 @@ dmypy.json
.vscode/

# Testmon
.testmondata
.testmondata*
9 changes: 3 additions & 6 deletions komposer/types/base.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
from typing import cast

import stringcase
from pydantic import BaseModel
from pydantic import BaseModel, ConfigDict


def to_camel(string: str) -> str:
return cast(str, stringcase.camelcase(string))


class ImmutableBaseModel(BaseModel):
class Config:
allow_mutation = False
model_config = ConfigDict(frozen=True)


class CamelCaseImmutableBaseModel(BaseModel):
class Config:
allow_mutation = False
alias_generator = to_camel
model_config = ConfigDict(frozen=True, alias_generator=to_camel)
11 changes: 7 additions & 4 deletions komposer/types/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from pathlib import Path
from typing import Any, Optional

from pydantic import validator
from pydantic import field_validator

from komposer.types.base import ImmutableBaseModel
from komposer.utils import load_yaml
Expand Down Expand Up @@ -44,20 +44,23 @@ class Context(ImmutableBaseModel):
deployment: DeploymentContext
ingress: IngressContext

@validator("project_name")
@field_validator("project_name")
@classmethod
def project_name_matches_kubernetes_name(cls, value: Optional[str]) -> Optional[str]:
if value is not None:
ensure_lowercase_kebab(value)

return value

@validator("branch_name")
@field_validator("branch_name")
@classmethod
def branch_name_matches_kubernetes_name(cls, value: str) -> str:
ensure_lowercase_kebab(value)

return value

@validator("repository_name")
@field_validator("repository_name")
@classmethod
def repository_name_matches_kubernetes_name(cls, value: str) -> str:
ensure_lowercase_kebab(value)

Expand Down
8 changes: 4 additions & 4 deletions komposer/types/kubernetes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

from abc import ABC
from collections.abc import Iterable
from enum import Enum, unique
from io import StringIO
Expand Down Expand Up @@ -68,7 +69,7 @@ def from_context_with_name(
)


class Item(CamelCaseImmutableBaseModel):
class Item(CamelCaseImmutableBaseModel, ABC):
api_version: str
kind: str
metadata: Metadata
Expand Down Expand Up @@ -117,7 +118,7 @@ def from_env_file(

class EnvironmentVariable(CamelCaseImmutableBaseModel):
name: str
value: Optional[str]
value: Optional[str] = None

@staticmethod
def from_string(string: str) -> Iterable[EnvironmentVariable]:
Expand Down Expand Up @@ -255,5 +256,4 @@ class Ingress(Item):
class List(CamelCaseImmutableBaseModel):
api_version: Literal["v1"] = "v1"
kind: Literal["List"] = "List"
# We should be able to use Field(..., discriminator="kind") here
items: list[Item] = []
items: list[Union[ConfigMap, Deployment, Service, Ingress]] = []
2 changes: 1 addition & 1 deletion komposer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ def command_to_args(command: Optional[Union[str, list[str]]]) -> Optional[list[s


def as_json_object(type_: BaseModel) -> dict[str, Any]:
return cast(dict[str, Any], json.loads(type_.json(by_alias=True)))
return cast(dict[str, Any], json.loads(type_.model_dump_json(by_alias=True)))
165 changes: 117 additions & 48 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ packages = [{ include = "komposer" }]
[tool.poetry.dependencies]
python = "^3.9"
click = "^8.1.3"
pydantic = "^1.9.1"
pydantic = ">=1.9.1,<3.0.0"
PyYAML = "^6.0"
stringcase = "^1.2.0"
python-dotenv = ">=0.20"
Expand Down