Skip to content

Commit 9ee3621

Browse files
chore: speedup initial import
1 parent 907c05f commit 9ee3621

1 file changed

Lines changed: 216 additions & 55 deletions

File tree

src/mobilerun/_client.py

Lines changed: 216 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from __future__ import annotations
44

55
import os
6-
from typing import Any, Mapping
6+
from typing import TYPE_CHECKING, Any, Mapping
77
from typing_extensions import Self, override
88

99
import httpx
@@ -21,18 +21,23 @@
2121
not_given,
2222
)
2323
from ._utils import is_given, get_async_library
24+
from ._compat import cached_property
2425
from ._version import __version__
25-
from .resources import apps, hooks
2626
from ._streaming import Stream as Stream, AsyncStream as AsyncStream
2727
from ._exceptions import APIStatusError
2828
from ._base_client import (
2929
DEFAULT_MAX_RETRIES,
3030
SyncAPIClient,
3131
AsyncAPIClient,
3232
)
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
3641

3742
__all__ = [
3843
"Timeout",
@@ -47,14 +52,6 @@
4752

4853

4954
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-
5855
# client options
5956
api_key: str | None
6057

@@ -105,13 +102,43 @@ def __init__(
105102
_strict_response_validation=_strict_response_validation,
106103
)
107104

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)
115142

116143
@property
117144
@override
@@ -232,14 +259,6 @@ def _make_status_error(
232259

233260

234261
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-
243262
# client options
244263
api_key: str | None
245264

@@ -290,13 +309,43 @@ def __init__(
290309
_strict_response_validation=_strict_response_validation,
291310
)
292311

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)
300349

301350
@property
302351
@override
@@ -417,39 +466,151 @@ def _make_status_error(
417466

418467

419468
class MobilerunWithRawResponse:
469+
_client: Mobilerun
470+
420471
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)
426503

427504

428505
class AsyncMobilerunWithRawResponse:
506+
_client: AsyncMobilerun
507+
429508
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)
435540

436541

437542
class MobilerunWithStreamedResponse:
543+
_client: Mobilerun
544+
438545
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)
444577

445578

446579
class AsyncMobilerunWithStreamedResponse:
580+
_client: AsyncMobilerun
581+
447582
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)
453614

454615

455616
Client = Mobilerun

0 commit comments

Comments
 (0)