Skip to content

Commit

Permalink
Fixes bug caused by cattrs allowing elipsis (...) to be passed to yam…
Browse files Browse the repository at this point in the history
…l writer
  • Loading branch information
petermorrowdev committed Sep 7, 2024
1 parent fda4b78 commit 7a1e2ac
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gybe/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""A simple YAML transpilation tool for rendering kubernetes manifests"""

__version__ = '0.3.2'
__version__ = '0.3.3'


from gybe import k8s
Expand Down
8 changes: 6 additions & 2 deletions gybe/decorators.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Decorators for building CLI commands."""

import inspect
import sys
from dataclasses import fields
from typing import Any, Callable
Expand All @@ -18,7 +19,10 @@ def _omit_none_values(obj: K8sSpec) -> dict[str, Any]:
for f in fields(obj):
v = getattr(obj, f.name)
if v is not None:
u[f.name] = _c.unstructure(v)
if inspect.isclass(f.type) and issubclass(f.type, K8sSpec):
u[f.name] = _c.unstructure(v, f.type)
else:
u[f.name] = _c.unstructure(v)
return u


Expand All @@ -34,7 +38,7 @@ def func(file):
try:
input_obj = _c.structure(input_data, input_model)
except Exception as exc:
print('Validation Error:')
print('validation errors:')
for m in transform_error(exc):
print('-', m)
sys.exit(-1)
Expand Down
10 changes: 8 additions & 2 deletions gybe/modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import inspect
from dataclasses import make_dataclass
from typing import Callable
from typing import Any, Callable, Union

from gybe.k8s.types import Manifest

Expand All @@ -16,5 +16,11 @@ def create_input_model(func: Callable[..., Manifest]) -> type:
else:
defaults = dict()

fields = [(k, t, defaults.get(k, ...)) for k, t in argspec.annotations.items() if k != 'return']
fields: list[Union[tuple[str, type, Any], tuple[str, type]]] = []
for k, t in argspec.annotations.items():
if k != 'return':
if k in defaults:
fields.append((k, t, defaults[k]))
else:
fields.append((k, t))
return make_dataclass(f'{func.__name__}', fields)

0 comments on commit 7a1e2ac

Please sign in to comment.