Skip to content

Commit f3f12ba

Browse files
committed
lint fixes
1 parent 7bf84bb commit f3f12ba

7 files changed

Lines changed: 254 additions & 256 deletions

File tree

examples/async_devbox.py

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,149 +9,148 @@
99
- Async command streaming
1010
"""
1111

12-
import asyncio
1312
import os
13+
import asyncio
14+
1415
from runloop_api_client import AsyncRunloopSDK
1516

1617

1718
async def demonstrate_basic_async():
1819
"""Demonstrate basic async devbox operations."""
1920
print("=== Basic Async Operations ===")
20-
21+
2122
sdk = AsyncRunloopSDK()
22-
23+
2324
# Create a devbox with async context manager
2425
async with sdk.devbox.create(name="async-example-devbox") as devbox:
2526
print(f"Created devbox: {devbox.id}")
26-
27+
2728
# Execute command asynchronously
2829
result = await devbox.cmd.exec("echo 'Hello from async devbox!'")
2930
output = await result.stdout()
3031
print(f"Command output: {output.strip()}")
31-
32+
3233
# File operations
3334
await devbox.file.write(
3435
path="/home/user/async_test.txt",
3536
contents="Hello from async operations!\n",
3637
)
3738
content = await devbox.file.read(path="/home/user/async_test.txt")
3839
print(f"File content: {content.strip()}")
39-
40+
4041
print("Devbox automatically shutdown\n")
4142

4243

4344
async def demonstrate_concurrent_commands():
4445
"""Execute multiple commands concurrently on the same devbox."""
4546
print("=== Concurrent Command Execution ===")
46-
47+
4748
sdk = AsyncRunloopSDK()
48-
49+
4950
async with sdk.devbox.create(name="concurrent-commands-devbox") as devbox:
5051
print(f"Created devbox: {devbox.id}")
51-
52+
5253
# Execute multiple commands concurrently
5354
async def run_command(cmd: str, label: str):
5455
print(f"Starting: {label}")
5556
result = await devbox.cmd.exec(cmd)
5657
output = await result.stdout()
5758
print(f"{label} completed: {output.strip()}")
5859
return output
59-
60+
6061
# Run multiple commands in parallel
6162
results = await asyncio.gather(
6263
run_command("echo 'Task 1' && sleep 1", "Task 1"),
6364
run_command("echo 'Task 2' && sleep 1", "Task 2"),
6465
run_command("echo 'Task 3' && sleep 1", "Task 3"),
6566
)
66-
67+
6768
print(f"All {len(results)} tasks completed\n")
6869

6970

7071
async def demonstrate_multiple_devboxes():
7172
"""Create and manage multiple devboxes concurrently."""
7273
print("=== Managing Multiple Devboxes ===")
73-
74+
7475
sdk = AsyncRunloopSDK()
75-
76+
7677
async def create_and_use_devbox(name: str, number: int):
7778
"""Create a devbox, run a command, and return the result."""
7879
async with sdk.devbox.create(name=name) as devbox:
7980
print(f"Devbox {number} ({devbox.id}): Created")
80-
81+
8182
# Run a command
8283
result = await devbox.cmd.exec(f"echo 'Hello from devbox {number}'")
8384
output = await result.stdout()
8485
print(f"Devbox {number}: {output.strip()}")
85-
86+
8687
return output
87-
88+
8889
# Create and use multiple devboxes concurrently
8990
results = await asyncio.gather(
9091
create_and_use_devbox("multi-devbox-1", 1),
9192
create_and_use_devbox("multi-devbox-2", 2),
9293
create_and_use_devbox("multi-devbox-3", 3),
9394
)
94-
95+
9596
print(f"All {len(results)} devboxes completed and shutdown\n")
9697

9798

9899
async def demonstrate_async_streaming():
99100
"""Demonstrate real-time command output streaming with async callbacks."""
100101
print("=== Async Command Streaming ===")
101-
102+
102103
sdk = AsyncRunloopSDK()
103-
104+
104105
async with sdk.devbox.create(name="streaming-devbox") as devbox:
105106
print(f"Created devbox: {devbox.id}")
106-
107+
107108
# Async callback to capture output
108109
output_lines = []
109-
110+
110111
async def capture_output(line: str):
111112
print(f"[STREAM] {line.strip()}")
112113
output_lines.append(line)
113-
114+
114115
# Execute command with streaming output
115116
print("\nStreaming command output:")
116117
await devbox.cmd.exec(
117-
"for i in 1 2 3 4 5; do echo \"Line $i\"; sleep 0.2; done",
118+
'for i in 1 2 3 4 5; do echo "Line $i"; sleep 0.2; done',
118119
stdout=capture_output,
119120
)
120-
121+
121122
print(f"\nCaptured {len(output_lines)} lines of output\n")
122123

123124

124125
async def demonstrate_async_execution():
125126
"""Demonstrate async execution management."""
126127
print("=== Async Execution Management ===")
127-
128+
128129
sdk = AsyncRunloopSDK()
129-
130+
130131
async with sdk.devbox.create(name="async-exec-devbox") as devbox:
131132
print(f"Created devbox: {devbox.id}")
132-
133+
133134
# Start an async execution
134-
execution = await devbox.cmd.exec_async(
135-
"echo 'Starting...'; sleep 2; echo 'Finished!'"
136-
)
135+
execution = await devbox.cmd.exec_async("echo 'Starting...'; sleep 2; echo 'Finished!'")
137136
print(f"Started execution: {execution.execution_id}")
138-
137+
139138
# Poll execution state
140139
state = await execution.get_state()
141140
print(f"Initial status: {state.status}")
142-
141+
143142
# Wait for completion
144143
print("Waiting for completion...")
145144
result = await execution.result()
146145
print(f"Exit code: {result.exit_code}")
147146
output = await result.stdout()
148147
print(f"Output:\n{output}")
149-
148+
150149
# Start another execution and kill it
151150
print("\nStarting long-running process...")
152151
long_execution = await devbox.cmd.exec_async("sleep 30")
153152
print(f"Execution ID: {long_execution.execution_id}")
154-
153+
155154
# Wait a bit then kill it
156155
await asyncio.sleep(1)
157156
print("Killing execution...")
@@ -162,14 +161,14 @@ async def demonstrate_async_execution():
162161
async def main():
163162
"""Run all async demonstrations."""
164163
print("Initialized Async Runloop SDK\n")
165-
164+
166165
# Run demonstrations
167166
await demonstrate_basic_async()
168167
await demonstrate_concurrent_commands()
169168
await demonstrate_multiple_devboxes()
170169
await demonstrate_async_streaming()
171170
await demonstrate_async_execution()
172-
171+
173172
print("All async demonstrations completed!")
174173

175174

@@ -180,10 +179,9 @@ async def main():
180179
print("Please set it to your Runloop API key:")
181180
print(" export RUNLOOP_API_KEY=your-api-key")
182181
exit(1)
183-
182+
184183
try:
185184
asyncio.run(main())
186185
except Exception as e:
187186
print(f"\nError: {e}")
188187
raise
189-

examples/basic_devbox.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import os
1313
from pathlib import Path
14+
1415
from runloop_api_client import RunloopSDK
1516

1617

@@ -23,56 +24,56 @@ def main():
2324
print("\n=== Creating Devbox ===")
2425
with sdk.devbox.create(name="basic-example-devbox") as devbox:
2526
print(f"Created devbox: {devbox.id}")
26-
27+
2728
# Get devbox information
2829
info = devbox.get_info()
2930
print(f"Devbox status: {info.status}")
3031
print(f"Devbox name: {info.name}")
31-
32+
3233
# Execute a simple command
3334
print("\n=== Executing Commands ===")
3435
result = devbox.cmd.exec("echo 'Hello from Runloop!'")
3536
print(f"Command output: {result.stdout().strip()}")
3637
print(f"Exit code: {result.exit_code}")
3738
print(f"Success: {result.success}")
38-
39+
3940
# Execute a command that generates output
4041
result = devbox.cmd.exec("ls -la /home/user")
4142
print(f"\nDirectory listing:\n{result.stdout()}")
42-
43+
4344
# Execute a command with error
4445
result = devbox.cmd.exec("ls /nonexistent")
4546
if result.failed:
4647
print(f"\nCommand failed with exit code {result.exit_code}")
4748
print(f"Error output: {result.stderr()}")
48-
49+
4950
# File operations
5051
print("\n=== File Operations ===")
51-
52+
5253
# Write a file
5354
file_path = "/home/user/test.txt"
5455
content = "Hello, Runloop!\nThis is a test file.\n"
5556
devbox.file.write(path=file_path, contents=content)
5657
print(f"Wrote file: {file_path}")
57-
58+
5859
# Read the file back
5960
read_content = devbox.file.read(path=file_path)
6061
print(f"Read file content:\n{read_content}")
61-
62+
6263
# Create a local file to upload
6364
local_file = Path("temp_upload.txt")
6465
local_file.write_text("This file will be uploaded to the devbox.\n")
65-
66+
6667
try:
6768
# Upload a file
6869
upload_path = "/home/user/uploaded.txt"
6970
devbox.file.upload(path=upload_path, file=local_file)
7071
print(f"\nUploaded file to: {upload_path}")
71-
72+
7273
# Verify the upload by reading the file
7374
uploaded_content = devbox.file.read(path=upload_path)
7475
print(f"Uploaded file content: {uploaded_content.strip()}")
75-
76+
7677
# Download a file
7778
download_data = devbox.file.download(path=upload_path)
7879
local_download = Path("temp_download.txt")
@@ -84,29 +85,29 @@ def main():
8485
local_file.unlink(missing_ok=True)
8586
if Path("temp_download.txt").exists():
8687
Path("temp_download.txt").unlink()
87-
88+
8889
# Asynchronous command execution
8990
print("\n=== Asynchronous Command Execution ===")
90-
91+
9192
# Start a long-running command asynchronously
9293
execution = devbox.cmd.exec_async("sleep 3 && echo 'Done sleeping!'")
9394
print(f"Started async execution: {execution.execution_id}")
94-
95+
9596
# Check the execution state
9697
state = execution.get_state()
9798
print(f"Execution status: {state.status}")
98-
99+
99100
# Wait for completion and get the result
100101
print("Waiting for execution to complete...")
101102
result = execution.result()
102103
print(f"Execution completed with exit code: {result.exit_code}")
103104
print(f"Output: {result.stdout().strip()}")
104-
105+
105106
# Keep devbox alive (extends timeout)
106107
print("\n=== Devbox Lifecycle ===")
107108
devbox.keep_alive()
108109
print("Extended devbox timeout")
109-
110+
110111
print("\n=== Devbox Cleanup ===")
111112
print("Devbox automatically shutdown when exiting context manager")
112113

@@ -118,10 +119,9 @@ def main():
118119
print("Please set it to your Runloop API key:")
119120
print(" export RUNLOOP_API_KEY=your-api-key")
120121
exit(1)
121-
122+
122123
try:
123124
main()
124125
except Exception as e:
125126
print(f"\nError: {e}")
126127
raise
127-

0 commit comments

Comments
 (0)