From 578b512bd91e1b065500c17e8faa928df71ecc74 Mon Sep 17 00:00:00 2001 From: Ryan Jung Date: Mon, 13 Jan 2025 17:49:13 -0700 Subject: [PATCH 1/3] Set up custom Flattenable type --- tb_pulumi/__init__.py | 4 +++- tb_pulumi/monitoring.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tb_pulumi/__init__.py b/tb_pulumi/__init__.py index 994c49b..f146f4c 100644 --- a/tb_pulumi/__init__.py +++ b/tb_pulumi/__init__.py @@ -14,6 +14,8 @@ from typing import Any +type Flattenable = dict | list | ThunderbirdComponentResource | pulumi.Output | pulumi.Resource + class ThunderbirdPulumiProject: """A collection of related Pulumi resources upon which we can take bulk/collective actions. This class enforces some usage conventions that help keep us organized and consistent. @@ -226,7 +228,7 @@ def env_var_is_true(name: str) -> bool: return env_var_matches(name, ['t', 'true', 'yes'], False) -def flatten(item: dict | list | ThunderbirdComponentResource | pulumi.Output | pulumi.Resource) -> set[pulumi.Resource]: +def flatten(item: Flattenable) -> set[pulumi.Resource]: """Recursively traverses a nested collection of Pulumi ``Resource`` s, converting them into a flat set which can be more easily iterated over. diff --git a/tb_pulumi/monitoring.py b/tb_pulumi/monitoring.py index a7cd669..6a5a731 100644 --- a/tb_pulumi/monitoring.py +++ b/tb_pulumi/monitoring.py @@ -85,7 +85,7 @@ def __init__( self.supported_resources = [] def __parse_resource_item( - item: list | dict | pulumi.Output | pulumi.Resource | tb_pulumi.ThunderbirdComponentResource, + item: tb_pulumi.Flattenable, ): """Not all items in a project's ``resources`` dict are actually Pulumi Resources. Sometimes we build resources downstream of a Pulumi Output, which makes those resources (as they are known to the project) From 8a9f5aa0af98e0107f2aa4e9f1b44c73ddf098da Mon Sep 17 00:00:00 2001 From: Ryan Jung Date: Mon, 13 Jan 2025 17:58:02 -0700 Subject: [PATCH 2/3] Commentary on Flattenables --- tb_pulumi/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tb_pulumi/__init__.py b/tb_pulumi/__init__.py index f146f4c..877a244 100644 --- a/tb_pulumi/__init__.py +++ b/tb_pulumi/__init__.py @@ -14,6 +14,7 @@ from typing import Any +#: Type alias representing valid types to be found among a ThunderbirdPulumiProject's resources type Flattenable = dict | list | ThunderbirdComponentResource | pulumi.Output | pulumi.Resource class ThunderbirdPulumiProject: @@ -232,8 +233,8 @@ def flatten(item: Flattenable) -> set[pulumi.Resource]: """Recursively traverses a nested collection of Pulumi ``Resource`` s, converting them into a flat set which can be more easily iterated over. - :param item: Either a Pulumi ``Resource`` object, or some collection thereof. The following types of collections are - supported: ``dict``, ``list``, ``ThunderbirdComponentResource``. + :param item: An item which we intend to flatten. Must be one of the recognized types or collections defined in + the Flattenable type alias. :type item: dict | list | ThunderbirdComponentResource :return: A ``set`` of Pulumi ``Resource`` s contained within the collection. From 818232fbc8ce1c5f4f704526987c526f7e7997c0 Mon Sep 17 00:00:00 2001 From: Ryan Jung Date: Mon, 13 Jan 2025 17:59:59 -0700 Subject: [PATCH 3/3] Lint --- tb_pulumi/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tb_pulumi/__init__.py b/tb_pulumi/__init__.py index 877a244..95fe9ea 100644 --- a/tb_pulumi/__init__.py +++ b/tb_pulumi/__init__.py @@ -17,6 +17,7 @@ #: Type alias representing valid types to be found among a ThunderbirdPulumiProject's resources type Flattenable = dict | list | ThunderbirdComponentResource | pulumi.Output | pulumi.Resource + class ThunderbirdPulumiProject: """A collection of related Pulumi resources upon which we can take bulk/collective actions. This class enforces some usage conventions that help keep us organized and consistent.