|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
5 | 5 | import os |
6 | | -from typing import Any, Mapping |
| 6 | +from typing import TYPE_CHECKING, Any, Mapping |
7 | 7 | from typing_extensions import Self, override |
8 | 8 |
|
9 | 9 | import httpx |
|
21 | 21 | not_given, |
22 | 22 | ) |
23 | 23 | from ._utils import is_given, get_async_library |
| 24 | +from ._compat import cached_property |
24 | 25 | from ._version import __version__ |
25 | | -from .resources import apps, hooks |
26 | 26 | from ._streaming import Stream as Stream, AsyncStream as AsyncStream |
27 | 27 | from ._exceptions import APIStatusError |
28 | 28 | from ._base_client import ( |
29 | 29 | DEFAULT_MAX_RETRIES, |
30 | 30 | SyncAPIClient, |
31 | 31 | AsyncAPIClient, |
32 | 32 | ) |
33 | | -from .resources.tasks import tasks |
34 | | -from .resources.devices import devices |
35 | | -from .resources.credentials import credentials |
| 33 | + |
| 34 | +if TYPE_CHECKING: |
| 35 | + from .resources import apps, hooks, tasks, devices, credentials |
| 36 | + from .resources.apps import AppsResource, AsyncAppsResource |
| 37 | + from .resources.hooks import HooksResource, AsyncHooksResource |
| 38 | + from .resources.tasks.tasks import TasksResource, AsyncTasksResource |
| 39 | + from .resources.devices.devices import DevicesResource, AsyncDevicesResource |
| 40 | + from .resources.credentials.credentials import CredentialsResource, AsyncCredentialsResource |
36 | 41 |
|
37 | 42 | __all__ = [ |
38 | 43 | "Timeout", |
|
47 | 52 |
|
48 | 53 |
|
49 | 54 | class Mobilerun(SyncAPIClient): |
50 | | - tasks: tasks.TasksResource |
51 | | - devices: devices.DevicesResource |
52 | | - apps: apps.AppsResource |
53 | | - credentials: credentials.CredentialsResource |
54 | | - hooks: hooks.HooksResource |
55 | | - with_raw_response: MobilerunWithRawResponse |
56 | | - with_streaming_response: MobilerunWithStreamedResponse |
57 | | - |
58 | 55 | # client options |
59 | 56 | api_key: str | None |
60 | 57 |
|
@@ -105,13 +102,43 @@ def __init__( |
105 | 102 | _strict_response_validation=_strict_response_validation, |
106 | 103 | ) |
107 | 104 |
|
108 | | - self.tasks = tasks.TasksResource(self) |
109 | | - self.devices = devices.DevicesResource(self) |
110 | | - self.apps = apps.AppsResource(self) |
111 | | - self.credentials = credentials.CredentialsResource(self) |
112 | | - self.hooks = hooks.HooksResource(self) |
113 | | - self.with_raw_response = MobilerunWithRawResponse(self) |
114 | | - self.with_streaming_response = MobilerunWithStreamedResponse(self) |
| 105 | + @cached_property |
| 106 | + def tasks(self) -> TasksResource: |
| 107 | + from .resources.tasks import TasksResource |
| 108 | + |
| 109 | + return TasksResource(self) |
| 110 | + |
| 111 | + @cached_property |
| 112 | + def devices(self) -> DevicesResource: |
| 113 | + from .resources.devices import DevicesResource |
| 114 | + |
| 115 | + return DevicesResource(self) |
| 116 | + |
| 117 | + @cached_property |
| 118 | + def apps(self) -> AppsResource: |
| 119 | + from .resources.apps import AppsResource |
| 120 | + |
| 121 | + return AppsResource(self) |
| 122 | + |
| 123 | + @cached_property |
| 124 | + def credentials(self) -> CredentialsResource: |
| 125 | + from .resources.credentials import CredentialsResource |
| 126 | + |
| 127 | + return CredentialsResource(self) |
| 128 | + |
| 129 | + @cached_property |
| 130 | + def hooks(self) -> HooksResource: |
| 131 | + from .resources.hooks import HooksResource |
| 132 | + |
| 133 | + return HooksResource(self) |
| 134 | + |
| 135 | + @cached_property |
| 136 | + def with_raw_response(self) -> MobilerunWithRawResponse: |
| 137 | + return MobilerunWithRawResponse(self) |
| 138 | + |
| 139 | + @cached_property |
| 140 | + def with_streaming_response(self) -> MobilerunWithStreamedResponse: |
| 141 | + return MobilerunWithStreamedResponse(self) |
115 | 142 |
|
116 | 143 | @property |
117 | 144 | @override |
@@ -232,14 +259,6 @@ def _make_status_error( |
232 | 259 |
|
233 | 260 |
|
234 | 261 | class AsyncMobilerun(AsyncAPIClient): |
235 | | - tasks: tasks.AsyncTasksResource |
236 | | - devices: devices.AsyncDevicesResource |
237 | | - apps: apps.AsyncAppsResource |
238 | | - credentials: credentials.AsyncCredentialsResource |
239 | | - hooks: hooks.AsyncHooksResource |
240 | | - with_raw_response: AsyncMobilerunWithRawResponse |
241 | | - with_streaming_response: AsyncMobilerunWithStreamedResponse |
242 | | - |
243 | 262 | # client options |
244 | 263 | api_key: str | None |
245 | 264 |
|
@@ -290,13 +309,43 @@ def __init__( |
290 | 309 | _strict_response_validation=_strict_response_validation, |
291 | 310 | ) |
292 | 311 |
|
293 | | - self.tasks = tasks.AsyncTasksResource(self) |
294 | | - self.devices = devices.AsyncDevicesResource(self) |
295 | | - self.apps = apps.AsyncAppsResource(self) |
296 | | - self.credentials = credentials.AsyncCredentialsResource(self) |
297 | | - self.hooks = hooks.AsyncHooksResource(self) |
298 | | - self.with_raw_response = AsyncMobilerunWithRawResponse(self) |
299 | | - self.with_streaming_response = AsyncMobilerunWithStreamedResponse(self) |
| 312 | + @cached_property |
| 313 | + def tasks(self) -> AsyncTasksResource: |
| 314 | + from .resources.tasks import AsyncTasksResource |
| 315 | + |
| 316 | + return AsyncTasksResource(self) |
| 317 | + |
| 318 | + @cached_property |
| 319 | + def devices(self) -> AsyncDevicesResource: |
| 320 | + from .resources.devices import AsyncDevicesResource |
| 321 | + |
| 322 | + return AsyncDevicesResource(self) |
| 323 | + |
| 324 | + @cached_property |
| 325 | + def apps(self) -> AsyncAppsResource: |
| 326 | + from .resources.apps import AsyncAppsResource |
| 327 | + |
| 328 | + return AsyncAppsResource(self) |
| 329 | + |
| 330 | + @cached_property |
| 331 | + def credentials(self) -> AsyncCredentialsResource: |
| 332 | + from .resources.credentials import AsyncCredentialsResource |
| 333 | + |
| 334 | + return AsyncCredentialsResource(self) |
| 335 | + |
| 336 | + @cached_property |
| 337 | + def hooks(self) -> AsyncHooksResource: |
| 338 | + from .resources.hooks import AsyncHooksResource |
| 339 | + |
| 340 | + return AsyncHooksResource(self) |
| 341 | + |
| 342 | + @cached_property |
| 343 | + def with_raw_response(self) -> AsyncMobilerunWithRawResponse: |
| 344 | + return AsyncMobilerunWithRawResponse(self) |
| 345 | + |
| 346 | + @cached_property |
| 347 | + def with_streaming_response(self) -> AsyncMobilerunWithStreamedResponse: |
| 348 | + return AsyncMobilerunWithStreamedResponse(self) |
300 | 349 |
|
301 | 350 | @property |
302 | 351 | @override |
@@ -417,39 +466,151 @@ def _make_status_error( |
417 | 466 |
|
418 | 467 |
|
419 | 468 | class MobilerunWithRawResponse: |
| 469 | + _client: Mobilerun |
| 470 | + |
420 | 471 | def __init__(self, client: Mobilerun) -> None: |
421 | | - self.tasks = tasks.TasksResourceWithRawResponse(client.tasks) |
422 | | - self.devices = devices.DevicesResourceWithRawResponse(client.devices) |
423 | | - self.apps = apps.AppsResourceWithRawResponse(client.apps) |
424 | | - self.credentials = credentials.CredentialsResourceWithRawResponse(client.credentials) |
425 | | - self.hooks = hooks.HooksResourceWithRawResponse(client.hooks) |
| 472 | + self._client = client |
| 473 | + |
| 474 | + @cached_property |
| 475 | + def tasks(self) -> tasks.TasksResourceWithRawResponse: |
| 476 | + from .resources.tasks import TasksResourceWithRawResponse |
| 477 | + |
| 478 | + return TasksResourceWithRawResponse(self._client.tasks) |
| 479 | + |
| 480 | + @cached_property |
| 481 | + def devices(self) -> devices.DevicesResourceWithRawResponse: |
| 482 | + from .resources.devices import DevicesResourceWithRawResponse |
| 483 | + |
| 484 | + return DevicesResourceWithRawResponse(self._client.devices) |
| 485 | + |
| 486 | + @cached_property |
| 487 | + def apps(self) -> apps.AppsResourceWithRawResponse: |
| 488 | + from .resources.apps import AppsResourceWithRawResponse |
| 489 | + |
| 490 | + return AppsResourceWithRawResponse(self._client.apps) |
| 491 | + |
| 492 | + @cached_property |
| 493 | + def credentials(self) -> credentials.CredentialsResourceWithRawResponse: |
| 494 | + from .resources.credentials import CredentialsResourceWithRawResponse |
| 495 | + |
| 496 | + return CredentialsResourceWithRawResponse(self._client.credentials) |
| 497 | + |
| 498 | + @cached_property |
| 499 | + def hooks(self) -> hooks.HooksResourceWithRawResponse: |
| 500 | + from .resources.hooks import HooksResourceWithRawResponse |
| 501 | + |
| 502 | + return HooksResourceWithRawResponse(self._client.hooks) |
426 | 503 |
|
427 | 504 |
|
428 | 505 | class AsyncMobilerunWithRawResponse: |
| 506 | + _client: AsyncMobilerun |
| 507 | + |
429 | 508 | def __init__(self, client: AsyncMobilerun) -> None: |
430 | | - self.tasks = tasks.AsyncTasksResourceWithRawResponse(client.tasks) |
431 | | - self.devices = devices.AsyncDevicesResourceWithRawResponse(client.devices) |
432 | | - self.apps = apps.AsyncAppsResourceWithRawResponse(client.apps) |
433 | | - self.credentials = credentials.AsyncCredentialsResourceWithRawResponse(client.credentials) |
434 | | - self.hooks = hooks.AsyncHooksResourceWithRawResponse(client.hooks) |
| 509 | + self._client = client |
| 510 | + |
| 511 | + @cached_property |
| 512 | + def tasks(self) -> tasks.AsyncTasksResourceWithRawResponse: |
| 513 | + from .resources.tasks import AsyncTasksResourceWithRawResponse |
| 514 | + |
| 515 | + return AsyncTasksResourceWithRawResponse(self._client.tasks) |
| 516 | + |
| 517 | + @cached_property |
| 518 | + def devices(self) -> devices.AsyncDevicesResourceWithRawResponse: |
| 519 | + from .resources.devices import AsyncDevicesResourceWithRawResponse |
| 520 | + |
| 521 | + return AsyncDevicesResourceWithRawResponse(self._client.devices) |
| 522 | + |
| 523 | + @cached_property |
| 524 | + def apps(self) -> apps.AsyncAppsResourceWithRawResponse: |
| 525 | + from .resources.apps import AsyncAppsResourceWithRawResponse |
| 526 | + |
| 527 | + return AsyncAppsResourceWithRawResponse(self._client.apps) |
| 528 | + |
| 529 | + @cached_property |
| 530 | + def credentials(self) -> credentials.AsyncCredentialsResourceWithRawResponse: |
| 531 | + from .resources.credentials import AsyncCredentialsResourceWithRawResponse |
| 532 | + |
| 533 | + return AsyncCredentialsResourceWithRawResponse(self._client.credentials) |
| 534 | + |
| 535 | + @cached_property |
| 536 | + def hooks(self) -> hooks.AsyncHooksResourceWithRawResponse: |
| 537 | + from .resources.hooks import AsyncHooksResourceWithRawResponse |
| 538 | + |
| 539 | + return AsyncHooksResourceWithRawResponse(self._client.hooks) |
435 | 540 |
|
436 | 541 |
|
437 | 542 | class MobilerunWithStreamedResponse: |
| 543 | + _client: Mobilerun |
| 544 | + |
438 | 545 | def __init__(self, client: Mobilerun) -> None: |
439 | | - self.tasks = tasks.TasksResourceWithStreamingResponse(client.tasks) |
440 | | - self.devices = devices.DevicesResourceWithStreamingResponse(client.devices) |
441 | | - self.apps = apps.AppsResourceWithStreamingResponse(client.apps) |
442 | | - self.credentials = credentials.CredentialsResourceWithStreamingResponse(client.credentials) |
443 | | - self.hooks = hooks.HooksResourceWithStreamingResponse(client.hooks) |
| 546 | + self._client = client |
| 547 | + |
| 548 | + @cached_property |
| 549 | + def tasks(self) -> tasks.TasksResourceWithStreamingResponse: |
| 550 | + from .resources.tasks import TasksResourceWithStreamingResponse |
| 551 | + |
| 552 | + return TasksResourceWithStreamingResponse(self._client.tasks) |
| 553 | + |
| 554 | + @cached_property |
| 555 | + def devices(self) -> devices.DevicesResourceWithStreamingResponse: |
| 556 | + from .resources.devices import DevicesResourceWithStreamingResponse |
| 557 | + |
| 558 | + return DevicesResourceWithStreamingResponse(self._client.devices) |
| 559 | + |
| 560 | + @cached_property |
| 561 | + def apps(self) -> apps.AppsResourceWithStreamingResponse: |
| 562 | + from .resources.apps import AppsResourceWithStreamingResponse |
| 563 | + |
| 564 | + return AppsResourceWithStreamingResponse(self._client.apps) |
| 565 | + |
| 566 | + @cached_property |
| 567 | + def credentials(self) -> credentials.CredentialsResourceWithStreamingResponse: |
| 568 | + from .resources.credentials import CredentialsResourceWithStreamingResponse |
| 569 | + |
| 570 | + return CredentialsResourceWithStreamingResponse(self._client.credentials) |
| 571 | + |
| 572 | + @cached_property |
| 573 | + def hooks(self) -> hooks.HooksResourceWithStreamingResponse: |
| 574 | + from .resources.hooks import HooksResourceWithStreamingResponse |
| 575 | + |
| 576 | + return HooksResourceWithStreamingResponse(self._client.hooks) |
444 | 577 |
|
445 | 578 |
|
446 | 579 | class AsyncMobilerunWithStreamedResponse: |
| 580 | + _client: AsyncMobilerun |
| 581 | + |
447 | 582 | def __init__(self, client: AsyncMobilerun) -> None: |
448 | | - self.tasks = tasks.AsyncTasksResourceWithStreamingResponse(client.tasks) |
449 | | - self.devices = devices.AsyncDevicesResourceWithStreamingResponse(client.devices) |
450 | | - self.apps = apps.AsyncAppsResourceWithStreamingResponse(client.apps) |
451 | | - self.credentials = credentials.AsyncCredentialsResourceWithStreamingResponse(client.credentials) |
452 | | - self.hooks = hooks.AsyncHooksResourceWithStreamingResponse(client.hooks) |
| 583 | + self._client = client |
| 584 | + |
| 585 | + @cached_property |
| 586 | + def tasks(self) -> tasks.AsyncTasksResourceWithStreamingResponse: |
| 587 | + from .resources.tasks import AsyncTasksResourceWithStreamingResponse |
| 588 | + |
| 589 | + return AsyncTasksResourceWithStreamingResponse(self._client.tasks) |
| 590 | + |
| 591 | + @cached_property |
| 592 | + def devices(self) -> devices.AsyncDevicesResourceWithStreamingResponse: |
| 593 | + from .resources.devices import AsyncDevicesResourceWithStreamingResponse |
| 594 | + |
| 595 | + return AsyncDevicesResourceWithStreamingResponse(self._client.devices) |
| 596 | + |
| 597 | + @cached_property |
| 598 | + def apps(self) -> apps.AsyncAppsResourceWithStreamingResponse: |
| 599 | + from .resources.apps import AsyncAppsResourceWithStreamingResponse |
| 600 | + |
| 601 | + return AsyncAppsResourceWithStreamingResponse(self._client.apps) |
| 602 | + |
| 603 | + @cached_property |
| 604 | + def credentials(self) -> credentials.AsyncCredentialsResourceWithStreamingResponse: |
| 605 | + from .resources.credentials import AsyncCredentialsResourceWithStreamingResponse |
| 606 | + |
| 607 | + return AsyncCredentialsResourceWithStreamingResponse(self._client.credentials) |
| 608 | + |
| 609 | + @cached_property |
| 610 | + def hooks(self) -> hooks.AsyncHooksResourceWithStreamingResponse: |
| 611 | + from .resources.hooks import AsyncHooksResourceWithStreamingResponse |
| 612 | + |
| 613 | + return AsyncHooksResourceWithStreamingResponse(self._client.hooks) |
453 | 614 |
|
454 | 615 |
|
455 | 616 | Client = Mobilerun |
|
0 commit comments