Skip to content

Commit fc42db5

Browse files
authored
[fixlib][feat] Allow marking resource classes as not exportable (#2259)
1 parent 3ba74a9 commit fc42db5

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

fixlib/fixlib/baseresources.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,8 @@ class BaseResource(ABC):
296296
_categories: ClassVar[List[Category]] = []
297297
# Link to the cloud providers product documentation of this resource kind.
298298
_docs_url: ClassVar[Optional[str]] = None
299+
# Mark this class as exportable. Use False for internal model classes without instances.
300+
_model_export: ClassVar[bool] = True
299301

300302
################################################################################
301303
# Instance Variables

fixlib/fixlib/core/model_check.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,10 @@ def dynamic_import(name: str) -> List[Type[Any]]:
174174
*dynamic_import("fix_plugin_github.resources.GithubResource"),
175175
*dynamic_import("fix_plugin_k8s.resources.KubernetesResource"),
176176
*dynamic_import("fix_plugin_onelogin.OneLoginResource"),
177-
*dynamic_import("fix_plugin_onprem.resources.OnpremResource"),
178177
*dynamic_import("fix_plugin_posthog.resources.PosthogResource"),
179178
*dynamic_import("fix_plugin_random.resources.RandomResource"),
180179
*dynamic_import("fix_plugin_scarf.resources.ScarfResource"),
181180
*dynamic_import("fix_plugin_slack.resources.SlackResource"),
182-
*dynamic_import("fix_plugin_vsphere.resources.VSphereResource"),
183181
*base,
184182
}
185183

fixlib/fixlib/core/model_export.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,16 @@ def transitive_classes(classes: Set[type], walk_subclasses: bool = True) -> Set[
6969
def check(to_check: type) -> None:
7070
clazz = optional_origin(to_check)
7171
if clazz in all_classes:
72-
pass
72+
return
7373
elif is_dict(clazz):
7474
key_type, value_type = dict_types(to_check)
7575
check(key_type)
7676
check(value_type)
7777
elif is_collection(clazz):
7878
check(type_arg(to_check))
7979
elif attrs.has(clazz):
80+
if getattr(clazz, "_model_export", True) is False:
81+
return
8082
resolve_types(clazz)
8183
all_classes.add(clazz)
8284
for mro_clazz in clazz.mro()[1:]:

fixlib/test/core/model_export_test.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ class DataClassOther(DataClassBase):
7070
something: str
7171

7272

73+
@define(slots=False)
74+
class DataClassNotExported(DataClassBase):
75+
_model_export: ClassVar[bool] = False
76+
kind: ClassVar[str] = "other"
77+
something: str
78+
79+
7380
def test_collection() -> None:
7481
assert is_collection(Optional[List[str]]) is True
7582
assert is_collection(List[str]) is True

0 commit comments

Comments
 (0)