diff --git a/fixlib/fixlib/baseresources.py b/fixlib/fixlib/baseresources.py index 411ec1e4fa..997539f502 100644 --- a/fixlib/fixlib/baseresources.py +++ b/fixlib/fixlib/baseresources.py @@ -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 diff --git a/fixlib/fixlib/core/model_check.py b/fixlib/fixlib/core/model_check.py index 9d811b2035..9b4e807cd4 100644 --- a/fixlib/fixlib/core/model_check.py +++ b/fixlib/fixlib/core/model_check.py @@ -174,12 +174,10 @@ def dynamic_import(name: str) -> List[Type[Any]]: *dynamic_import("fix_plugin_github.resources.GithubResource"), *dynamic_import("fix_plugin_k8s.resources.KubernetesResource"), *dynamic_import("fix_plugin_onelogin.OneLoginResource"), - *dynamic_import("fix_plugin_onprem.resources.OnpremResource"), *dynamic_import("fix_plugin_posthog.resources.PosthogResource"), *dynamic_import("fix_plugin_random.resources.RandomResource"), *dynamic_import("fix_plugin_scarf.resources.ScarfResource"), *dynamic_import("fix_plugin_slack.resources.SlackResource"), - *dynamic_import("fix_plugin_vsphere.resources.VSphereResource"), *base, } diff --git a/fixlib/fixlib/core/model_export.py b/fixlib/fixlib/core/model_export.py index 53196bca45..3636c32af9 100644 --- a/fixlib/fixlib/core/model_export.py +++ b/fixlib/fixlib/core/model_export.py @@ -69,7 +69,7 @@ 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) @@ -77,6 +77,8 @@ def check(to_check: type) -> None: 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:]: diff --git a/fixlib/test/core/model_export_test.py b/fixlib/test/core/model_export_test.py index 0dfb8489c5..f628b98ada 100644 --- a/fixlib/test/core/model_export_test.py +++ b/fixlib/test/core/model_export_test.py @@ -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