Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/runloop_api_client/sdk/async_.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async def create(
devbox_view = await self._client.devboxes.create_and_await_running(
**params,
)
return AsyncDevbox(self._client, devbox_view.id)
return AsyncDevbox(self._client, devbox_view)

async def create_from_blueprint_id(
self,
Expand All @@ -101,7 +101,7 @@ async def create_from_blueprint_id(
blueprint_id=blueprint_id,
**params,
)
return AsyncDevbox(self._client, devbox_view.id)
return AsyncDevbox(self._client, devbox_view)

async def create_from_blueprint_name(
self,
Expand All @@ -120,7 +120,7 @@ async def create_from_blueprint_name(
blueprint_name=blueprint_name,
**params,
)
return AsyncDevbox(self._client, devbox_view.id)
return AsyncDevbox(self._client, devbox_view)

async def create_from_snapshot(
self,
Expand All @@ -139,9 +139,9 @@ async def create_from_snapshot(
snapshot_id=snapshot_id,
**params,
)
return AsyncDevbox(self._client, devbox_view.id)
return AsyncDevbox(self._client, devbox_view)

def from_id(self, devbox_id: str) -> AsyncDevbox:
async def from_id(self, devbox_id: str) -> AsyncDevbox:
"""Attach to an existing devbox by ID.

Returns immediately without waiting for the devbox to reach ``running``
Expand All @@ -153,7 +153,8 @@ def from_id(self, devbox_id: str) -> AsyncDevbox:
:return: Wrapper bound to the requested devbox
:rtype: AsyncDevbox
"""
return AsyncDevbox(self._client, devbox_id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also see pydoc above referencing intentionally being a quick return with option for user to await retrieve

devbox_view = await self._client.devboxes.retrieve(devbox_id)
return AsyncDevbox(self._client, devbox_view)

async def list(
self,
Expand All @@ -168,7 +169,7 @@ async def list(
page = await self._client.devboxes.list(
**params,
)
return [AsyncDevbox(self._client, item.id) for item in page.devboxes]
return [AsyncDevbox(self._client, item) for item in page.devboxes]


class AsyncSnapshotOps:
Expand Down
2 changes: 1 addition & 1 deletion src/runloop_api_client/sdk/async_blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,4 @@ async def create_devbox(
blueprint_id=self._id,
**params,
)
return AsyncDevbox(self._client, devbox_view.id)
return AsyncDevbox(self._client, devbox_view)
43 changes: 39 additions & 4 deletions src/runloop_api_client/sdk/async_devbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,21 @@ class AsyncDevbox:
# Devbox is automatically shut down on exit
"""

def __init__(self, client: AsyncRunloop, devbox_id: str) -> None:
def __init__(
self,
client: AsyncRunloop,
devbox_view: DevboxView,
) -> None:
"""Initialize the wrapper.

:param client: Generated async Runloop client
:type client: AsyncRunloop
:param devbox_id: Devbox identifier returned by the API
:type devbox_id: str
:param devbox_view: DevboxView from the API
:type devbox_view: DevboxView
"""
self._client = client
self._id = devbox_id
self._id = devbox_view.id
self._tunnel: Optional[TunnelView] = devbox_view.tunnel
self._logger = logging.getLogger(__name__)

@override
Expand Down Expand Up @@ -104,6 +109,18 @@ def id(self) -> str:
"""
return self._id

@property
def tunnel(self) -> Optional[TunnelView]:
"""Return the cached tunnel info, if available.

This returns the tunnel info cached at creation time. For the latest
tunnel state, use :meth:`get_info` or :meth:`net.view_tunnel`.

:return: Cached tunnel info, or None if no tunnel was enabled at creation
:rtype: TunnelView | None
"""
return self._tunnel

async def get_info(
self,
**options: Unpack[BaseRequestOptions],
Expand Down Expand Up @@ -776,6 +793,24 @@ async def enable_tunnel(
**params,
)

async def view_tunnel(
self,
**options: Unpack[BaseRequestOptions],
) -> Optional[TunnelView]:
"""Retrieve the current tunnel info for this devbox, if one exists.

:param options: Optional request configuration
:return: Current tunnel info, or None if no tunnel is enabled
:rtype: TunnelView | None

Example:
>>> tunnel = await devbox.net.view_tunnel()
>>> if tunnel:
... print(f"Tunnel key: {tunnel.tunnel_key}")
"""
info = await self._devbox.get_info(**options)
return info.tunnel

async def remove_tunnel(
self,
**params: Unpack[SDKDevboxRemoveTunnelParams],
Expand Down
9 changes: 4 additions & 5 deletions src/runloop_api_client/sdk/async_scenario_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import os
from typing import Union, Optional
from functools import cached_property
from typing_extensions import Unpack, override

from ..types import ScenarioRunView
Expand Down Expand Up @@ -68,16 +67,16 @@ def devbox_id(self) -> str:
"""
return self._devbox_id

@cached_property
def devbox(self) -> AsyncDevbox:
"""The devbox instance for this scenario run.
async def get_devbox(self) -> AsyncDevbox:
"""Get the devbox instance for this scenario run.

Use this to interact with the devbox environment during the scenario run.

:return: AsyncDevbox instance
:rtype: AsyncDevbox
"""
return AsyncDevbox(self._client, self._devbox_id)
devbox_view = await self._client.devboxes.retrieve(self._devbox_id)
return AsyncDevbox(self._client, devbox_view)

async def get_info(
self,
Expand Down
2 changes: 1 addition & 1 deletion src/runloop_api_client/sdk/async_snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,4 @@ async def create_devbox(
snapshot_id=self._id,
**params,
)
return AsyncDevbox(self._client, devbox_view.id)
return AsyncDevbox(self._client, devbox_view)
2 changes: 1 addition & 1 deletion src/runloop_api_client/sdk/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,4 @@ def create_devbox(
blueprint_id=self._id,
**params,
)
return Devbox(self._client, devbox_view.id)
return Devbox(self._client, devbox_view)
43 changes: 39 additions & 4 deletions src/runloop_api_client/sdk/devbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,21 @@ class Devbox:
# Devbox is automatically shutdown on exit
"""

def __init__(self, client: Runloop, devbox_id: str) -> None:
def __init__(
self,
client: Runloop,
devbox_view: DevboxView,
) -> None:
"""Initialize the wrapper.

:param client: Generated Runloop client
:type client: Runloop
:param devbox_id: Devbox identifier returned by the API
:type devbox_id: str
:param devbox_view: DevboxView from the API
:type devbox_view: DevboxView
"""
self._client = client
self._id = devbox_id
self._id = devbox_view.id
self._tunnel: Optional[TunnelView] = devbox_view.tunnel
self._logger = logging.getLogger(__name__)

@override
Expand Down Expand Up @@ -103,6 +108,18 @@ def id(self) -> str:
"""
return self._id

@property
def tunnel(self) -> Optional[TunnelView]:
"""Return the cached tunnel info, if available.

This returns the tunnel info cached at creation time. For the latest
tunnel state, use :meth:`get_info` or :meth:`net.view_tunnel`.

:return: Cached tunnel info, or None if no tunnel was enabled at creation
:rtype: TunnelView | None
"""
return self._tunnel

def get_info(
self,
**options: Unpack[BaseRequestOptions],
Expand Down Expand Up @@ -779,6 +796,24 @@ def enable_tunnel(
**params,
)

def view_tunnel(
self,
**options: Unpack[BaseRequestOptions],
) -> Optional[TunnelView]:
"""Retrieve the current tunnel info for this devbox, if one exists.

:param options: Optional request configuration
:return: Current tunnel info, or None if no tunnel is enabled
:rtype: TunnelView | None

Example:
>>> tunnel = devbox.net.view_tunnel()
>>> if tunnel:
... print(f"Tunnel key: {tunnel.tunnel_key}")
"""
info = self._devbox.get_info(**options)
return info.tunnel

def remove_tunnel(
self,
**params: Unpack[SDKDevboxRemoveTunnelParams],
Expand Down
3 changes: 2 additions & 1 deletion src/runloop_api_client/sdk/scenario_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ def devbox(self) -> Devbox:
:return: Devbox instance
:rtype: Devbox
"""
return Devbox(self._client, self._devbox_id)
devbox_view = self._client.devboxes.retrieve(self._devbox_id)
return Devbox(self._client, devbox_view)

def get_info(
self,
Expand Down
2 changes: 1 addition & 1 deletion src/runloop_api_client/sdk/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,4 @@ def create_devbox(
snapshot_id=self._id,
**params,
)
return Devbox(self._client, devbox_view.id)
return Devbox(self._client, devbox_view)
13 changes: 7 additions & 6 deletions src/runloop_api_client/sdk/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def create(
devbox_view = self._client.devboxes.create_and_await_running(
**params,
)
return Devbox(self._client, devbox_view.id)
return Devbox(self._client, devbox_view)

def create_from_blueprint_id(
self,
Expand All @@ -100,7 +100,7 @@ def create_from_blueprint_id(
blueprint_id=blueprint_id,
**params,
)
return Devbox(self._client, devbox_view.id)
return Devbox(self._client, devbox_view)

def create_from_blueprint_name(
self,
Expand All @@ -119,7 +119,7 @@ def create_from_blueprint_name(
blueprint_name=blueprint_name,
**params,
)
return Devbox(self._client, devbox_view.id)
return Devbox(self._client, devbox_view)

def create_from_snapshot(
self,
Expand All @@ -138,7 +138,7 @@ def create_from_snapshot(
snapshot_id=snapshot_id,
**params,
)
return Devbox(self._client, devbox_view.id)
return Devbox(self._client, devbox_view)

def from_id(self, devbox_id: str) -> Devbox:
"""Attach to an existing devbox by ID.
Expand All @@ -152,7 +152,8 @@ def from_id(self, devbox_id: str) -> Devbox:
:rtype: Devbox
"""
self._client.devboxes.await_running(devbox_id)
return Devbox(self._client, devbox_id)
devbox_view = self._client.devboxes.retrieve(devbox_id)
return Devbox(self._client, devbox_view)

def list(
self,
Expand All @@ -167,7 +168,7 @@ def list(
page = self._client.devboxes.list(
**params,
)
return [Devbox(self._client, item.id) for item in page.devboxes]
return [Devbox(self._client, item) for item in page.devboxes]


class SnapshotOps:
Expand Down
Loading