Skip to content

Commit

Permalink
[fixlib][feat] Allow marking resource classes as not exportable
Browse files Browse the repository at this point in the history
  • Loading branch information
aquamatthias committed Oct 18, 2024
1 parent 3ba74a9 commit 21995c0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions fixlib/fixlib/baseresources.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,8 @@ class BaseResource(ABC):
_categories: ClassVar[List[Category]] = []
# Link to the cloud providers product documentation of this resource kind.
_docs_url: ClassVar[Optional[str]] = None
# Mark this class as exportable. Use False for internal model classes without instances.
_model_export: ClassVar[bool] = True

################################################################################
# Instance Variables
Expand Down
4 changes: 3 additions & 1 deletion fixlib/fixlib/core/model_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,16 @@ def transitive_classes(classes: Set[type], walk_subclasses: bool = True) -> Set[
def check(to_check: type) -> None:
clazz = optional_origin(to_check)
if clazz in all_classes:
pass
return
elif is_dict(clazz):
key_type, value_type = dict_types(to_check)
check(key_type)
check(value_type)
elif is_collection(clazz):
check(type_arg(to_check))
elif attrs.has(clazz):
if getattr(clazz, "_model_export", True) is False:
return
resolve_types(clazz)
all_classes.add(clazz)
for mro_clazz in clazz.mro()[1:]:
Expand Down
7 changes: 7 additions & 0 deletions fixlib/test/core/model_export_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ class DataClassOther(DataClassBase):
something: str


@define(slots=False)
class DataClassNotExported(DataClassBase):
_model_export: ClassVar[bool] = False
kind: ClassVar[str] = "other"
something: str


def test_collection() -> None:
assert is_collection(Optional[List[str]]) is True
assert is_collection(List[str]) is True
Expand Down

0 comments on commit 21995c0

Please sign in to comment.