Skip to content

Commit f45ca23

Browse files
Base Config
1 parent 95b5398 commit f45ca23

File tree

5 files changed

+29
-20
lines changed

5 files changed

+29
-20
lines changed

exasol/toolbox/BaseConfig/__init__.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
from collections.abc import Iterable
2+
from dataclasses import dataclass
23
from pathlib import Path
34
from typing import (
45
Annotated,
56
Optional,
67
)
78

89
from pydantic import (
9-
BaseModel,
1010
AfterValidator,
11-
computed_field
11+
BaseModel,
12+
computed_field,
13+
ConfigDict
1214
)
1315
from pydantic.dataclasses import dataclass
1416

1517
from exasol.toolbox.util.version import Version
16-
from dataclasses import dataclass
18+
1719

1820
def str_like_version_validation(versions: list[str]):
1921
for version in versions:
@@ -31,15 +33,14 @@ class BaseConfig(BaseModel):
3133
* max_py_version: Maximum of python_versions
3234
* exasol_versions: (Iterable[str]): Iterabble over all available exasol versions [default: ("7.1.9)
3335
"""
36+
3437
python_versions: Annotated[
3538
list[str], AfterValidator(str_like_version_validation)
3639
] = ["3.9", "3.10", "3.11", "3.12", "3.13"]
3740
exasol_versions: Annotated[
3841
list[str], AfterValidator(str_like_version_validation)
3942
] = ["7.1.9"]
40-
model_config = {
41-
"frozen": True
42-
}
43+
model_config = ConfigDict(frozen=True)
4344

4445
@computed_field
4546
@property
@@ -49,4 +50,4 @@ def min_py_version(self) -> str:
4950
@computed_field
5051
@property
5152
def max_py_version(self) -> str:
52-
return str(max([Version.from_string(v) for v in self.python_versions]))
53+
return str(max([Version.from_string(v) for v in self.python_versions]))

noxconfig.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
from dataclasses import dataclass
77
from pathlib import Path
88

9+
from exasol.toolbox.BaseConfig import BaseConfig
910
from exasol.toolbox.nox.plugin import hookimpl
1011
from exasol.toolbox.tools.replace_version import update_github_yml
11-
from exasol.toolbox.BaseConfig import BaseConfig
12+
1213

1314
class UpdateTemplates:
1415
TEMPLATE_PATH: Path = Path(__file__).parent / "exasol" / "toolbox" / "templates"
@@ -39,6 +40,7 @@ def prepare_release_add_files(self, session, config):
3940

4041
class Config(BaseConfig):
4142
"""Project specific configuration used by nox infrastructure"""
43+
4244
root: Path = Path(__file__).parent
4345
doc: Path = Path(__file__).parent / "doc"
4446
source: Path = Path("exasol/toolbox")

project-template/{{cookiecutter.repo_name}}/noxconfig.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
from dataclasses import dataclass
44
from pathlib import Path
55
from typing import Iterable
6+
from exasol.toolbox.BaseConfig import BaseConfig
67

78

8-
@dataclass(frozen=True)
9-
class Config:
9+
class Config(BaseConfig):
1010
root: Path = Path(__file__).parent
1111
doc: Path = Path(__file__).parent / "doc"
1212
source: Path = Path("exasol/{{cookiecutter.package_name}}")

test/integration/project-template/conftest.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,26 @@ def cwd(tmp_path_factory):
1111
return tmp_path_factory.mktemp("project_template_test")
1212

1313

14+
@pytest.fixture(scope="session")
15+
def config():
16+
return Config()
17+
18+
1419
@pytest.fixture(scope="session", autouse=True)
15-
def new_project(cwd):
20+
def new_project(cwd, config):
1621
project_name = "project"
1722
repo_name = "repo"
1823
package_name = "package"
1924

2025
subprocess.run(
21-
["cookiecutter", Config.root / "project-template", "-o", cwd, "--no-input",
26+
["cookiecutter", config.root / "project-template", "-o", cwd, "--no-input",
2227
f"project_name={project_name}", f"repo_name={repo_name}",
2328
f"package_name={package_name}",
2429
], capture_output=True, check=True)
2530

2631
return cwd / repo_name
2732

33+
2834
@pytest.fixture(scope="session", autouse=True)
2935
def poetry_install(run_command, poetry_path):
3036
run_command([poetry_path, "install"])

test/unit/BaseConfig/base_config_test.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
from exasol.toolbox.BaseConfig import BaseConfig, str_like_version_validation
2-
import pytest
31
import pydantic
2+
import pytest
3+
4+
from exasol.toolbox.BaseConfig import (
5+
BaseConfig,
6+
str_like_version_validation,
7+
)
8+
49

510
@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-
)
11+
"versions", (["$.2.3"], ["1.f.1"], ["1.1.1", "1.2.3", "2.3.4", "2.3.7", "1.1.1.1"])
1212
)
1313
def test_str_like_version_validation(versions):
1414
with pytest.raises(ValueError):

0 commit comments

Comments
 (0)