-
Notifications
You must be signed in to change notification settings - Fork 2
feat(scenarios): added scenario class to sdk #701
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
a8bf27f
uv lock upgrade
sid-rl 5e07fee
scenario wrapper
sid-rl ed187e7
modified ScenarioStartRunParams to follow our previous pattern for us…
sid-rl 45d0ab3
fixed redundancy and formatting in scenario and scenario run unit tests
sid-rl f204cee
formatting fixes
sid-rl dc8a68e
changed scenario and scenario smoketests to update existing scenarios…
sid-rl 23e625b
changed scenario run methods to `run` and `run_async`, updated parame…
sid-rl 79ea205
exposed all scenario update parameters appropriately using typeddict
sid-rl eee6b78
formatting fixes
sid-rl 7ca3154
remove scenario builder smoketests
sid-rl 82f3597
add score_and_complete and download_logs methods to scenario runs, an…
sid-rl e35a745
add unit tests for ScenarioOps and AsyncScenarioOps
sid-rl de0a302
update tests for scenario.update and change test name for scenario.ru…
sid-rl 94b56ea
add unit tests for download_logs and score_and_complete
sid-rl f152b36
don't pass polling_config to get_info within await_env_ready
sid-rl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| """AsyncScenario resource class for asynchronous operations.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing_extensions import Unpack, override | ||
|
|
||
| from ..types import ScenarioView | ||
| from ._types import BaseRequestOptions, SDKScenarioRunParams, SDKScenarioUpdateParams, SDKScenarioRunAsyncParams | ||
| from .._client import AsyncRunloop | ||
| from .async_scenario_run import AsyncScenarioRun | ||
|
|
||
|
|
||
| class AsyncScenario: | ||
| """Async wrapper around a scenario resource. | ||
|
|
||
| Provides async methods for retrieving scenario details, updating the scenario, | ||
| and starting scenario runs. | ||
|
|
||
| Example: | ||
| >>> scenario = sdk.scenario.from_id("scn-xxx") | ||
| >>> info = await scenario.get_info() | ||
| >>> run = await scenario.run(run_name="test-run") | ||
| >>> devbox = run.devbox | ||
| """ | ||
|
|
||
| def __init__(self, client: AsyncRunloop, scenario_id: str) -> None: | ||
| """Initialize the wrapper. | ||
|
||
|
|
||
| :param client: Generated AsyncRunloop client | ||
| :type client: AsyncRunloop | ||
| :param scenario_id: Scenario ID returned by the API | ||
| :type scenario_id: str | ||
| """ | ||
| self._client = client | ||
| self._id = scenario_id | ||
|
|
||
| @override | ||
| def __repr__(self) -> str: | ||
| return f"<AsyncScenario id={self._id!r}>" | ||
|
|
||
| @property | ||
| def id(self) -> str: | ||
| """Return the scenario ID. | ||
|
|
||
| :return: Unique scenario ID | ||
| :rtype: str | ||
| """ | ||
| return self._id | ||
|
|
||
| async def get_info( | ||
| self, | ||
| **options: Unpack[BaseRequestOptions], | ||
| ) -> ScenarioView: | ||
| """Retrieve current scenario details. | ||
|
|
||
| :param options: Optional request configuration | ||
| :return: Current scenario info | ||
| :rtype: ScenarioView | ||
| """ | ||
| return await self._client.scenarios.retrieve( | ||
| self._id, | ||
| **options, | ||
| ) | ||
|
|
||
| async def update( | ||
| self, | ||
| **params: Unpack[SDKScenarioUpdateParams], | ||
| ) -> ScenarioView: | ||
| """Update the scenario. | ||
|
|
||
| Only provided fields will be updated. | ||
|
|
||
| :param params: See SDKScenarioUpdateParams for available parameters | ||
| :return: Updated scenario info | ||
| :rtype: ScenarioView | ||
| """ | ||
| return await self._client.scenarios.update( | ||
| self._id, | ||
| **params, | ||
| ) | ||
|
|
||
| async def run_async( | ||
| self, | ||
| **params: Unpack[SDKScenarioRunAsyncParams], | ||
| ) -> AsyncScenarioRun: | ||
| """Start a new scenario run. | ||
|
|
||
| Creates a new scenario run and returns a wrapper for managing it. | ||
| The underlying devbox may still be starting; call await_env_ready() | ||
| on the returned AsyncScenarioRun to wait for it to be ready. | ||
|
|
||
| :param params: See SDKScenarioRunParams for available parameters | ||
| :return: Wrapper for the new scenario run | ||
| :rtype: AsyncScenarioRun | ||
| """ | ||
| run_view = await self._client.scenarios.start_run( | ||
| scenario_id=self._id, | ||
| **params, | ||
| ) | ||
| return AsyncScenarioRun(self._client, run_view.id, run_view.devbox_id) | ||
|
|
||
| async def run( | ||
| self, | ||
| **params: Unpack[SDKScenarioRunParams], | ||
| ) -> AsyncScenarioRun: | ||
| """Start a new scenario run and wait for environment to be ready. | ||
|
|
||
| Convenience method that starts a run and waits for the devbox to be ready. | ||
|
|
||
| :param params: See SDKScenarioRunParams for available parameters | ||
| :return: Wrapper for the scenario run with ready environment | ||
| :rtype: AsyncScenarioRun | ||
| """ | ||
| run_view = await self._client.scenarios.start_run_and_await_env_ready( | ||
| scenario_id=self._id, | ||
| **params, | ||
| ) | ||
| return AsyncScenarioRun(self._client, run_view.id, run_view.devbox_id) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get rid of the
Async wrappercomment. It doesn't add value and it leaks system internals