Skip to content

Commit

Permalink
Add Anod spec API version 1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikokrock committed Jan 10, 2024
1 parent ff78513 commit 312e879
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
22 changes: 21 additions & 1 deletion src/e3/anod/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]] = {}

Expand Down Expand Up @@ -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)
15 changes: 11 additions & 4 deletions src/e3/anod/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 312e879

Please sign in to comment.