Skip to content

Commit 1cc7ba7

Browse files
committed
Switch loading of content to be explicit so clearer
1 parent 46233bc commit 1cc7ba7

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

exasol/toolbox/nox/_dependencies.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ def run(self, session: Session) -> None:
8888
def dependency_licenses(session: Session) -> None:
8989
"""returns the packages and their licenses"""
9090
working_directory = Path()
91-
groups = PoetryToml(working_directory=working_directory).groups
91+
poetry_dep = PoetryToml.load_from_toml(working_directory=working_directory)
9292
dependencies = PoetryDependencies(
93-
groups=groups, working_directory=working_directory
93+
groups=poetry_dep.groups, working_directory=working_directory
9494
).direct_dependencies
9595
package_infos = licenses()
9696
print(packages_to_markdown(dependencies=dependencies, packages=package_infos))

exasol/toolbox/util/dependencies/poetry_dependencies.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,27 @@ class Config:
2727

2828

2929
class PoetryToml(BaseModel):
30-
working_directory: Path
30+
content: TOMLDocument
31+
32+
class Config:
33+
frozen = True
34+
arbitrary_types_allowed = True
3135

32-
@model_validator(mode="before")
33-
def read_content(cls, values):
34-
file_path = values["working_directory"] / "pyproject.toml"
36+
@classmethod
37+
def load_from_toml(cls, working_directory: Path) -> PoetryToml:
38+
file_path = working_directory / "pyproject.toml"
3539
if not file_path.exists():
3640
raise ValueError(f"File not found: {file_path}")
3741

3842
try:
3943
text = file_path.read_text()
40-
cls._content: TOMLDocument = tomlkit.loads(text)
44+
content = tomlkit.loads(text)
45+
return cls(content=content)
4146
except Exception as e:
4247
raise ValueError(f"Error reading file: {str(e)}")
43-
return values
4448

4549
def get_section_dict(self, section: str) -> Optional[dict]:
46-
current = self._content.copy()
50+
current = self.content.copy()
4751
for section in section.split("."):
4852
if section not in current:
4953
return None

test/unit/util/dependencies/poetry_dependencies_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def create_poetry_project(cwd, project_name, project_path):
5959

6060
@pytest.fixture(scope="module")
6161
def pyproject_toml(project_path, create_poetry_project):
62-
return PoetryToml(working_directory=project_path)
62+
return PoetryToml.load_from_toml(working_directory=project_path)
6363

6464

6565
class TestPoetryToml:

0 commit comments

Comments
 (0)