Skip to content

Commit

Permalink
[fixlib][feat] Allow marking resource classes as not exportable (#2259)
Browse files Browse the repository at this point in the history
  • Loading branch information
aquamatthias authored Oct 18, 2024
1 parent 3ba74a9 commit fc42db5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
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
2 changes: 0 additions & 2 deletions fixlib/fixlib/core/model_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

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 fc42db5

Please sign in to comment.