From 312e8794282ab053d790ff9cbb8af3438473bf71 Mon Sep 17 00:00:00 2001 From: Nicolas Roche Date: Wed, 10 Jan 2024 12:28:04 +0100 Subject: [PATCH] Add Anod spec API version 1.6 --- src/e3/anod/loader.py | 22 +++++++++++++++++++++- src/e3/anod/spec.py | 15 +++++++++++---- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/e3/anod/loader.py b/src/e3/anod/loader.py index 165368f0..b3d57e55 100644 --- a/src/e3/anod/loader.py +++ b/src/e3/anod/loader.py @@ -69,7 +69,21 @@ def __init__( if not os.path.isdir(spec_dir): raise SandBoxError(f"spec directory {spec_dir} does not exist") self.spec_dir = spec_dir - self.api_version = __version__ + + # Read read the API version file + version_file = os.path.join(self.spec_dir, "VERSION") + if os.path.isfile(version_file): + with open(version_file) as f: + content = f.read().strip() + if ":" not in content: + raise SandBoxError( + f"invalid VERSION file in spec dir {self.spec_dir}" + ) + self.api_version = content.split(":")[1].strip() + else: + # If no VERSION file is found use the default API VERSION + self.api_version = __version__ + self.specs = {} self.repos: dict[str, dict[str, str]] = {} @@ -295,4 +309,10 @@ def spec(name: str) -> Callable[..., Anod]: break assert spec_repository is not None + + if spec_repository.api_version not in ("1.4", "1.5"): + logger.error("e3.anod.loader.spec is only valid for API VERSION 1.4 and 1.5") + raise SandBoxError( + "e3.anod.loader.spec is only valid for API VERSION 1.4 and 1.5", "spec" + ) return spec_repository.load(name) diff --git a/src/e3/anod/spec.py b/src/e3/anod/spec.py index f2b9fd52..286a1627 100644 --- a/src/e3/anod/spec.py +++ b/src/e3/anod/spec.py @@ -16,12 +16,19 @@ from e3.anod.qualifiers_manager import QualifiersManager from e3.yaml import load_with_config -# CURRENT API version +# Default API version __version__ = "1.4" -SUPPORTED_API = (__version__, "1.5") -# The driver can support multiple version of the spec API, we currently support -# only the version 1.4 and 1.5. Default is still 1.4 +SUPPORTED_API = (__version__, "1.5", "1.6") +# API VERSIONS +# +# Version 1.4 (initial version) +# Version 1.5 +# NEW: YAML files are also searched in subdirectories whose basename is the +# the associated spec basename. +# Version 1.6 +# NEW: Add support for spec function automatically declared inside each spec +# DEPRECATED: remove support of e3.anod.loader.spec logger = e3.log.getLogger("anod") spec_logger = e3.log.getLogger("anod.spec")