kscale 0.0.5__tar.gz → 0.0.6__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {kscale-0.0.5/kscale.egg-info → kscale-0.0.6}/PKG-INFO +1 -1
- {kscale-0.0.5 → kscale-0.0.6}/kscale/__init__.py +1 -1
- {kscale-0.0.5 → kscale-0.0.6}/kscale/store/api.py +5 -1
- {kscale-0.0.5 → kscale-0.0.6}/kscale/store/client.py +5 -3
- {kscale-0.0.5 → kscale-0.0.6}/kscale/store/urdf.py +14 -8
- {kscale-0.0.5 → kscale-0.0.6}/kscale/store/utils.py +15 -1
- {kscale-0.0.5 → kscale-0.0.6/kscale.egg-info}/PKG-INFO +1 -1
- {kscale-0.0.5 → kscale-0.0.6}/LICENSE +0 -0
- {kscale-0.0.5 → kscale-0.0.6}/MANIFEST.in +0 -0
- {kscale-0.0.5 → kscale-0.0.6}/README.md +0 -0
- {kscale-0.0.5 → kscale-0.0.6}/kscale/api.py +0 -0
- {kscale-0.0.5 → kscale-0.0.6}/kscale/conf.py +0 -0
- {kscale-0.0.5 → kscale-0.0.6}/kscale/py.typed +0 -0
- {kscale-0.0.5 → kscale-0.0.6}/kscale/requirements-dev.txt +0 -0
- {kscale-0.0.5 → kscale-0.0.6}/kscale/requirements.txt +0 -0
- {kscale-0.0.5 → kscale-0.0.6}/kscale/store/__init__.py +0 -0
- {kscale-0.0.5 → kscale-0.0.6}/kscale/store/bullet/MANIFEST.in +0 -0
- {kscale-0.0.5 → kscale-0.0.6}/kscale/store/cli.py +0 -0
- {kscale-0.0.5 → kscale-0.0.6}/kscale/store/gen/__init__.py +0 -0
- {kscale-0.0.5 → kscale-0.0.6}/kscale/store/gen/api.py +0 -0
- {kscale-0.0.5 → kscale-0.0.6}/kscale/store/pybullet.py +0 -0
- {kscale-0.0.5 → kscale-0.0.6}/kscale/utils/__init__.py +0 -0
- {kscale-0.0.5 → kscale-0.0.6}/kscale/utils/api_base.py +0 -0
- {kscale-0.0.5 → kscale-0.0.6}/kscale.egg-info/SOURCES.txt +0 -0
- {kscale-0.0.5 → kscale-0.0.6}/kscale.egg-info/dependency_links.txt +0 -0
- {kscale-0.0.5 → kscale-0.0.6}/kscale.egg-info/entry_points.txt +0 -0
- {kscale-0.0.5 → kscale-0.0.6}/kscale.egg-info/requires.txt +0 -0
- {kscale-0.0.5 → kscale-0.0.6}/kscale.egg-info/top_level.txt +0 -0
- {kscale-0.0.5 → kscale-0.0.6}/pyproject.toml +0 -0
- {kscale-0.0.5 → kscale-0.0.6}/setup.cfg +0 -0
- {kscale-0.0.5 → kscale-0.0.6}/setup.py +0 -0
- {kscale-0.0.5 → kscale-0.0.6}/tests/test_dummy.py +0 -0
@@ -2,7 +2,8 @@
|
|
2
2
|
|
3
3
|
from pathlib import Path
|
4
4
|
|
5
|
-
from kscale.store.
|
5
|
+
from kscale.store.gen.api import UploadArtifactResponse
|
6
|
+
from kscale.store.urdf import download_urdf, upload_urdf
|
6
7
|
from kscale.utils.api_base import APIBase
|
7
8
|
|
8
9
|
|
@@ -18,3 +19,6 @@ class StoreAPI(APIBase):
|
|
18
19
|
|
19
20
|
async def urdf(self, artifact_id: str) -> Path:
|
20
21
|
return await download_urdf(artifact_id)
|
22
|
+
|
23
|
+
async def upload_urdf(self, listing_id: str, root_dir: Path) -> UploadArtifactResponse:
|
24
|
+
return await upload_urdf(listing_id, root_dir)
|
@@ -1,6 +1,7 @@
|
|
1
1
|
"""Defines a typed client for the K-Scale Store API."""
|
2
2
|
|
3
3
|
import logging
|
4
|
+
from pathlib import Path
|
4
5
|
from types import TracebackType
|
5
6
|
from typing import Any, Dict, Type
|
6
7
|
from urllib.parse import urljoin
|
@@ -14,13 +15,13 @@ from kscale.store.gen.api import (
|
|
14
15
|
SingleArtifactResponse,
|
15
16
|
UploadArtifactResponse,
|
16
17
|
)
|
17
|
-
from kscale.store.utils import
|
18
|
+
from kscale.store.utils import get_api_key, get_api_root
|
18
19
|
|
19
20
|
logger = logging.getLogger(__name__)
|
20
21
|
|
21
22
|
|
22
23
|
class KScaleStoreClient:
|
23
|
-
def __init__(self, base_url: str =
|
24
|
+
def __init__(self, base_url: str = get_api_root()) -> None:
|
24
25
|
self.base_url = base_url
|
25
26
|
self.client = httpx.AsyncClient(
|
26
27
|
base_url=self.base_url,
|
@@ -55,8 +56,9 @@ class KScaleStoreClient:
|
|
55
56
|
return SingleArtifactResponse(**data)
|
56
57
|
|
57
58
|
async def upload_artifact(self, listing_id: str, file_path: str) -> UploadArtifactResponse:
|
59
|
+
file_name = Path(file_path).name
|
58
60
|
with open(file_path, "rb") as f:
|
59
|
-
files = {"files": (
|
61
|
+
files = {"files": (file_name, f, "application/gzip")}
|
60
62
|
data = await self._request("POST", f"/artifacts/upload/{listing_id}", files=files)
|
61
63
|
return UploadArtifactResponse(**data)
|
62
64
|
|
@@ -14,7 +14,7 @@ import requests
|
|
14
14
|
|
15
15
|
from kscale.conf import Settings
|
16
16
|
from kscale.store.client import KScaleStoreClient
|
17
|
-
from kscale.store.gen.api import SingleArtifactResponse
|
17
|
+
from kscale.store.gen.api import SingleArtifactResponse, UploadArtifactResponse
|
18
18
|
from kscale.store.utils import get_api_key
|
19
19
|
|
20
20
|
# Set up logging
|
@@ -128,18 +128,24 @@ async def remove_local_urdf(artifact_id: str) -> None:
|
|
128
128
|
raise
|
129
129
|
|
130
130
|
|
131
|
-
async def upload_urdf(listing_id: str,
|
132
|
-
parser = argparse.ArgumentParser(description="K-Scale URDF Store", add_help=False)
|
133
|
-
parser.add_argument("root_dir", type=Path, help="The path to the root directory to upload")
|
134
|
-
parsed_args = parser.parse_args(args)
|
135
|
-
|
136
|
-
root_dir = parsed_args.root_dir
|
131
|
+
async def upload_urdf(listing_id: str, root_dir: Path) -> UploadArtifactResponse:
|
137
132
|
tarball_path = create_tarball(root_dir, "robot.tgz", get_artifact_dir(listing_id))
|
138
133
|
|
139
134
|
async with KScaleStoreClient() as client:
|
140
135
|
response = await client.upload_artifact(listing_id, str(tarball_path))
|
141
136
|
|
142
137
|
logger.info("Uploaded artifacts: %s", [artifact.artifact_id for artifact in response.artifacts])
|
138
|
+
return response
|
139
|
+
|
140
|
+
|
141
|
+
async def upload_urdf_cli(listing_id: str, args: Sequence[str]) -> UploadArtifactResponse:
|
142
|
+
parser = argparse.ArgumentParser(description="K-Scale URDF Store", add_help=False)
|
143
|
+
parser.add_argument("root_dir", type=Path, help="The path to the root directory to upload")
|
144
|
+
parsed_args = parser.parse_args(args)
|
145
|
+
|
146
|
+
root_dir = parsed_args.root_dir
|
147
|
+
response = await upload_urdf(listing_id, root_dir)
|
148
|
+
return response
|
143
149
|
|
144
150
|
|
145
151
|
Command = Literal["download", "info", "upload", "remove-local"]
|
@@ -165,7 +171,7 @@ async def main(args: Sequence[str] | None = None) -> None:
|
|
165
171
|
await remove_local_urdf(id)
|
166
172
|
|
167
173
|
case "upload":
|
168
|
-
await
|
174
|
+
await upload_urdf_cli(id, remaining_args)
|
169
175
|
|
170
176
|
case _:
|
171
177
|
logger.error("Invalid command")
|
@@ -4,10 +4,24 @@ import os
|
|
4
4
|
|
5
5
|
from kscale.conf import Settings
|
6
6
|
|
7
|
-
|
7
|
+
|
8
|
+
def get_api_root() -> str:
|
9
|
+
"""Returns the base URL for the K-Scale Store API.
|
10
|
+
|
11
|
+
This can be overridden when targetting a different server.
|
12
|
+
|
13
|
+
Returns:
|
14
|
+
The base URL for the K-Scale Store API.
|
15
|
+
"""
|
16
|
+
return os.getenv("KSCALE_API_ROOT", "https://api.kscale.store")
|
8
17
|
|
9
18
|
|
10
19
|
def get_api_key() -> str:
|
20
|
+
"""Returns the API key for the K-Scale Store API.
|
21
|
+
|
22
|
+
Returns:
|
23
|
+
The API key for the K-Scale Store API.
|
24
|
+
"""
|
11
25
|
api_key = Settings.load().store.api_key
|
12
26
|
if api_key is None:
|
13
27
|
api_key = os.getenv("KSCALE_API_KEY")
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|