|
6 | 6 | At the top level, `kr8s` provides a synchronous API that wraps the asynchronous API provided by `kr8s.asyncio`. |
7 | 7 | Both APIs are functionally identical with the same objects, method signatures and return values. |
8 | 8 | """ |
| 9 | +# Disable missing docstrings, these are inherited from the async version of the objects |
| 10 | +# ruff: noqa: D102 |
| 11 | +from __future__ import annotations |
| 12 | + |
9 | 13 | from functools import partial, update_wrapper |
10 | | -from typing import Dict, Optional, Type, Union |
| 14 | +from typing import Generator |
11 | 15 |
|
12 | 16 | from . import asyncio, objects, portforward |
13 | 17 | from ._api import ALL |
14 | 18 | from ._api import Api as _AsyncApi |
15 | 19 | from ._async_utils import run_sync as _run_sync |
16 | | -from ._async_utils import sync as _sync |
17 | 20 | from ._exceptions import ( |
18 | 21 | APITimeoutError, |
19 | 22 | ConnectionClosedError, |
20 | 23 | ExecError, |
21 | 24 | NotFoundError, |
22 | 25 | ServerError, |
23 | 26 | ) |
| 27 | +from ._objects import APIObject |
24 | 28 | from .asyncio import ( |
25 | 29 | api as _api, |
26 | 30 | ) |
|
48 | 52 | __version_tuple__ = (0, 0, 0) |
49 | 53 |
|
50 | 54 |
|
51 | | -@_sync |
52 | 55 | class Api(_AsyncApi): |
53 | | - __doc__ = _AsyncApi.__doc__ |
| 56 | + _asyncio = False |
| 57 | + |
| 58 | + def version(self) -> dict: # type: ignore |
| 59 | + return _run_sync(self.async_version)() # type: ignore |
| 60 | + |
| 61 | + def reauthenticate(self): # type: ignore |
| 62 | + return _run_sync(self.async_reauthenticate)() # type: ignore |
| 63 | + |
| 64 | + def whoami(self): # type: ignore |
| 65 | + return _run_sync(self.async_whoami)() # type: ignore |
| 66 | + |
| 67 | + def lookup_kind(self, kind) -> tuple[str, str, bool]: # type: ignore |
| 68 | + return _run_sync(self.async_lookup_kind)(kind) # type: ignore |
| 69 | + |
| 70 | + def get( # type: ignore |
| 71 | + self, |
| 72 | + kind: str | type, |
| 73 | + *names: str, |
| 74 | + namespace: str | None = None, |
| 75 | + label_selector: str | dict | None = None, |
| 76 | + field_selector: str | dict | None = None, |
| 77 | + as_object: type[APIObject] | None = None, |
| 78 | + allow_unknown_type: bool = True, |
| 79 | + **kwargs, |
| 80 | + ) -> Generator[APIObject]: |
| 81 | + yield from _run_sync(self.async_get)( |
| 82 | + kind, |
| 83 | + *names, |
| 84 | + namespace=namespace, |
| 85 | + label_selector=label_selector, |
| 86 | + field_selector=field_selector, |
| 87 | + as_object=as_object, |
| 88 | + allow_unknown_type=allow_unknown_type, |
| 89 | + **kwargs, |
| 90 | + ) |
| 91 | + |
| 92 | + def watch( # type: ignore |
| 93 | + self, |
| 94 | + kind: str, |
| 95 | + namespace: str | None = None, |
| 96 | + label_selector: str | dict | None = None, |
| 97 | + field_selector: str | dict | None = None, |
| 98 | + since: str | None = None, |
| 99 | + ) -> Generator[tuple[str, APIObject]]: |
| 100 | + yield from _run_sync(self.async_watch)( |
| 101 | + kind, |
| 102 | + namespace=namespace, |
| 103 | + label_selector=label_selector, |
| 104 | + field_selector=field_selector, |
| 105 | + since=since, |
| 106 | + ) |
| 107 | + |
| 108 | + def api_resources(self) -> list[dict]: # type: ignore |
| 109 | + return _run_sync(self.async_api_resources)() # type: ignore |
| 110 | + |
| 111 | + def api_versions(self) -> Generator[str]: # type: ignore |
| 112 | + yield from _run_sync(self.async_api_versions)() |
54 | 113 |
|
55 | 114 |
|
56 | 115 | def get( |
57 | 116 | kind: str, |
58 | 117 | *names: str, |
59 | | - namespace: Optional[str] = None, |
60 | | - label_selector: Optional[Union[str, Dict]] = None, |
61 | | - field_selector: Optional[Union[str, Dict]] = None, |
62 | | - as_object: Optional[Type] = None, |
| 118 | + namespace: str | None = None, |
| 119 | + label_selector: str | dict | None = None, |
| 120 | + field_selector: str | dict | None = None, |
| 121 | + as_object: type | None = None, |
63 | 122 | allow_unknown_type: bool = True, |
64 | 123 | api=None, |
65 | 124 | **kwargs, |
@@ -109,12 +168,12 @@ def get( |
109 | 168 |
|
110 | 169 |
|
111 | 170 | def api( |
112 | | - url: Optional[str] = None, |
113 | | - kubeconfig: Optional[str] = None, |
114 | | - serviceaccount: Optional[str] = None, |
115 | | - namespace: Optional[str] = None, |
116 | | - context: Optional[str] = None, |
117 | | -) -> Union[Api, _AsyncApi]: |
| 171 | + url: str | None = None, |
| 172 | + kubeconfig: str | None = None, |
| 173 | + serviceaccount: str | None = None, |
| 174 | + namespace: str | None = None, |
| 175 | + context: str | None = None, |
| 176 | +) -> Api: |
118 | 177 | """Create a :class:`kr8s.Api` object for interacting with the Kubernetes API. |
119 | 178 |
|
120 | 179 | If a kr8s object already exists with the same arguments in this thread, it will be returned. |
@@ -142,7 +201,7 @@ def api( |
142 | 201 | context=context, |
143 | 202 | _asyncio=False, |
144 | 203 | ) |
145 | | - assert isinstance(ret, (Api, _AsyncApi)) |
| 204 | + assert isinstance(ret, Api) |
146 | 205 | return ret |
147 | 206 |
|
148 | 207 |
|
|
0 commit comments