diff --git a/agipack/config.py b/agipack/config.py index e9a59b7..b5f58f4 100644 --- a/agipack/config.py +++ b/agipack/config.py @@ -4,7 +4,7 @@ from typing import Dict, List, Optional, Tuple, Union import yaml -from pydantic import Extra, validator +from pydantic import ConfigDict, field_validator from pydantic.dataclasses import dataclass logger = logging.getLogger(__name__) @@ -28,13 +28,7 @@ def is_leaf(self) -> bool: return not len(self.children) -class _ForbidExtrasConfig: - """Pydantic config to forbid extra fields.""" - - extra = Extra.forbid - - -@dataclass(config=_ForbidExtrasConfig) +@dataclass(config=ConfigDict(extra="forbid")) class ImageConfig: """AGIPack configuration for a docker target specified in `agibuild.yaml` @@ -128,7 +122,7 @@ def is_base_image(self) -> bool: """Check if the base target is root / does not have a parent.""" return ":" in self.base - @validator("python", pre=True) + @field_validator("python", mode="before") def validate_python_version(cls, python) -> str: """Validate the python version.""" if not isinstance(python, str): @@ -137,7 +131,7 @@ def validate_python_version(cls, python) -> str: raise ValueError(f"Python version must be >= 3.6 (found {python})") return python - @validator("add", pre=True) + @field_validator("add", mode="before") def validate_add(cls, items) -> Tuple[str, str]: """Validate the add command.""" for item in items: @@ -150,7 +144,7 @@ def validate_add(cls, items) -> Tuple[str, str]: raise ValueError(f"`add` {from_path} does not exist") return items - @validator("command", pre=True) + @field_validator("command", mode="before") def validate_command_version(cls, cmd) -> List[str]: """Validate the command.""" if isinstance(cmd, str): @@ -159,6 +153,16 @@ def validate_command_version(cls, cmd) -> List[str]: pass return cmd + @field_validator("env", mode="before") + def validate_env(cls, env) -> Dict[str, str]: + """Validate the environment variables.""" + if not isinstance(env, dict): + raise ValueError(f"`env` must be a dictionary (type={type(env)})") + for key, value in env.items(): + if isinstance(value, int): + env[key] = str(value) + return env + @dataclass class AGIPackConfig: @@ -204,7 +208,7 @@ def is_prod(self) -> bool: """Check if the configuration is for production.""" return self.prod - @validator("images") + @field_validator("images") def validate_python_dependencies_for_nonbase_images(cls, images): """Validate that all images have the same python dependency as the base image.""" py_version = None diff --git a/agipack/version.py b/agipack/version.py index d38c350..d3ec452 100644 --- a/agipack/version.py +++ b/agipack/version.py @@ -1 +1 @@ -__version__ = "0.1.19" +__version__ = "0.2.0" diff --git a/examples/generated/Dockerfile-base-cpu b/examples/generated/Dockerfile-base-cpu index 7aa360c..f27bfac 100644 --- a/examples/generated/Dockerfile-base-cpu +++ b/examples/generated/Dockerfile-base-cpu @@ -1,5 +1,5 @@ # >>>>>>>>>>>>>>>>>>>>>>>>>>> -# Auto-generated by agi-pack (version=0.1.19). +# Auto-generated by agi-pack (version=0.2.0). FROM debian:buster-slim AS base-cpu # Setup environment variables diff --git a/examples/generated/Dockerfile-base-cu118 b/examples/generated/Dockerfile-base-cu118 index b6495f7..7fb9337 100644 --- a/examples/generated/Dockerfile-base-cu118 +++ b/examples/generated/Dockerfile-base-cu118 @@ -1,5 +1,5 @@ # >>>>>>>>>>>>>>>>>>>>>>>>>>> -# Auto-generated by agi-pack (version=0.1.19). +# Auto-generated by agi-pack (version=0.2.0). FROM nvidia/cuda:11.8.0-base-ubuntu22.04 AS base-gpu # Setup environment variables diff --git a/examples/generated/Dockerfile-builder b/examples/generated/Dockerfile-builder index 5dbf080..973d7ec 100644 --- a/examples/generated/Dockerfile-builder +++ b/examples/generated/Dockerfile-builder @@ -1,5 +1,5 @@ # >>>>>>>>>>>>>>>>>>>>>>>>>>> -# Auto-generated by agi-pack (version=0.1.19). +# Auto-generated by agi-pack (version=0.2.0). FROM debian:buster-slim AS agipack-builder # Setup environment variables diff --git a/examples/generated/Dockerfile-multistage b/examples/generated/Dockerfile-multistage index 9ba8790..8ffa576 100644 --- a/examples/generated/Dockerfile-multistage +++ b/examples/generated/Dockerfile-multistage @@ -1,5 +1,5 @@ # >>>>>>>>>>>>>>>>>>>>>>>>>>> -# Auto-generated by agi-pack (version=0.1.19). +# Auto-generated by agi-pack (version=0.2.0). FROM debian:buster-slim AS base-cpu # Setup environment variables @@ -80,7 +80,7 @@ RUN apt-get -y autoclean \ && rm -rf /tmp/reqs \ && echo "pip cleanup complete" # >>>>>>>>>>>>>>>>>>>>>>>>>>> -# Auto-generated by agi-pack (version=0.1.19). +# Auto-generated by agi-pack (version=0.2.0). FROM base-cpu AS dev-cpu # Install additional system packages diff --git a/pyproject.toml b/pyproject.toml index 63a09fb..bea466a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,7 +28,7 @@ classifiers = [ dynamic = ["version"] dependencies = [ "jinja2", - "pydantic<2", + "pydantic>=2.5", "pyyaml", "typer[all]" ]