Skip to content

Commit 9a770a8

Browse files
committed
fix(sdk): fix minor tg_artifact_upload python SDK bugs
1 parent 250cf2d commit 9a770a8

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

typegraph/python/typegraph/graph/tg_artifact_upload.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414

1515
@dataclass
1616
class UploadArtifactMeta:
17-
typegraph_name: str
17+
typegraphName: str
1818
hash: str
19-
size_in_bytes: int
20-
relative_path: str
19+
sizeInBytes: int
20+
relativePath: str
2121

2222

2323
class ArtifactUploader:
@@ -49,10 +49,11 @@ def __fetch_upload_urls(
4949
self,
5050
artifact_metas: List[UploadArtifactMeta],
5151
) -> List[str]:
52-
artifacts_json = json.dumps(artifact_metas.__dict__).encode()
52+
artifacts_objs = [vars(meta) for meta in artifact_metas]
53+
artifacts_json = json.dumps(artifacts_objs, indent=4).encode()
5354
req = request.Request(
5455
url=self.get_upload_url,
55-
method="PUT",
56+
method="POST",
5657
headers=self.headers,
5758
data=artifacts_json,
5859
)
@@ -71,30 +72,33 @@ def __upload(
7172
upload_headers["Authorization"] = self.auth.as_header_value()
7273

7374
if url is None:
74-
print(f"Skipping upload for artifact: {meta.relative_path}")
75+
print(f"Skipping upload for artifact: {meta.relativePath}")
7576
return Ok(None)
7677

77-
path = os.path.join(os.path.dirname(self.tg_path), meta.relative_path)
78+
path = os.path.join(os.path.dirname(self.tg_path), meta.relativePath)
7879
# TODO: read in chunks?
79-
with open(path, "r") as file:
80+
with open(path, "rb") as file:
8081
content = file.read()
8182

8283
upload_req = request.Request(
8384
url=url,
8485
method="POST",
85-
data=content.encode(),
86+
data=content,
8687
headers=upload_headers,
8788
)
8889
response = request.urlopen(upload_req)
89-
if response.status != 200:
90+
if response.status != 201:
9091
raise Exception(f"Failed to upload artifact {path} {response.status}")
9192

9293
return handle_response(response.read().decode())
9394

9495
def get_metas(self, artifacts: List[Artifact]) -> List[UploadArtifactMeta]:
9596
return [
9697
UploadArtifactMeta(
97-
self.tg_name, artifact.hash, artifact.size, artifact.path
98+
typegraphName=self.tg_name,
99+
hash=artifact.hash,
100+
sizeInBytes=artifact.size,
101+
relativePath=artifact.path,
98102
)
99103
for artifact in artifacts
100104
]
@@ -107,10 +111,10 @@ def __handle_errors(
107111
errors = 0
108112
for result, meta in zip(results, artifact_metas):
109113
if isinstance(result, Err):
110-
print(f"Failed to upload artifact {meta.relative_path}: {result.value}")
114+
print(f"Failed to upload artifact {meta.relativePath}: {result.value}")
111115
errors += 1
112116
else:
113-
print(f"Successfuly uploaded artifact {meta.relative_path}")
117+
print(f"Successfuly uploaded artifact {meta.relativePath}")
114118

115119
if errors > 0:
116120
raise Exception(f"Failed to upload {errors} artifacts")

typegraph/python/typegraph/runtimes/wasmedge.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from dataclasses import dataclass
44
from typing import List, Optional
55

6-
from typegraph import t
76
from typegraph.gen.exports.runtimes import (
87
BaseMaterializer,
98
Effect,
@@ -14,6 +13,8 @@
1413
from typegraph.runtimes.base import Materializer, Runtime
1514
from typegraph.wit import runtimes, store
1615

16+
from typegraph import t
17+
1718

1819
class WasmEdgeRuntime(Runtime):
1920
def __init__(self):
@@ -29,12 +30,11 @@ def wasi(
2930
effect: Optional[Effect] = None,
3031
):
3132
effect = effect or EffectRead()
32-
wasm = f"file:{wasm}"
3333

3434
mat_id = runtimes.from_wasi_module(
3535
store,
3636
BaseMaterializer(runtime=self.id.value, effect=effect),
37-
MaterializerWasi(module=wasm, func_name=func),
37+
MaterializerWasi(wasm_artifact=wasm, func_name=func),
3838
)
3939

4040
if isinstance(mat_id, Err):

0 commit comments

Comments
 (0)