Skip to content

Commit 89907b5

Browse files
Base Config
1 parent b4f9094 commit 89907b5

File tree

3 files changed

+94
-6
lines changed

3 files changed

+94
-6
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
from collections.abc import Iterable
2+
from pathlib import Path
3+
from typing import (
4+
Annotated,
5+
Optional,
6+
)
7+
8+
from pydantic import (
9+
BaseModel,
10+
AfterValidator,
11+
computed_field
12+
)
13+
from pydantic.dataclasses import dataclass
14+
15+
from exasol.toolbox.util.version import Version
16+
from dataclasses import dataclass
17+
18+
def str_like_version_validation(versions: list[str]):
19+
for version in versions:
20+
Version.from_string(version)
21+
return versions
22+
23+
24+
class BaseConfig(BaseModel):
25+
"""
26+
Basic Configuration for Projects
27+
28+
Attributes:
29+
* python_versions (Iterable[str]): Iterable over all available python versions of the project [default: ("3.9", "3.10", "3.11", "3.12", "3.13")]
30+
* min_py_version : Minimum of python_versions
31+
* max_py_version: Maximum of python_versions
32+
* exasol_versions: (Iterable[str]): Iterabble over all available exasol versions [default: ("7.1.9)
33+
"""
34+
python_versions: Annotated[
35+
list[str], AfterValidator(str_like_version_validation)
36+
] = ["3.9", "3.10", "3.11", "3.12", "3.13"]
37+
exasol_versions: Annotated[
38+
list[str], AfterValidator(str_like_version_validation)
39+
] = ["7.1.9"]
40+
model_config = {
41+
"frozen": True
42+
}
43+
44+
@computed_field
45+
@property
46+
def min_py_version(self) -> str:
47+
return str(min([Version.from_string(v) for v in self.python_versions]))
48+
49+
@computed_field
50+
@property
51+
def max_py_version(self) -> str:
52+
return str(max([Version.from_string(v) for v in self.python_versions]))

noxconfig.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from exasol.toolbox.nox.plugin import hookimpl
1010
from exasol.toolbox.tools.replace_version import update_github_yml
11-
11+
from exasol.toolbox.BaseConfig import BaseConfig
1212

1313
class UpdateTemplates:
1414
TEMPLATE_PATH: Path = Path(__file__).parent / "exasol" / "toolbox" / "templates"
@@ -37,10 +37,8 @@ def prepare_release_add_files(self, session, config):
3737
return self.template_workflows + self.actions
3838

3939

40-
@dataclass(frozen=True)
41-
class Config:
40+
class Config(BaseConfig):
4241
"""Project specific configuration used by nox infrastructure"""
43-
4442
root: Path = Path(__file__).parent
4543
doc: Path = Path(__file__).parent / "doc"
4644
source: Path = Path("exasol/toolbox")
@@ -51,8 +49,6 @@ class Config:
5149
"project-template",
5250
"idioms",
5351
)
54-
python_versions: Iterable[str] = ("3.9", "3.10", "3.11", "3.12", "3.13")
55-
exasol_versions: Iterable[str] = ("7.1.9",)
5652
plugins: Iterable[object] = (UpdateTemplates,)
5753
# need --keep-runtime-typing, as pydantic with python3.9 does not accept str | None
5854
# format, and it is not resolved with from __future__ import annotations. pyupgrade
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from exasol.toolbox.BaseConfig import BaseConfig, str_like_version_validation
2+
import pytest
3+
import pydantic
4+
5+
@pytest.mark.parametrize(
6+
"versions",
7+
(
8+
["$.2.3"],
9+
["1.f.1"],
10+
["1.1.1", "1.2.3", "2.3.4", "2.3.7", "1.1.1.1"]
11+
)
12+
)
13+
def test_str_like_version_validation(versions):
14+
with pytest.raises(ValueError):
15+
str_like_version_validation(versions)
16+
17+
18+
def test_default():
19+
config = BaseConfig()
20+
str_like_version_validation(config.python_versions)
21+
str_like_version_validation(config.exasol_versions)
22+
23+
24+
def test_new_value():
25+
conf = BaseConfig(python_versions=["1.21.1", "1.1.1"])
26+
assert conf.python_versions == ["1.21.1", "1.1.1"]
27+
28+
29+
class BaseConfigExpansion(BaseConfig):
30+
expansion1: str = "test1"
31+
32+
33+
def test_expansion_validation():
34+
with pytest.raises(ValueError):
35+
_ = BaseConfigExpansion(python_versions=["1.1.1", "1.1.F"])
36+
37+
38+
def test_min_max_py():
39+
conf = BaseConfig(python_versions=["1.1.1", "5.5.5", "9.9.9"])
40+
assert conf.min_py_version == "1.1.1" and conf.max_py_version == "9.9.9"

0 commit comments

Comments
 (0)