Skip to content

Commit 80a51b1

Browse files
authored
Merge pull request #7 from martindurant/url-format
change URL schema to key/op/path
2 parents 79b6106 + 51611c0 commit 80a51b1

File tree

3 files changed

+14
-46
lines changed

3 files changed

+14
-46
lines changed

fsspec-proxy/fsspec_proxy/bytes_server.py

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
from fsspec_proxy import file_manager
88

99

10+
URL_SCHEMA = "{prefix}/{key}/{op}/{path}"
11+
# where op = bytes | list
12+
1013
@asynccontextmanager
1114
async def lifespan(app: fastapi.FastAPI):
1215
# start instances in async context
@@ -24,18 +27,7 @@ async def lifespan(app: fastapi.FastAPI):
2427
)
2528

2629

27-
@app.get("/api/list")
28-
async def list_root():
29-
keys = list(app.manager.filesystems)
30-
return {
31-
"status": "ok",
32-
"contents": [
33-
{"name": k, "size": 0, "type": "directory"} for k in keys
34-
]
35-
}
36-
37-
38-
@app.get("/api/list/{key}/{path:path}")
30+
@app.get("/{key}/list/{path:path}")
3931
async def list_dir(key, path):
4032
fs_info = app.manager.get_filesystem(key)
4133
if fs_info is None:
@@ -53,7 +45,7 @@ async def list_dir(key, path):
5345
return {"status": "ok", "contents": out}
5446

5547

56-
@app.delete("/api/delete/{key}/{path:path}")
48+
@app.delete("/{key}/delete/{path:path}")
5749
async def delete_file(key, path, response: fastapi.Response):
5850
fs_info = app.manager.get_filesystem(key)
5951
path = f"{fs_info['path'].rstrip('/')}/{path.lstrip('/')}"
@@ -70,7 +62,7 @@ async def delete_file(key, path, response: fastapi.Response):
7062
response.status_code = 204
7163

7264

73-
@app.get("/api/bytes/{key}/{path:path}")
65+
@app.get("/{key}/bytes/{path:path}")
7466
async def get_bytes(key, path, request: fastapi.Request):
7567
start, end = _process_range(request.headers.get("Range"))
7668
fs_info = app.manager.get_filesystem(key)
@@ -84,7 +76,7 @@ async def get_bytes(key, path, request: fastapi.Request):
8476
return StreamingResponse(io.BytesIO(out), media_type="application/octet-stream")
8577

8678

87-
@app.post("/api/bytes/{key}/{path:path}")
79+
@app.post("/{key}/bytes/{path:path}")
8880
async def put_bytes(key, path, request: fastapi.Request, response: fastapi.Response):
8981
fs_info = app.manager.get_filesystem(key)
9082
if fs_info is None:
@@ -101,14 +93,6 @@ async def put_bytes(key, path, request: fastapi.Request, response: fastapi.Respo
10193
return {"contents": []}
10294

10395

104-
@app.post("/api/config")
105-
async def setup(request: fastapi.Request):
106-
if not app.manager.config.get("allow_reload", False):
107-
raise fastapi.HTTPException(status_code=403, detail="Not Allowed")
108-
app.manager.config = await request.json()
109-
app.manager.initialize_filesystems()
110-
111-
11296
def _process_range(range):
11397
if range and range.startswith("bytes=") and range.count("-") == 1:
11498
sstart, sstop = range.split("=")[1].split("-")

pyscript-fsspec-client/pyscript_fsspec_client/client.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
logger = logging.getLogger("pyscript_fsspec_client")
99
fsspec.utils.setup_logging(logger=logger)
10-
default_endpoint = os.getenv("FSSPEC_PROXY_URL", "http://127.0.0.1:8000/api")
10+
default_endpoint = os.getenv("FSSPEC_PROXY_URL", "http://127.0.0.1:8000")
1111

1212

1313
class PyscriptFileSystem(AbstractFileSystem):
@@ -57,9 +57,9 @@ def ls(self, path, detail=True, **kwargs):
5757
key, *path = path.split("/", 1)
5858
if key:
5959
part = path[0] if path else ""
60-
out = self._call(f"list/{key}/{part}")
60+
out = self._call(f"{key}/list/{part}")
6161
else:
62-
out = self._call(f"list")
62+
raise ValueError
6363

6464
if detail:
6565
return out
@@ -68,7 +68,7 @@ def ls(self, path, detail=True, **kwargs):
6868
def rm_file(self, path):
6969
path = self._strip_protocol(path)
7070
key, path = path.split("/", 1)
71-
self._call(f"delete/{key}/{path}", method="DELETE", binary=True)
71+
self._call(f"{key}/delete/{path}", method="DELETE", binary=True)
7272

7373
def _open(
7474
self,
@@ -87,19 +87,11 @@ def cat_file(self, path, start=None, end=None, **kw):
8787
range = (start, end + 1)
8888
else:
8989
range = None
90-
return self._call(f"bytes/{key}/{relpath}", binary=True, range=range)
90+
return self._call(f"{key}/bytes/{relpath}", binary=True, range=range)
9191

9292
def pipe_file(self, path, value, mode="overwrite", **kwargs):
9393
key, relpath = self._split_path(path)
94-
self._call(f"bytes/{key}/{relpath}", method="POST", data=value)
95-
96-
def reconfigure(self, config):
97-
# only privileged identities can do this
98-
if not "sources" in config:
99-
raise ValueError("Bad config")
100-
if not ["name" in _ and "path" in _ for _ in config["sources"]]:
101-
raise ValueError("Bad config")
102-
self._call(f"config", method="POST", json=config, binary=True)
94+
self._call(f"{key}/bytes/{relpath}", method="POST", data=value)
10395

10496

10597
class JFile(AbstractBufferedFile):

tests/test_client.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def server():
2424
raise
2525
count -= 1
2626
time.sleep(0.1)
27-
yield f"{s}/api"
27+
yield f"{s}"
2828
P.terminate()
2929
P.wait()
3030

@@ -42,11 +42,3 @@ def test_file(fs):
4242
assert f.read() == b"hello"
4343
fs.rm("inmemory/afile")
4444
assert not fs.exists("inmemory/afile")
45-
46-
47-
def test_config(fs):
48-
out = fs.ls("", detail=False)
49-
assert "inmemory" in out and "local" in out # other spaces might fail
50-
fs.reconfigure({"sources": [{"name": "mem", "path": "memory://"}]})
51-
out = fs.ls("", detail=False)
52-
assert out == ["mem"]

0 commit comments

Comments
 (0)