Skip to content

Commit

Permalink
add version checking
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam-D-Lewis committed Dec 12, 2024
1 parent 5c86415 commit b6ffec8
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions src/_nebari/config_set.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
import pathlib

from pydantic import BaseModel, ConfigDict
from packaging.requirements import Requirement
from pydantic import BaseModel, ConfigDict, field_validator

from _nebari._version import __version__
from _nebari.utils import yaml


class ConfigSetMetadata(BaseModel):
model_config: ConfigDict = ConfigDict(
extra="allow",
)
name: str = None # for use with guided init
model_config: ConfigDict = ConfigDict(extra="allow", arbitrary_types_allowed=True)
name: str # for use with guided init
description: str = None
nebari_version: str = None
nebari_version: str | Requirement

@field_validator("nebari_version")
@classmethod
def validate_version_requirement(cls, version_req):
if isinstance(version_req, str):
version_req = Requirement(f"nebari{version_req}")
version_req.specifier.prereleases = True

return version_req

def check_version(self, version):
if version not in self.nebari_version.specifier:
raise ValueError(
f"Current Nebari version {__version__} is not compatible with "
f'required version {self.nebari_version.specifier} for "{self.name}" config set.'
)


class ConfigSet(BaseModel):
Expand All @@ -27,7 +43,9 @@ def read_config_set(config_set_filepath: str):
with filename.open() as f:
config_set_yaml = yaml.load(f)

# TODO: Validation e.g. Check Nebari version
config_set = ConfigSet(**config_set_yaml)

# validation
config_set.metadata.check_version(__version__)

return config_set

0 comments on commit b6ffec8

Please sign in to comment.