|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | import asyncio |
4 | | -import importlib |
5 | 4 | import os |
6 | 5 | from abc import abstractmethod |
7 | 6 | from typing import TYPE_CHECKING, Any, Optional |
8 | 7 |
|
9 | 8 | from git import Repo |
10 | 9 |
|
11 | | -from .exceptions import InfrahubTransformNotFoundError, UninitializedError |
| 10 | +from .exceptions import UninitializedError |
12 | 11 |
|
13 | 12 | if TYPE_CHECKING: |
14 | | - from pathlib import Path |
15 | | - |
16 | 13 | from . import InfrahubClient |
17 | | - from .schema.repository import InfrahubPythonTransformConfig |
18 | 14 |
|
19 | 15 | INFRAHUB_TRANSFORM_VARIABLE_TO_IMPORT = "INFRAHUB_TRANSFORMS" |
20 | 16 |
|
@@ -95,40 +91,3 @@ async def run(self, data: Optional[dict] = None) -> Any: |
95 | 91 | return await self.transform(data=unpacked) |
96 | 92 |
|
97 | 93 | return self.transform(data=unpacked) |
98 | | - |
99 | | - |
100 | | -def get_transform_class_instance( |
101 | | - transform_config: InfrahubPythonTransformConfig, |
102 | | - search_path: Optional[Path] = None, |
103 | | - branch: str = "", |
104 | | - client: Optional[InfrahubClient] = None, |
105 | | -) -> InfrahubTransform: |
106 | | - """Gets an instance of the InfrahubTransform class. |
107 | | -
|
108 | | - Args: |
109 | | - transform_config: A config object with information required to find and load the transform. |
110 | | - search_path: The path in which to search for a python file containing the transform. The current directory is |
111 | | - assumed if not speicifed. |
112 | | - branch: Infrahub branch which will be targeted in graphql query used to acquire data for transformation. |
113 | | - client: InfrahubClient used to interact with infrahub API. |
114 | | - """ |
115 | | - if transform_config.file_path.is_absolute() or search_path is None: |
116 | | - search_location = transform_config.file_path |
117 | | - else: |
118 | | - search_location = search_path / transform_config.file_path |
119 | | - |
120 | | - try: |
121 | | - spec = importlib.util.spec_from_file_location(transform_config.class_name, search_location) |
122 | | - module = importlib.util.module_from_spec(spec) # type: ignore[arg-type] |
123 | | - spec.loader.exec_module(module) # type: ignore[union-attr] |
124 | | - |
125 | | - # Get the specified class from the module |
126 | | - transform_class = getattr(module, transform_config.class_name) |
127 | | - |
128 | | - # Create an instance of the class |
129 | | - transform_instance = transform_class(branch=branch, client=client) |
130 | | - |
131 | | - except (FileNotFoundError, AttributeError) as exc: |
132 | | - raise InfrahubTransformNotFoundError(name=transform_config.name) from exc |
133 | | - |
134 | | - return transform_instance |
0 commit comments