|
3 | 3 | import asyncio |
4 | 4 | import importlib |
5 | 5 | import os |
| 6 | +import warnings |
6 | 7 | from abc import abstractmethod |
7 | 8 | from typing import TYPE_CHECKING, Any, Optional |
8 | 9 |
|
9 | 10 | import ujson |
10 | 11 | from git.repo import Repo |
11 | 12 | from pydantic import BaseModel, Field |
12 | 13 |
|
13 | | -from . import InfrahubClient |
14 | 14 | from .exceptions import InfrahubCheckNotFoundError, UninitializedError |
15 | 15 |
|
16 | 16 | if TYPE_CHECKING: |
17 | 17 | from pathlib import Path |
18 | 18 |
|
| 19 | + from . import InfrahubClient |
19 | 20 | from .schema import InfrahubCheckDefinitionConfig |
20 | 21 |
|
21 | 22 | INFRAHUB_CHECK_VARIABLE_TO_IMPORT = "INFRAHUB_CHECKS" |
22 | 23 |
|
| 24 | +_client_class = "InfrahubClient" |
| 25 | + |
23 | 26 |
|
24 | 27 | class InfrahubCheckInitializer(BaseModel): |
25 | 28 | """Information about the originator of the check.""" |
@@ -81,11 +84,17 @@ def client(self, value: InfrahubClient) -> None: |
81 | 84 | @classmethod |
82 | 85 | async def init(cls, client: Optional[InfrahubClient] = None, *args: Any, **kwargs: Any) -> InfrahubCheck: |
83 | 86 | """Async init method, If an existing InfrahubClient client hasn't been provided, one will be created automatically.""" |
84 | | - |
85 | | - instance = cls(*args, **kwargs) |
86 | | - instance.client = client or InfrahubClient() |
87 | | - |
88 | | - return instance |
| 87 | + warnings.warn( |
| 88 | + "InfrahubCheck.init has been deprecated and will be removed in the version in Infrahub SDK 2.0.0", |
| 89 | + DeprecationWarning, |
| 90 | + stacklevel=1, |
| 91 | + ) |
| 92 | + if not client: |
| 93 | + client_module = importlib.import_module("infrahub_sdk.client") |
| 94 | + client_class = getattr(client_module, _client_class) |
| 95 | + client = client_class() |
| 96 | + kwargs["client"] = client |
| 97 | + return cls(*args, **kwargs) |
89 | 98 |
|
90 | 99 | @property |
91 | 100 | def errors(self) -> list[dict[str, Any]]: |
|
0 commit comments