Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fixlib][feat] Allow marking resource classes as not exportable #2259

Merged
merged 2 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading