Skip to content

Commit ef66679

Browse files
committed
Group poetry.lock and pyproject.toml in frozen dataclass
1 parent a666ede commit ef66679

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

exasol/toolbox/nox/_lint.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from nox import Session
1212

1313
from exasol.toolbox.nox._shared import python_files
14+
from exasol.toolbox.util.dependencies.poetry_dependencies import PoetryFiles
1415
from noxconfig import PROJECT_CONFIG
1516

1617

@@ -140,7 +141,7 @@ def security_lint(session: Session) -> None:
140141
@nox.session(name="lint:dependencies", python=False)
141142
def dependency_check(session: Session) -> None:
142143
"""Checks if only valid sources of dependencies are used"""
143-
content = Path(PROJECT_CONFIG.root, "pyproject.toml").read_text()
144+
content = Path(PROJECT_CONFIG.root, PoetryFiles.pyproject_toml).read_text()
144145
dependencies = Dependencies.parse(content)
145146
console = rich.console.Console()
146147
if illegal := dependencies.illegal:

exasol/toolbox/nox/_release.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
check_for_config_attribute,
1515
)
1616
from exasol.toolbox.nox.plugin import NoxTasks
17+
from exasol.toolbox.util.dependencies.poetry_dependencies import PoetryFiles
1718
from exasol.toolbox.util.git import Git
1819
from exasol.toolbox.util.release.changelog import Changelogs
1920
from exasol.toolbox.util.version import (
@@ -142,7 +143,7 @@ def prepare_release(session: Session) -> None:
142143
return
143144

144145
changed_files += [
145-
PROJECT_CONFIG.root / "pyproject.toml",
146+
PROJECT_CONFIG.root / PoetryFiles.pyproject_toml,
146147
PROJECT_CONFIG.version_file,
147148
]
148149
results = pm.hook.prepare_release_add_files(session=session, config=PROJECT_CONFIG)

exasol/toolbox/util/dependencies/poetry_dependencies.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
import subprocess
44
import tempfile
55
from collections import OrderedDict
6+
from dataclasses import dataclass
67
from pathlib import Path
7-
from typing import Optional
8+
from typing import Final
89

910
import tomlkit
1011
from pydantic import (
@@ -28,7 +29,16 @@ class PoetryGroup(BaseModel):
2829
toml_section: str | None
2930

3031

31-
PYPROJECT_TOML = "pyproject.toml"
32+
@dataclass(frozen=True)
33+
class PoetryFiles:
34+
pyproject_toml: Final[str] = "pyproject.toml"
35+
poetry_lock: Final[str] = "poetry.lock"
36+
37+
@property
38+
def files(self) -> tuple[str, ...]:
39+
return tuple(self.__dict__.values())
40+
41+
3242
TRANSITIVE_GROUP = PoetryGroup(name="transitive", toml_section=None)
3343

3444

@@ -39,7 +49,7 @@ class PoetryToml(BaseModel):
3949

4050
@classmethod
4151
def load_from_toml(cls, working_directory: Path) -> PoetryToml:
42-
file_path = working_directory / PYPROJECT_TOML
52+
file_path = working_directory / PoetryFiles.pyproject_toml
4353
if not file_path.exists():
4454
raise ValueError(f"File not found: {file_path}")
4555

@@ -169,6 +179,6 @@ def get_dependencies_from_latest_tag() -> (
169179
path = PROJECT_CONFIG.root.relative_to(Git.toplevel())
170180
with tempfile.TemporaryDirectory() as tmpdir_str:
171181
tmpdir = Path(tmpdir_str)
172-
for file in ("poetry.lock", PYPROJECT_TOML):
182+
for file in PoetryFiles().files:
173183
Git.checkout(latest_tag, path / file, tmpdir / file)
174184
return get_dependencies(working_directory=tmpdir)

0 commit comments

Comments
 (0)