Skip to content

Commit

Permalink
refactor: do not store variables schema
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulFarault committed Nov 24, 2023
1 parent bfc5704 commit 0d9ea44
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
16 changes: 7 additions & 9 deletions tdp/core/variables/cluster_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def initialize_cluster_variables(
else:
repo = repository_class.init(service_tdp_vars)
schemas = collections.get_service_schema(service)

Check failure on line 106 in tdp/core/variables/cluster_variables.py

View workflow job for this annotation

GitHub Actions / Check linting with Ruff

Ruff (F841)

tdp/core/variables/cluster_variables.py:106:21: F841 Local variable `schemas` is assigned to but never used
service_variables = ServiceVariables(service, repo, schemas)
service_variables = ServiceVariables(service, repo)
cluster_variables[service] = service_variables

try:
Expand All @@ -126,7 +126,7 @@ def initialize_cluster_variables(

cluster_variables = ClusterVariables(cluster_variables)
if validate:
cluster_variables._validate_services_schemas()
cluster_variables._validate_services_schemas(collections)

return cluster_variables

Expand Down Expand Up @@ -154,22 +154,20 @@ def get_cluster_variables(
for path in tdp_vars.iterdir():
if path.is_dir():
repo = repository_class(tdp_vars / path.name)
schemas = collections.get_service_schema(path.stem)
cluster_variables[path.name] = ServiceVariables(
path.name, repo, schemas
)
cluster_variables[path.name] = ServiceVariables(path.name, repo)

cluster_variables = ClusterVariables(cluster_variables)

if validate:
cluster_variables._validate_services_schemas()
cluster_variables._validate_services_schemas(collections)

return cluster_variables

def _validate_services_schemas(self):
def _validate_services_schemas(self, collections: Collections):
"""Validate all services schemas."""
for service in self.values():
service.validate()
schema = collections.get_service_schema(service.name)
service.validate(schema)

def get_modified_sch(
self,
Expand Down
14 changes: 4 additions & 10 deletions tdp/core/variables/service_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import logging
from collections import OrderedDict
from collections.abc import Generator
from collections.abc import Generator, Mapping

Check failure on line 7 in tdp/core/variables/service_variables.py

View workflow job for this annotation

GitHub Actions / Check linting with Ruff

Ruff (F401)

tdp/core/variables/service_variables.py:7:40: F401 `collections.abc.Mapping` imported but unused
from contextlib import ExitStack, contextmanager
from pathlib import Path
from typing import TYPE_CHECKING
Expand Down Expand Up @@ -43,7 +43,7 @@ def __repr__(self):
class ServiceVariables:
"""Variables of a service."""

def __init__(self, service_name: str, repository: Repository, schema: dict):
def __init__(self, service_name: str, repository: Repository):
"""Initialize a ServiceVariables object.
Args:
Expand All @@ -58,7 +58,6 @@ def __init__(self, service_name: str, repository: Repository, schema: dict):
raise ValueError(f"{service_name} is longer than {SERVICE_NAME_MAX_LENGTH}")
self._name = service_name
self._repo = repository
self._schema = schema

@property
def name(self) -> str:
Expand All @@ -70,11 +69,6 @@ def repository(self) -> Repository:
"""Repository of the service."""
return self._repo

@property
def schema(self) -> dict:
"""Schema of the service."""
return self._schema

@property
def version(self) -> str:
"""Version of the service configuration."""
Expand Down Expand Up @@ -242,7 +236,7 @@ def validate_schema(self, variables: Variables, schema: dict) -> None:
except exceptions.ValidationError as e:
raise InvalidSchema("Schema is invalid", variables.name) from e

def validate(self) -> None:
def validate(self, schema: dict) -> None:
"""Validates the service schema.
Raises:
Expand All @@ -262,6 +256,6 @@ def validate(self) -> None:
service_variables.copy(), variables.name
)
test_variables.merge(variables)
self.validate_schema(test_variables, self.schema)
self.validate_schema(test_variables, schema)
logger.debug(f"{path.stem} is valid")
logger.debug(f"Service {self.name} is valid")

0 comments on commit 0d9ea44

Please sign in to comment.