exxec 0.3.7__tar.gz → 0.3.8__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {exxec-0.3.7 → exxec-0.3.8}/PKG-INFO +1 -1
- {exxec-0.3.7 → exxec-0.3.8}/pyproject.toml +1 -1
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/mock_provider/provider.py +5 -7
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/pyodide_provider/__init__.py +1 -2
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/pyodide_provider/provider.py +17 -58
- exxec-0.3.7/src/exxec/pyodide_provider/filesystem.py +0 -232
- exxec-0.3.7/src/exxec/pyodide_provider/pyodide_server.ts +0 -825
- {exxec-0.3.7 → exxec-0.3.8}/LICENSE +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/README.md +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/__init__.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/acp_provider/__init__.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/acp_provider/process_manager.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/acp_provider/provider.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/base.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/beam_provider/__init__.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/beam_provider/helpers.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/beam_provider/process_manager.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/beam_provider/provider.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/daytona_provider/__init__.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/daytona_provider/helpers.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/daytona_provider/process_manager.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/daytona_provider/provider.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/daytona_provider/pty_manager.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/docker_provider/__init__.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/docker_provider/provider.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/docker_provider/pty_manager.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/e2b_provider/__init__.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/e2b_provider/process_manager.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/e2b_provider/provider.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/e2b_provider/pty_manager.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/events.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/local_provider/__init__.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/local_provider/provider.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/local_provider/pty_manager.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/local_provider/utils.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/log.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/microsandbox_provider/__init__.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/microsandbox_provider/provider.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/mock_provider/__init__.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/mock_provider/process_manager.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/mock_provider/pty_manager.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/modal_provider/__init__.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/modal_provider/provider.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/modal_provider/pty_manager.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/models.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/parse_output.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/pep723.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/process_manager.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/pty_manager.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/py.typed +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/remote_callable.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/srt_provider/__init__.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/srt_provider/provider.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/ssh_provider/__init__.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/ssh_provider/provider.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/ssh_provider/pty_manager.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/vercel_provider/__init__.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/vercel_provider/process_manager.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec/vercel_provider/provider.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec_config/__init__.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec_config/configs.py +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec_config/py.typed +0 -0
- {exxec-0.3.7 → exxec-0.3.8}/src/exxec_config/srt_sandbox_config.py +0 -0
|
@@ -5,11 +5,6 @@ from __future__ import annotations
|
|
|
5
5
|
from typing import TYPE_CHECKING
|
|
6
6
|
import uuid
|
|
7
7
|
|
|
8
|
-
from fsspec.implementations.asyn_wrapper import ( # type: ignore[import-untyped]
|
|
9
|
-
AsyncFileSystemWrapper,
|
|
10
|
-
)
|
|
11
|
-
from fsspec.implementations.memory import MemoryFileSystem # type: ignore[import-untyped]
|
|
12
|
-
|
|
13
8
|
from exxec.base import ExecutionEnvironment
|
|
14
9
|
from exxec.events import OutputEvent, ProcessCompletedEvent, ProcessErrorEvent, ProcessStartedEvent
|
|
15
10
|
from exxec.mock_provider.process_manager import MockProcessManager
|
|
@@ -58,6 +53,9 @@ class MockExecutionEnvironment(ExecutionEnvironment):
|
|
|
58
53
|
env_vars: Environment variables (stored but not used in mock)
|
|
59
54
|
inherit_env: If True, inherit environment variables from os.environ
|
|
60
55
|
"""
|
|
56
|
+
from upathtools import to_async_fs
|
|
57
|
+
from upathtools.filesystems import IsolatedMemoryFileSystem
|
|
58
|
+
|
|
61
59
|
super().__init__(cwd=cwd, env_vars=env_vars, inherit_env=inherit_env)
|
|
62
60
|
self._code_results = code_results or {}
|
|
63
61
|
self._command_results = command_results or {}
|
|
@@ -71,8 +69,8 @@ class MockExecutionEnvironment(ExecutionEnvironment):
|
|
|
71
69
|
stderr="",
|
|
72
70
|
exit_code=0,
|
|
73
71
|
)
|
|
74
|
-
self._sync_fs =
|
|
75
|
-
self._fs =
|
|
72
|
+
self._sync_fs = IsolatedMemoryFileSystem()
|
|
73
|
+
self._fs = to_async_fs(self._sync_fs)
|
|
76
74
|
self._mock_process_manager = MockProcessManager(
|
|
77
75
|
default_output=default_process_output,
|
|
78
76
|
command_outputs=process_outputs,
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
-
from exxec.pyodide_provider.filesystem import PyodideFS
|
|
6
5
|
from exxec.pyodide_provider.provider import PyodideExecutionEnvironment
|
|
7
6
|
|
|
8
|
-
__all__ = ["PyodideExecutionEnvironment"
|
|
7
|
+
__all__ = ["PyodideExecutionEnvironment"]
|
|
@@ -5,17 +5,16 @@ from __future__ import annotations
|
|
|
5
5
|
import asyncio
|
|
6
6
|
import contextlib
|
|
7
7
|
import json
|
|
8
|
-
from pathlib import Path
|
|
9
8
|
import shutil
|
|
10
9
|
import time
|
|
11
10
|
from typing import TYPE_CHECKING, Any, Self
|
|
12
11
|
|
|
13
12
|
from anyenv.processes import create_process
|
|
13
|
+
from upathtools.filesystems.sandbox_filesystems.pyodide_fs import PyodideFS, build_command
|
|
14
14
|
|
|
15
15
|
from exxec.base import ExecutionEnvironment
|
|
16
16
|
from exxec.events import OutputEvent, ProcessCompletedEvent, ProcessErrorEvent, ProcessStartedEvent
|
|
17
17
|
from exxec.models import ExecutionResult
|
|
18
|
-
from exxec.pyodide_provider.filesystem import PyodideFS
|
|
19
18
|
|
|
20
19
|
|
|
21
20
|
if TYPE_CHECKING:
|
|
@@ -23,22 +22,10 @@ if TYPE_CHECKING:
|
|
|
23
22
|
from contextlib import AbstractAsyncContextManager
|
|
24
23
|
from types import TracebackType
|
|
25
24
|
|
|
25
|
+
from upathtools.filesystems.sandbox_filesystems.pyodide_fs import PyodideMethod
|
|
26
|
+
|
|
26
27
|
from exxec.events import ExecutionEvent
|
|
27
28
|
from exxec.models import ServerInfo
|
|
28
|
-
from exxec.pyodide_provider.filesystem import PyodideMethod
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
# Path to the TypeScript server relative to this file
|
|
32
|
-
SERVER_SCRIPT = Path(__file__).parent / "pyodide_server.ts"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
def _build_permission_flag(flag: str, value: bool | list[str]) -> str | None:
|
|
36
|
-
"""Build a Deno permission flag string."""
|
|
37
|
-
if value is True:
|
|
38
|
-
return flag
|
|
39
|
-
if isinstance(value, list) and value:
|
|
40
|
-
return f"{flag}={','.join(value)}"
|
|
41
|
-
return None
|
|
42
29
|
|
|
43
30
|
|
|
44
31
|
class PyodideExecutionEnvironment(ExecutionEnvironment):
|
|
@@ -118,46 +105,23 @@ class PyodideExecutionEnvironment(ExecutionEnvironment):
|
|
|
118
105
|
# Pyodide emulates a Linux-like environment
|
|
119
106
|
self._os_type = "Linux"
|
|
120
107
|
|
|
121
|
-
def _build_command(self) -> list[str]:
|
|
122
|
-
"""Build the Deno command with permissions."""
|
|
123
|
-
if not self.deno_executable:
|
|
124
|
-
msg = "Deno executable not found. Install from https://deno.land"
|
|
125
|
-
raise RuntimeError(msg)
|
|
126
|
-
|
|
127
|
-
cmd = [self.deno_executable, "run"]
|
|
128
|
-
|
|
129
|
-
# Build permission flags
|
|
130
|
-
permission_defs = [
|
|
131
|
-
("--allow-net", self.allow_net),
|
|
132
|
-
("--allow-read", self.allow_read),
|
|
133
|
-
("--allow-write", self.allow_write),
|
|
134
|
-
("--allow-env", self.allow_env),
|
|
135
|
-
("--allow-run", self.allow_run),
|
|
136
|
-
("--allow-ffi", self.allow_ffi),
|
|
137
|
-
]
|
|
138
|
-
|
|
139
|
-
for flag, value in permission_defs:
|
|
140
|
-
perm = _build_permission_flag(flag, value)
|
|
141
|
-
if perm:
|
|
142
|
-
cmd.append(perm)
|
|
143
|
-
|
|
144
|
-
# Always need read for node_modules (Pyodide downloads)
|
|
145
|
-
if not self.allow_read:
|
|
146
|
-
cmd.append("--allow-read=node_modules")
|
|
147
|
-
if not self.allow_write:
|
|
148
|
-
cmd.append("--allow-write=node_modules")
|
|
149
|
-
|
|
150
|
-
cmd.append("--node-modules-dir=auto")
|
|
151
|
-
cmd.append(str(SERVER_SCRIPT))
|
|
152
|
-
|
|
153
|
-
return cmd
|
|
154
|
-
|
|
155
108
|
async def __aenter__(self) -> Self:
|
|
156
109
|
"""Start the Deno/Pyodide server process."""
|
|
157
110
|
import anyenv
|
|
158
111
|
|
|
159
112
|
await super().__aenter__()
|
|
160
|
-
|
|
113
|
+
if not self.deno_executable:
|
|
114
|
+
msg = "Deno executable not found. Install from https://deno.land"
|
|
115
|
+
raise RuntimeError(msg)
|
|
116
|
+
cmd = build_command(
|
|
117
|
+
self.deno_executable,
|
|
118
|
+
allow_net=self.allow_net,
|
|
119
|
+
allow_read=self.allow_read,
|
|
120
|
+
allow_write=self.allow_write,
|
|
121
|
+
allow_env=self.allow_env,
|
|
122
|
+
allow_run=self.allow_run,
|
|
123
|
+
allow_ffi=self.allow_ffi,
|
|
124
|
+
)
|
|
161
125
|
self._process = await create_process(*cmd, stdin="pipe", stdout="pipe", stderr="pipe")
|
|
162
126
|
# Wait for ready signal
|
|
163
127
|
try:
|
|
@@ -316,10 +280,8 @@ class PyodideExecutionEnvironment(ExecutionEnvironment):
|
|
|
316
280
|
|
|
317
281
|
match event_type:
|
|
318
282
|
case "started":
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
command=f"execute({len(code)} chars)",
|
|
322
|
-
)
|
|
283
|
+
cmd = f"execute({len(code)} chars)"
|
|
284
|
+
yield ProcessStartedEvent(process_id=pid, command=cmd)
|
|
323
285
|
case "output":
|
|
324
286
|
yield OutputEvent(
|
|
325
287
|
process_id=pid,
|
|
@@ -390,12 +352,9 @@ result.returncode
|
|
|
390
352
|
# Delegate to execute_command since streaming shell commands
|
|
391
353
|
# is not really supported in Pyodide
|
|
392
354
|
process_id = f"pyodide_cmd_{self._request_id + 1}"
|
|
393
|
-
|
|
394
355
|
yield ProcessStartedEvent(process_id=process_id, command=command)
|
|
395
|
-
|
|
396
356
|
try:
|
|
397
357
|
result = await self.execute_command(command, timeout=timeout)
|
|
398
|
-
|
|
399
358
|
if result.stdout:
|
|
400
359
|
yield OutputEvent(process_id=process_id, data=result.stdout, stream="stdout")
|
|
401
360
|
if result.stderr:
|
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
"""Pyodide fsspec filesystem implementation."""
|
|
2
|
-
|
|
3
|
-
from __future__ import annotations
|
|
4
|
-
|
|
5
|
-
import base64
|
|
6
|
-
from collections.abc import Awaitable, Callable
|
|
7
|
-
from typing import TYPE_CHECKING, Any, Literal, TypedDict, overload
|
|
8
|
-
|
|
9
|
-
from fsspec.asyn import AsyncFileSystem, sync_wrapper # type: ignore[import-untyped]
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if TYPE_CHECKING:
|
|
13
|
-
from upathtools.filesystems.base.basefilesystem import CreationMode
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
PyodideMethod = Literal[
|
|
17
|
-
"fs_ls",
|
|
18
|
-
"fs_cat",
|
|
19
|
-
"fs_write",
|
|
20
|
-
"fs_mkdir",
|
|
21
|
-
"fs_rm",
|
|
22
|
-
"fs_rmdir",
|
|
23
|
-
"fs_stat",
|
|
24
|
-
"fs_exists",
|
|
25
|
-
]
|
|
26
|
-
|
|
27
|
-
# Type alias for filesystem request callback
|
|
28
|
-
PyodideFilesystemCallback = Callable[[PyodideMethod, dict[str, Any]], Awaitable[Any]]
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
class PyodideFileInfo(TypedDict):
|
|
32
|
-
"""Info dict for Pyodide filesystem paths."""
|
|
33
|
-
|
|
34
|
-
name: str
|
|
35
|
-
size: int
|
|
36
|
-
type: Literal["file", "directory"]
|
|
37
|
-
mtime: float | None
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
def _to_file_info(data: dict[str, Any]) -> PyodideFileInfo:
|
|
41
|
-
"""Convert a dict to PyodideFileInfo."""
|
|
42
|
-
return PyodideFileInfo(
|
|
43
|
-
name=data["name"],
|
|
44
|
-
size=data["size"],
|
|
45
|
-
type=data["type"],
|
|
46
|
-
mtime=data.get("mtime"),
|
|
47
|
-
)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
class PyodideFS(AsyncFileSystem): # type: ignore[misc]
|
|
51
|
-
"""Async filesystem for Pyodide environments.
|
|
52
|
-
|
|
53
|
-
This filesystem provides access to files within the Pyodide WASM environment's
|
|
54
|
-
in-memory filesystem (MEMFS). Files written here persist for the duration of
|
|
55
|
-
the session but are lost when the environment is closed.
|
|
56
|
-
|
|
57
|
-
Note: This filesystem operates on Pyodide's virtual filesystem, not the host.
|
|
58
|
-
"""
|
|
59
|
-
|
|
60
|
-
protocol = "pyodide"
|
|
61
|
-
root_marker = "/"
|
|
62
|
-
cachable = False
|
|
63
|
-
|
|
64
|
-
def __init__(
|
|
65
|
-
self,
|
|
66
|
-
request_callback: PyodideFilesystemCallback,
|
|
67
|
-
**kwargs: Any,
|
|
68
|
-
) -> None:
|
|
69
|
-
"""Initialize Pyodide filesystem.
|
|
70
|
-
|
|
71
|
-
Args:
|
|
72
|
-
request_callback: Async callback for sending filesystem requests
|
|
73
|
-
**kwargs: Additional filesystem arguments
|
|
74
|
-
"""
|
|
75
|
-
super().__init__(**kwargs)
|
|
76
|
-
self._request_callback = request_callback
|
|
77
|
-
|
|
78
|
-
async def _fs_request(self, method: PyodideMethod, params: dict[str, Any]) -> Any:
|
|
79
|
-
"""Send a filesystem request via the injected callback."""
|
|
80
|
-
return await self._request_callback(method, params)
|
|
81
|
-
|
|
82
|
-
@overload
|
|
83
|
-
async def _ls(
|
|
84
|
-
self,
|
|
85
|
-
path: str,
|
|
86
|
-
detail: Literal[True] = ...,
|
|
87
|
-
**kwargs: Any,
|
|
88
|
-
) -> list[PyodideFileInfo]: ...
|
|
89
|
-
|
|
90
|
-
@overload
|
|
91
|
-
async def _ls(
|
|
92
|
-
self,
|
|
93
|
-
path: str,
|
|
94
|
-
detail: Literal[False],
|
|
95
|
-
**kwargs: Any,
|
|
96
|
-
) -> list[str]: ...
|
|
97
|
-
|
|
98
|
-
async def _ls(
|
|
99
|
-
self,
|
|
100
|
-
path: str,
|
|
101
|
-
detail: bool = True,
|
|
102
|
-
**kwargs: Any,
|
|
103
|
-
) -> list[str] | list[PyodideFileInfo]:
|
|
104
|
-
"""List directory contents."""
|
|
105
|
-
try:
|
|
106
|
-
entries = await self._fs_request("fs_ls", {"path": path})
|
|
107
|
-
if detail:
|
|
108
|
-
return [_to_file_info(e) for e in entries]
|
|
109
|
-
return [e["name"] for e in entries]
|
|
110
|
-
except RuntimeError as e:
|
|
111
|
-
if "No such file or directory" in str(e) or "FileNotFoundError" in str(e):
|
|
112
|
-
msg = f"Path not found: {path}"
|
|
113
|
-
raise FileNotFoundError(msg) from e
|
|
114
|
-
raise
|
|
115
|
-
|
|
116
|
-
async def _cat_file(
|
|
117
|
-
self,
|
|
118
|
-
path: str,
|
|
119
|
-
start: int | None = None,
|
|
120
|
-
end: int | None = None,
|
|
121
|
-
**kwargs: Any,
|
|
122
|
-
) -> bytes:
|
|
123
|
-
"""Read file contents."""
|
|
124
|
-
try:
|
|
125
|
-
result = await self._fs_request("fs_cat", {"path": path})
|
|
126
|
-
content = base64.b64decode(result["content"])
|
|
127
|
-
if start is not None or end is not None:
|
|
128
|
-
return content[start:end]
|
|
129
|
-
except RuntimeError as e:
|
|
130
|
-
if "No such file or directory" in str(e) or "FileNotFoundError" in str(e):
|
|
131
|
-
msg = f"File not found: {path}"
|
|
132
|
-
raise FileNotFoundError(msg) from e
|
|
133
|
-
raise
|
|
134
|
-
else:
|
|
135
|
-
return content
|
|
136
|
-
|
|
137
|
-
async def _pipe_file(
|
|
138
|
-
self,
|
|
139
|
-
path: str,
|
|
140
|
-
value: bytes,
|
|
141
|
-
mode: CreationMode = "overwrite",
|
|
142
|
-
**kwargs: Any,
|
|
143
|
-
) -> None:
|
|
144
|
-
"""Write file contents."""
|
|
145
|
-
content_b64 = base64.b64encode(value).decode("ascii")
|
|
146
|
-
await self._fs_request("fs_write", {"path": path, "content": content_b64})
|
|
147
|
-
|
|
148
|
-
async def _mkdir(self, path: str, create_parents: bool = True, **kwargs: Any) -> None:
|
|
149
|
-
"""Create directory."""
|
|
150
|
-
await self._fs_request("fs_mkdir", {"path": path, "recursive": create_parents})
|
|
151
|
-
|
|
152
|
-
async def _rm_file(self, path: str, **kwargs: Any) -> None:
|
|
153
|
-
"""Remove file."""
|
|
154
|
-
await self._fs_request("fs_rm", {"path": path})
|
|
155
|
-
|
|
156
|
-
async def _rmdir(self, path: str, **kwargs: Any) -> None:
|
|
157
|
-
"""Remove directory."""
|
|
158
|
-
await self._fs_request("fs_rmdir", {"path": path, "recursive": False})
|
|
159
|
-
|
|
160
|
-
async def _rm(
|
|
161
|
-
self, path: str, recursive: bool = False, batch_size: int | None = None, **kwargs: Any
|
|
162
|
-
) -> None:
|
|
163
|
-
"""Remove file or directory."""
|
|
164
|
-
if recursive:
|
|
165
|
-
await self._fs_request("fs_rmdir", {"path": path, "recursive": True})
|
|
166
|
-
else:
|
|
167
|
-
# Check if it's a file or directory
|
|
168
|
-
try:
|
|
169
|
-
info = await self._info(path)
|
|
170
|
-
if info["type"] == "directory":
|
|
171
|
-
await self._rmdir(path)
|
|
172
|
-
else:
|
|
173
|
-
await self._rm_file(path)
|
|
174
|
-
except FileNotFoundError:
|
|
175
|
-
pass # Already gone
|
|
176
|
-
|
|
177
|
-
async def _exists(self, path: str, **kwargs: Any) -> bool:
|
|
178
|
-
"""Check if path exists."""
|
|
179
|
-
result = await self._fs_request("fs_exists", {"path": path})
|
|
180
|
-
return bool(result)
|
|
181
|
-
|
|
182
|
-
async def _info(self, path: str, **kwargs: Any) -> PyodideFileInfo:
|
|
183
|
-
"""Get file/directory info."""
|
|
184
|
-
try:
|
|
185
|
-
result = await self._fs_request("fs_stat", {"path": path})
|
|
186
|
-
return _to_file_info(result)
|
|
187
|
-
except RuntimeError as e:
|
|
188
|
-
if "No such file or directory" in str(e) or "FileNotFoundError" in str(e):
|
|
189
|
-
msg = f"Path not found: {path}"
|
|
190
|
-
raise FileNotFoundError(msg) from e
|
|
191
|
-
raise
|
|
192
|
-
|
|
193
|
-
async def _isfile(self, path: str, **kwargs: Any) -> bool:
|
|
194
|
-
"""Check if path is a file."""
|
|
195
|
-
try:
|
|
196
|
-
info = await self._info(path)
|
|
197
|
-
return info["type"] == "file"
|
|
198
|
-
except FileNotFoundError:
|
|
199
|
-
return False
|
|
200
|
-
|
|
201
|
-
async def _isdir(self, path: str, **kwargs: Any) -> bool:
|
|
202
|
-
"""Check if path is a directory."""
|
|
203
|
-
try:
|
|
204
|
-
info = await self._info(path)
|
|
205
|
-
return info["type"] == "directory"
|
|
206
|
-
except FileNotFoundError:
|
|
207
|
-
return False
|
|
208
|
-
|
|
209
|
-
async def _size(self, path: str, **kwargs: Any) -> int:
|
|
210
|
-
"""Get file size."""
|
|
211
|
-
info = await self._info(path)
|
|
212
|
-
return info["size"]
|
|
213
|
-
|
|
214
|
-
async def _modified(self, path: str, **kwargs: Any) -> float:
|
|
215
|
-
"""Get file modification time."""
|
|
216
|
-
info = await self._info(path)
|
|
217
|
-
return info.get("mtime") or 0.0
|
|
218
|
-
|
|
219
|
-
# Sync wrapper methods
|
|
220
|
-
ls = sync_wrapper(_ls)
|
|
221
|
-
cat_file = sync_wrapper(_cat_file) # pyright: ignore[reportAssignmentType]
|
|
222
|
-
pipe_file = sync_wrapper(_pipe_file)
|
|
223
|
-
mkdir = sync_wrapper(_mkdir)
|
|
224
|
-
rm_file = sync_wrapper(_rm_file)
|
|
225
|
-
rmdir = sync_wrapper(_rmdir)
|
|
226
|
-
rm = sync_wrapper(_rm)
|
|
227
|
-
exists = sync_wrapper(_exists) # pyright: ignore[reportAssignmentType]
|
|
228
|
-
info = sync_wrapper(_info)
|
|
229
|
-
isfile = sync_wrapper(_isfile)
|
|
230
|
-
isdir = sync_wrapper(_isdir)
|
|
231
|
-
size = sync_wrapper(_size)
|
|
232
|
-
modified = sync_wrapper(_modified)
|