Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Rename watch to watch dir

Jakub Novakbfc4bb51d8cd
diff --git a/apps/web/src/code/python/basics/fs_watch.py b/apps/web/src/code/python/basics/fs_watch.py
index 12a2f0e59..099b87f95 100644
--- a/apps/web/src/code/python/basics/fs_watch.py
+++ b/apps/web/src/code/python/basics/fs_watch.py
@@ -4,7 +4,7 @@ from e2b import Sandbox
sandbox = Sandbox()
-watcher = sandbox.files.watch("/home") # $HighlightLine
+watcher = sandbox.files.watch_dir("/home") # $HighlightLine
# Create files in the /home directory inside the playground
# We'll receive notifications for these events through the watcher we created above.
diff --git a/packages/js-sdk/src/sandbox/filesystem/index.ts b/packages/js-sdk/src/sandbox/filesystem/index.ts
index eae381ff9..146a7c9ee 100644
--- a/packages/js-sdk/src/sandbox/filesystem/index.ts
+++ b/packages/js-sdk/src/sandbox/filesystem/index.ts
@@ -352,7 +352,7 @@ export class Filesystem {
* @param opts Options for the request
* @returns New watcher
*/
- async watch(
+ async watchDir(
path: string,
onEvent: (event: FilesystemEvent) => void | Promise<void>,
opts?: FilesystemRequestOpts & {
diff --git a/packages/js-sdk/tests/sandbox/files/watch.test.ts b/packages/js-sdk/tests/sandbox/files/watch.test.ts
index 7486632b0..4cb9251f9 100644
--- a/packages/js-sdk/tests/sandbox/files/watch.test.ts
+++ b/packages/js-sdk/tests/sandbox/files/watch.test.ts
@@ -18,7 +18,7 @@ sandboxTest('watch directory changes', async ({ sandbox }) => {
trigger = resolve
})
- const handle = await sandbox.files.watch(dirname, async (event) => {
+ const handle = await sandbox.files.watchDir(dirname, async (event) => {
if (event.type === FilesystemEventType.WRITE && event.name === filename) {
trigger()
}
@@ -34,7 +34,7 @@ sandboxTest('watch directory changes', async ({ sandbox }) => {
sandboxTest('watch non-existing directory', async ({ sandbox }) => {
const dirname = 'non_existing_watch_dir'
- await expect(sandbox.files.watch(dirname, () => {})).rejects.toThrowError(
+ await expect(sandbox.files.watchDir(dirname, () => {})).rejects.toThrowError(
NotFoundError
)
})
@@ -44,7 +44,7 @@ sandboxTest('watch file', async ({ sandbox }) => {
const content = 'This file will be watched.'
await sandbox.files.write(filename, content)
- await expect(sandbox.files.watch(filename, () => {})).rejects.toThrowError(
+ await expect(sandbox.files.watchDir(filename, () => {})).rejects.toThrowError(
SandboxError
)
})
diff --git a/packages/python-sdk/e2b/sandbox_async/filesystem/filesystem.py b/packages/python-sdk/e2b/sandbox_async/filesystem/filesystem.py
index ed16239b6..f726b9e12 100644
--- a/packages/python-sdk/e2b/sandbox_async/filesystem/filesystem.py
+++ b/packages/python-sdk/e2b/sandbox_async/filesystem/filesystem.py
@@ -302,7 +302,7 @@ class Filesystem:
return False
raise handle_rpc_exception(e)
- async def watch(
+ async def watch_dir(
self,
path: str,
on_event: OutputHandler[FilesystemEvent],
diff --git a/packages/python-sdk/e2b/sandbox_sync/filesystem/filesystem.py b/packages/python-sdk/e2b/sandbox_sync/filesystem/filesystem.py
index b2e7bc9a8..13540112c 100644
--- a/packages/python-sdk/e2b/sandbox_sync/filesystem/filesystem.py
+++ b/packages/python-sdk/e2b/sandbox_sync/filesystem/filesystem.py
@@ -298,7 +298,7 @@ class Filesystem:
return False
raise handle_rpc_exception(e)
- def watch(
+ def watch_dir(
self,
path: str,
user: Username = "user",
diff --git a/packages/python-sdk/tests/async/sandbox_async/files/test_watch.py b/packages/python-sdk/tests/async/sandbox_async/files/test_watch.py
index c5f1b557e..19d319a95 100644
--- a/packages/python-sdk/tests/async/sandbox_async/files/test_watch.py
+++ b/packages/python-sdk/tests/async/sandbox_async/files/test_watch.py
@@ -26,7 +26,7 @@ async def test_watch_directory_changes(async_sandbox: AsyncSandbox):
if e.type == FilesystemEventType.WRITE and e.name == filename:
event_triggered.set()
- handle = await async_sandbox.files.watch(dirname, on_event=handle_event)
+ handle = await async_sandbox.files.watch_dir(dirname, on_event=handle_event)
await async_sandbox.files.write(f"{dirname}/{filename}", new_content)
@@ -39,7 +39,7 @@ async def test_watch_non_existing_directory(async_sandbox: AsyncSandbox):
dirname = "non_existing_watch_dir"
with pytest.raises(NotFoundException):
- await async_sandbox.files.watch(dirname, on_event=lambda e: None)
+ await async_sandbox.files.watch_dir(dirname, on_event=lambda e: None)
async def test_watch_file(async_sandbox: AsyncSandbox):
@@ -47,4 +47,4 @@ async def test_watch_file(async_sandbox: AsyncSandbox):
await async_sandbox.files.write(filename, "This file will be watched.")
with pytest.raises(SandboxException):
- await async_sandbox.files.watch(filename, on_event=lambda e: None)
+ await async_sandbox.files.watch_dir(filename, on_event=lambda e: None)
diff --git a/packages/python-sdk/tests/sync/sandbox_sync/files/test_watch.py b/packages/python-sdk/tests/sync/sandbox_sync/files/test_watch.py
index 484931112..e9fc5faf1 100644
--- a/packages/python-sdk/tests/sync/sandbox_sync/files/test_watch.py
+++ b/packages/python-sdk/tests/sync/sandbox_sync/files/test_watch.py
@@ -9,7 +9,7 @@ def test_watch_directory_changes(sandbox: Sandbox):
content = "This file will be watched."
sandbox.files.make_dir(dirname)
- handle = sandbox.files.watch(dirname)
+ handle = sandbox.files.watch_dir(dirname)
sandbox.files.write(f"{dirname}/{filename}", content)
events = handle.get_new_events()
@@ -31,7 +31,7 @@ def test_watch_iterated(sandbox: Sandbox):
new_content = "This file has been modified."
sandbox.files.make_dir(dirname)
- handle = sandbox.files.watch(dirname)
+ handle = sandbox.files.watch_dir(dirname)
sandbox.files.write(f"{dirname}/{filename}", content)
events = handle.get_new_events()
@@ -50,7 +50,7 @@ def test_watch_non_existing_directory(sandbox: Sandbox):
dirname = "non_existing_watch_dir"
with pytest.raises(NotFoundException):
- sandbox.files.watch(dirname)
+ sandbox.files.watch_dir(dirname)
def test_watch_file(sandbox: Sandbox):
@@ -58,4 +58,4 @@ def test_watch_file(sandbox: Sandbox):
sandbox.files.write(filename, "This file will be watched.")
with pytest.raises(SandboxException):
- sandbox.files.watch(filename)
+ sandbox.files.watch_dir(filename)