humalab 0.0.3__tar.gz → 0.0.4__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.

Potentially problematic release.


This version of humalab might be problematic. Click here for more details.

Files changed (51) hide show
  1. humalab-0.0.4/Makefile +19 -0
  2. {humalab-0.0.3/humalab.egg-info → humalab-0.0.4}/PKG-INFO +1 -1
  3. humalab-0.0.4/VERSION +1 -0
  4. humalab-0.0.4/build.sh +13 -0
  5. humalab-0.0.4/humalab/assets/__init__.py +4 -0
  6. humalab-0.0.4/humalab/assets/files/__init__.py +4 -0
  7. humalab-0.0.4/humalab/assets/files/resource_file.py +41 -0
  8. humalab-0.0.4/humalab/assets/files/urdf_file.py +65 -0
  9. humalab-0.0.4/humalab/assets/resource_manager.py +57 -0
  10. {humalab-0.0.3 → humalab-0.0.4}/humalab/dists/categorical.py +3 -0
  11. {humalab-0.0.3 → humalab-0.0.4}/humalab/humalab.py +68 -0
  12. {humalab-0.0.3 → humalab-0.0.4/humalab.egg-info}/PKG-INFO +1 -1
  13. {humalab-0.0.3 → humalab-0.0.4}/humalab.egg-info/SOURCES.txt +6 -2
  14. humalab-0.0.3/VERSION +0 -1
  15. humalab-0.0.3/humalab/assets/__init__.py +0 -0
  16. humalab-0.0.3/humalab/assets/resource_file.py +0 -28
  17. humalab-0.0.3/humalab/assets/resource_handler.py +0 -175
  18. {humalab-0.0.3 → humalab-0.0.4}/.gitignore +0 -0
  19. {humalab-0.0.3 → humalab-0.0.4}/LICENSE +0 -0
  20. {humalab-0.0.3 → humalab-0.0.4}/README.md +0 -0
  21. {humalab-0.0.3 → humalab-0.0.4}/humalab/__init__.py +0 -0
  22. {humalab-0.0.3 → humalab-0.0.4}/humalab/assets/archive.py +0 -0
  23. {humalab-0.0.3 → humalab-0.0.4}/humalab/constants.py +0 -0
  24. {humalab-0.0.3 → humalab-0.0.4}/humalab/dists/__init__.py +0 -0
  25. {humalab-0.0.3 → humalab-0.0.4}/humalab/dists/bernoulli.py +0 -0
  26. {humalab-0.0.3 → humalab-0.0.4}/humalab/dists/discrete.py +0 -0
  27. {humalab-0.0.3 → humalab-0.0.4}/humalab/dists/distribution.py +0 -0
  28. {humalab-0.0.3 → humalab-0.0.4}/humalab/dists/gaussian.py +0 -0
  29. {humalab-0.0.3 → humalab-0.0.4}/humalab/dists/log_uniform.py +0 -0
  30. {humalab-0.0.3 → humalab-0.0.4}/humalab/dists/truncated_gaussian.py +0 -0
  31. {humalab-0.0.3 → humalab-0.0.4}/humalab/dists/uniform.py +0 -0
  32. {humalab-0.0.3 → humalab-0.0.4}/humalab/humalab_api_client.py +0 -0
  33. {humalab-0.0.3 → humalab-0.0.4}/humalab/humalab_config.py +0 -0
  34. {humalab-0.0.3 → humalab-0.0.4}/humalab/humalab_test.py +0 -0
  35. {humalab-0.0.3 → humalab-0.0.4}/humalab/metrics/__init__.py +0 -0
  36. {humalab-0.0.3 → humalab-0.0.4}/humalab/metrics/dist_metric.py +0 -0
  37. {humalab-0.0.3 → humalab-0.0.4}/humalab/metrics/metric.py +0 -0
  38. {humalab-0.0.3 → humalab-0.0.4}/humalab/metrics/summary.py +0 -0
  39. {humalab-0.0.3 → humalab-0.0.4}/humalab/run.py +0 -0
  40. {humalab-0.0.3 → humalab-0.0.4}/humalab/scenario.py +0 -0
  41. {humalab-0.0.3 → humalab-0.0.4}/humalab/scenario_test.py +0 -0
  42. {humalab-0.0.3 → humalab-0.0.4}/humalab.egg-info/dependency_links.txt +0 -0
  43. {humalab-0.0.3 → humalab-0.0.4}/humalab.egg-info/entry_points.txt +0 -0
  44. {humalab-0.0.3 → humalab-0.0.4}/humalab.egg-info/not-zip-safe +0 -0
  45. {humalab-0.0.3 → humalab-0.0.4}/humalab.egg-info/requires.txt +0 -0
  46. {humalab-0.0.3 → humalab-0.0.4}/humalab.egg-info/top_level.txt +0 -0
  47. {humalab-0.0.3 → humalab-0.0.4}/pyproject.toml +0 -0
  48. {humalab-0.0.3 → humalab-0.0.4}/requirements-dev.txt +0 -0
  49. {humalab-0.0.3 → humalab-0.0.4}/requirements.txt +0 -0
  50. {humalab-0.0.3 → humalab-0.0.4}/setup.cfg +0 -0
  51. {humalab-0.0.3 → humalab-0.0.4}/setup.py +0 -0
humalab-0.0.4/Makefile ADDED
@@ -0,0 +1,19 @@
1
+ .PHONY: clean build upload upload-test install dev
2
+
3
+ clean:
4
+ rm -rf dist/ build/ *.egg-info
5
+
6
+ build: clean
7
+ python -m build
8
+
9
+ upload: build
10
+ twine upload dist/*
11
+
12
+ upload-test: build
13
+ twine upload --repository testpypi dist/*
14
+
15
+ install:
16
+ pip install -e .
17
+
18
+ dev:
19
+ pip install -e ".[dev]"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: humalab
3
- Version: 0.0.3
3
+ Version: 0.0.4
4
4
  Summary: Python SDK for HumaLab - A platform for adaptive AI validation.
5
5
  Home-page: https://github.com/humalab/humalab_sdk
6
6
  Author: HumaLab Team
humalab-0.0.4/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.4
humalab-0.0.4/build.sh ADDED
@@ -0,0 +1,13 @@
1
+ #!/bin/bash
2
+ # Build script for humalab package
3
+
4
+ set -e
5
+
6
+ echo "Cleaning old builds..."
7
+ rm -rf dist/ build/ *.egg-info
8
+
9
+ echo "Building package..."
10
+ python -m build
11
+
12
+ echo "Build complete! Artifacts in dist/"
13
+ ls -lh dist/
@@ -0,0 +1,4 @@
1
+ from .resource import ResourceManager
2
+ from .files import ResourceFile, URDFFile
3
+
4
+ __all__ = ["ResourceManager", "ResourceFile", "URDFFile"]
@@ -0,0 +1,4 @@
1
+ from .resource_file import ResourceFile
2
+ from .urdf_file import URDFFile
3
+
4
+ __all__ = ["ResourceFile", "URDFFile"]
@@ -0,0 +1,41 @@
1
+ from datetime import datetime
2
+
3
+
4
+ class ResourceFile:
5
+ def __init__(self,
6
+ name: str,
7
+ version: int,
8
+ filename: str,
9
+ resource_type: str,
10
+ description: str | None = None,
11
+ created_at: datetime | None = None):
12
+ self._name = name
13
+ self._version = version
14
+ self._filename = filename
15
+ self._resource_type = resource_type
16
+ self._description = description
17
+ self._created_at = created_at
18
+
19
+ @property
20
+ def name(self) -> str:
21
+ return self._name
22
+
23
+ @property
24
+ def version(self) -> int:
25
+ return self._version
26
+
27
+ @property
28
+ def filename(self) -> str:
29
+ return self._filename
30
+
31
+ @property
32
+ def resource_type(self) -> str:
33
+ return self._resource_type
34
+
35
+ @property
36
+ def created_at(self) -> datetime | None:
37
+ return self._created_at
38
+
39
+ @property
40
+ def description(self) -> str | None:
41
+ return self._description
@@ -0,0 +1,65 @@
1
+ from datetime import datetime
2
+ import os
3
+ import glob
4
+ from humalab.assets.files.resource_file import ResourceFile
5
+ from humalab.assets.archive import extract_archive
6
+
7
+
8
+ class URDFFile(ResourceFile):
9
+ def __init__(self,
10
+ name: str,
11
+ version: int,
12
+ filename: str,
13
+ urdf_filename: str | None = None,
14
+ description: str | None = None,
15
+ created_at: datetime | None = None,):
16
+ super().__init__(name=name,
17
+ version=version,
18
+ description=description,
19
+ filename=filename,
20
+ resource_type="URDF",
21
+ created_at=created_at)
22
+ self._urdf_base_filename = urdf_filename
23
+ self._urdf_filename, self._root_path = self._extract()
24
+ self._urdf_filename = os.path.join(self._urdf_filename, self._urdf_filename)
25
+
26
+ def _extract(self):
27
+ working_path = os.path.dirname(self._filename)
28
+ if not os.path.exists(working_path):
29
+ _, ext = os.path.splitext(self._filename)
30
+ ext = ext.lstrip('.') # Remove leading dot
31
+ if ext.lower() != "urdf":
32
+ extract_archive(self._filename, working_path)
33
+ try:
34
+ os.remove(self._filename)
35
+ except Exception as e:
36
+ print(f"Error removing saved file {self._filename}: {e}")
37
+ local_filename = self.search_resource_file(self._urdf_base_filename, working_path)
38
+ if local_filename is None:
39
+ raise ValueError(f"Resource filename {self._urdf_base_filename} not found in {working_path}")
40
+ return local_filename, working_path
41
+
42
+ def search_resource_file(self, resource_filename: str | None, working_path: str) -> str | None:
43
+ found_filename = None
44
+ if resource_filename:
45
+ search_path = os.path.join(working_path, "**")
46
+ search_pattern = os.path.join(search_path, resource_filename)
47
+ files = glob.glob(search_pattern, recursive=True)
48
+ if len(files) > 0:
49
+ found_filename = files[0]
50
+
51
+ if found_filename is None:
52
+ ext = "urdf"
53
+ search_pattern = os.path.join(working_path, "**", f"*.{ext}")
54
+ files = glob.glob(search_pattern, recursive=True)
55
+ if len(files) > 0:
56
+ found_filename = files[0]
57
+ return found_filename
58
+
59
+ @property
60
+ def urdf_filename(self) -> str | None:
61
+ return self._urdf_filename
62
+
63
+ @property
64
+ def root_path(self) -> str:
65
+ return self._root_path
@@ -0,0 +1,57 @@
1
+ from humalab.assets.files.resource_file import ResourceFile
2
+ from humalab.humalab_config import HumalabConfig
3
+ from humalab.humalab_api_client import HumaLabApiClient
4
+ from humalab.assets.files.urdf_file import URDFFile
5
+ import os
6
+ from typing import Any
7
+
8
+
9
+ class ResourceManager:
10
+ def __init__(self,
11
+ api_key: str | None = None,
12
+ host: str | None = None,
13
+ timeout: float | None = None):
14
+ self._humalab_config = HumalabConfig()
15
+ self._base_url = host or self._humalab_config.base_url
16
+ self._api_key = api_key or self._humalab_config.api_key
17
+ self._timeout = timeout or self._humalab_config.timeout
18
+
19
+ self._api_client = HumaLabApiClient(base_url=self._base_url,
20
+ api_key=self._api_key,
21
+ timeout=self._timeout)
22
+
23
+ def _asset_dir(self, name: str, version: int) -> str:
24
+ return os.path.join(self._humalab_config.workspace_path, "assets", name, f"{version}")
25
+
26
+ def _create_asset_dir(self, name: str, version: int) -> bool:
27
+ asset_dir = self._asset_dir(name, version)
28
+ if not os.path.exists(asset_dir):
29
+ os.makedirs(asset_dir, exist_ok=True)
30
+ return True
31
+ return False
32
+
33
+ def download(self,
34
+ name: str,
35
+ version: int | None=None) -> Any:
36
+ resource = self._api_client.get_resource(name=name, version=version)
37
+ file_content = self._api_client.download_resource(name="lerobot")
38
+ filename = os.path.basename(resource['resource_url'])
39
+ filename = os.path.join(self._asset_dir(name, resource["version"]), filename)
40
+ if self._create_asset_dir(name, resource["version"]):
41
+ with open(filename, "wb") as f:
42
+ f.write(file_content)
43
+
44
+ if resource["resource_type"].lower() == "urdf":
45
+ return URDFFile(name=resource["name"],
46
+ version=resource["version"],
47
+ description=resource.get("description"),
48
+ filename=filename,
49
+ urdf_filename=resource.get("filename"),
50
+ created_at=resource.get("created_at"))
51
+
52
+ return ResourceFile(name=name,
53
+ version=resource["version"],
54
+ filename=filename,
55
+ resource_type=resource["resource_type"],
56
+ description=resource.get("description"),
57
+ created_at=resource.get("created_at"))
@@ -20,6 +20,9 @@ class Categorical(Distribution):
20
20
  super().__init__(generator=generator)
21
21
  self._choices = choices
22
22
  self._size = size
23
+ if weights is not None and not np.isclose(sum(weights), 1.0):
24
+ weight_sum = sum(weights)
25
+ weights = [w / weight_sum for w in weights]
23
26
  self._weights = weights
24
27
 
25
28
  def _sample(self) -> int | float | np.ndarray:
@@ -1,4 +1,8 @@
1
1
  from contextlib import contextmanager
2
+
3
+ from humalab.assets.files.resource_file import ResourceFile
4
+ from humalab.assets.files.urdf_file import URDFFile
5
+ from humalab.assets.resource_manager import ResourceManager
2
6
  from humalab.run import Run
3
7
  from humalab.humalab_config import HumalabConfig
4
8
  from humalab.humalab_api_client import HumaLabApiClient
@@ -131,6 +135,69 @@ if __name__ == "__main__":
131
135
  print("Friction: ", scenario.scenario.cup.friction)
132
136
  print("Num Objects: ", scenario.scenario.num_objects)
133
137
 
138
+ scenario_string = """
139
+ scenario:
140
+ cup:
141
+ position: "${uniform: [0.7, 0.7, 0.7],
142
+ [1.5, 1.3, 0.7], [2, 3]}"
143
+ orientation: "${uniform: 0.3, 0.7}"
144
+ asset: "${categorical: ['lerobot', 'apple2', 'apple3'], [0.1, 0.3, 0.5]}"
145
+ friction: "${gaussian: 0.3, 0.05}"
146
+ hello: 13
147
+ jkjk: test
148
+ num_objects: "${discrete: 5, 10}"
149
+ dfdjkjk: "hello"
150
+ """
151
+ with init(entity="default",
152
+ project="test",
153
+ name="my first run",
154
+ description="testing the humalab sdk",
155
+ tags=["tag1", "tag2"],
156
+ scenario=scenario_string,
157
+ num_env=None) as run:
158
+ print(f"Run ID: {run.id}")
159
+ print(f"Run Name: {run.name}")
160
+ print(f"Run Description: {run.description}")
161
+ print(f"Run Tags: {run.tags}")
162
+ print(f"Run Scenario YAML:\n{run.scenario.yaml}")
163
+
164
+ scenario = run.scenario
165
+ # Simulate some operations
166
+ print("CUP position: ", scenario.scenario.cup.position)
167
+ print("CUP orientation: ", scenario.scenario.cup.orientation)
168
+ print("Asset: ", scenario.scenario.cup.asset)
169
+ print("Friction: ", scenario.scenario.cup.friction)
170
+ print("Num Objects: ", scenario.scenario.num_objects)
171
+ scenario.reset()
172
+ print("======================SCENARIO RESET==========================")
173
+ print("CUP position: ", scenario.scenario.cup.position)
174
+ print("CUP orientation: ", scenario.scenario.cup.orientation)
175
+ print("Asset: ", scenario.scenario.cup.asset)
176
+ print("Friction: ", scenario.scenario.cup.friction)
177
+ print("Num Objects: ", scenario.scenario.num_objects)
178
+
179
+ resource = ResourceManager()
180
+ urdf_file: URDFFile = resource.download(name="lerobot", version=1)
181
+ print("URDF File: ", urdf_file.filename)
182
+ print("URDF Description: ", urdf_file.description)
183
+ print("URDF Created At: ", urdf_file.created_at)
184
+ print("URDF Root Path: ", urdf_file._root_path)
185
+ print("URDF Root Path: ", urdf_file._urdf_filename)
186
+
187
+ urdf_file: URDFFile = resource.download(name="lerobot")
188
+ print("URDF File: ", urdf_file.filename)
189
+ print("URDF Description: ", urdf_file.description)
190
+ print("URDF Created At: ", urdf_file.created_at)
191
+ print("URDF Root Path: ", urdf_file._root_path)
192
+ print("URDF Root Path: ", urdf_file._urdf_filename)
193
+
194
+ atlas_file: ResourceFile = resource.download(name="atlas_description_test")
195
+ print("Atlas File: ", atlas_file.filename)
196
+ print("Atlas Description: ", atlas_file.description)
197
+ print("Atlas Created At: ", atlas_file.created_at)
198
+
199
+
200
+ """
134
201
  humalab_config = HumalabConfig()
135
202
  base_url = humalab_config.base_url
136
203
  api_key = humalab_config.api_key
@@ -147,3 +214,4 @@ if __name__ == "__main__":
147
214
  with open(filename, "wb") as f:
148
215
  f.write(file_content)
149
216
  print(f"Resource file downloaded: {filename}")
217
+ """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: humalab
3
- Version: 0.0.3
3
+ Version: 0.0.4
4
4
  Summary: Python SDK for HumaLab - A platform for adaptive AI validation.
5
5
  Home-page: https://github.com/humalab/humalab_sdk
6
6
  Author: HumaLab Team
@@ -1,7 +1,9 @@
1
1
  .gitignore
2
2
  LICENSE
3
+ Makefile
3
4
  README.md
4
5
  VERSION
6
+ build.sh
5
7
  pyproject.toml
6
8
  requirements-dev.txt
7
9
  requirements.txt
@@ -24,8 +26,10 @@ humalab.egg-info/requires.txt
24
26
  humalab.egg-info/top_level.txt
25
27
  humalab/assets/__init__.py
26
28
  humalab/assets/archive.py
27
- humalab/assets/resource_file.py
28
- humalab/assets/resource_handler.py
29
+ humalab/assets/resource_manager.py
30
+ humalab/assets/files/__init__.py
31
+ humalab/assets/files/resource_file.py
32
+ humalab/assets/files/urdf_file.py
29
33
  humalab/dists/__init__.py
30
34
  humalab/dists/bernoulli.py
31
35
  humalab/dists/categorical.py
humalab-0.0.3/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.0.3
File without changes
@@ -1,28 +0,0 @@
1
-
2
-
3
- class ResourceFile:
4
- def __init__(self,
5
- name: str,
6
- version: int,
7
- resource_type: str,
8
- filepath: str):
9
- self._name = name
10
- self._version = version
11
- self._resource_type = resource_type
12
- self._filepath = filepath
13
-
14
- @property
15
- def name(self) -> str:
16
- return self._name
17
-
18
- @property
19
- def version(self) -> int:
20
- return self._version
21
-
22
- @property
23
- def resource_type(self) -> str:
24
- return self._resource_type
25
-
26
- @property
27
- def filepath(self) -> str:
28
- return self._filepath
@@ -1,175 +0,0 @@
1
- import mongoengine as me
2
- from minio import Minio
3
- import os
4
- import glob
5
- import tempfile
6
- import trimesh
7
- from humalab_service.humalab_host import HumaLabHost
8
- from humalab_service.services.stores.obj_store import ObjStore
9
- from humalab_service.services.stores.namespace import ObjectType
10
- from humalab_service.db.resource import ResourceDocument
11
- from humalab.assets.archive import extract_archive
12
-
13
-
14
- ASSET_TYPE_TO_EXTENSIONS = {
15
- "urdf": {"urdf"},
16
- "mjcf": {"xml"},
17
- "mesh": trimesh.available_formats(),
18
- "usd": {"usd"},
19
- "controller": {"py"},
20
- "global_controller": {"py"},
21
- "terminator": {"py"},
22
- "data": {},
23
- }
24
-
25
- class ResourceHandler:
26
- def __init__(self, working_path: str=tempfile.gettempdir()):
27
- self._minio_client = Minio(
28
- HumaLabHost.get_minio_service_address(),
29
- access_key="humalab",
30
- secret_key="humalab123",
31
- secure=False
32
- )
33
- self._obj_store = ObjStore(self._minio_client)
34
- self.working_path_root = working_path
35
-
36
- def search_resource_file(self, resource_filename: str | None, working_path: str, morph_type: str) -> str | None:
37
- found_filename = None
38
- if resource_filename:
39
- search_path = os.path.join(working_path, "**")
40
- search_pattern = os.path.join(search_path, resource_filename)
41
- files = glob.glob(search_pattern, recursive=True)
42
- if len(files) > 0:
43
- found_filename = files[0]
44
-
45
- if found_filename is None:
46
- for ext in ASSET_TYPE_TO_EXTENSIONS[morph_type]:
47
- search_pattern = os.path.join(working_path, "**", f"*.{ext}")
48
- files = glob.glob(search_pattern, recursive=True)
49
- if len(files) > 0:
50
- found_filename = files[0]
51
- break
52
- return found_filename
53
-
54
- def _save_file(self, filepath: str, data: bytes) -> str:
55
- os.makedirs(os.path.dirname(filepath), exist_ok=True)
56
- with open(filepath, "wb") as f:
57
- f.write(data)
58
- return filepath
59
-
60
- def _save_and_extract(self, working_path: str, local_filepath: str, file_content: bytes, file_type: str):
61
- os.makedirs(working_path, exist_ok=True)
62
- saved_filepath = self._save_file(local_filepath, file_content)
63
- _, ext = os.path.splitext(saved_filepath)
64
- ext = ext.lstrip('.') # Remove leading dot
65
- if ext not in ASSET_TYPE_TO_EXTENSIONS[file_type]:
66
- extract_archive(saved_filepath, working_path)
67
- try:
68
- os.remove(saved_filepath)
69
- except Exception as e:
70
- print(f"Error removing saved file {saved_filepath}: {e}")
71
-
72
- def save_file(self,
73
- resource_name: str,
74
- resource_version: int,
75
- object_type: ObjectType,
76
- file_content: bytes,
77
- file_url: str,
78
- resource_type: str,
79
- filename: str | None = None) -> str:
80
- working_path = self.get_working_path(object_type, resource_name, resource_version)
81
- local_filepath = os.path.join(working_path, os.path.basename(file_url))
82
- local_filename = None
83
- if os.path.exists(os.path.dirname(working_path)):
84
- # if directory exists, try to search for the file
85
- local_filename = self.search_resource_file(filename, working_path, resource_type)
86
- if local_filename is None:
87
- # if not found, save the file and extract the archive,
88
- # then search for the file again
89
- self._save_and_extract(working_path, local_filepath, file_content, resource_type)
90
- local_filename = self.search_resource_file(filename, working_path, resource_type)
91
- if local_filename is None:
92
- # if still not found, raise an error
93
- raise ValueError(f"Resource filename {filename} not found in {working_path}")
94
- return local_filename
95
-
96
- def get_working_path(self, obj_type: ObjectType, uuid: str, version: int) -> str:
97
- return os.path.join(self.working_path_root, "humalab", obj_type.value, uuid + "_" + str(version))
98
-
99
- def query_and_download_resource(self, resource_name: str, resource_version: int | None = None) -> tuple[str, str]:
100
- """ Query the resource from the database and download it from the object store.
101
- Args:
102
- resource_name (str): The name of the resource.
103
- resource_version (int | None): The version of the resource. If None, the latest version will be used.
104
- Returns:
105
- tuple[str, str]: A tuple containing the local filename of the resource and the working directory
106
- where the resource was downloaded and extracted.
107
- """
108
- me.connect("humalab", host=f"mongodb://{HumaLabHost.get_mongodb_service_address()}")
109
- if resource_version is None:
110
- resource = ResourceDocument.objects(name=resource_name.strip(), latest=True).first()
111
- else:
112
- resource = ResourceDocument.objects(name=resource_name.strip(), version=resource_version).first()
113
- if resource is None:
114
- raise ValueError(f"Resource {resource_name}:{resource_version} not found")
115
- return self.download_resource(resource.name, resource.version, resource.file_url, resource.resource_type.value, resource.filename)
116
-
117
- def download_resource(self,
118
- resource_name: str,
119
- resource_version: int,
120
- resource_url: str,
121
- resource_type: str,
122
- resource_filename: str | None = None) -> tuple[str, str]:
123
- """ Download a resource from the object store.
124
- Args:
125
- resource_name (str): The name of the resource.
126
- resource_version (int): The version of the resource.
127
- resource_url (str): The URL of the resource in the object store.
128
- resource_type (str): The type of the resource (e.g., "urdf", "mjcf", "mesh", etc.).
129
- resource_filename (str | None): The specific filename to search for within the resource directory. If None, the first file found will be used.
130
- Returns:
131
- tuple[str, str]: A tuple containing the local filename of the resource and the working directory
132
- where the resource was downloaded and extracted.
133
- """
134
- return self._download_resource(resource_name,
135
- resource_version,
136
- ObjectType.RESOURCE,
137
- resource_url,
138
- resource_type,
139
- resource_filename)
140
-
141
- def _download_resource(self,
142
- resource_name: str,
143
- resource_version: int,
144
- object_type: ObjectType,
145
- resource_url: str,
146
- resource_type: str,
147
- resource_filename: str | None = None) -> tuple[str, str]:
148
- """
149
- Download an asset from the object store and extract it if necessary.
150
-
151
- Args:
152
- asset_uuid (str): The UUID of the asset.
153
- asset_version (int): The version of the asset.
154
- asset_type (ObjectType): The type of the asset (e.g., URDF, MJCF, Mesh, etc.).
155
- asset_url (str): The URL of the asset in the object store.
156
- asset_file_type (str): The type of the asset file (e.g., "urdf", "mjcf", "mesh", etc.).
157
- asset_filename (str | None): The specific filename to search for within the asset directory. If None, the first file found will be used.
158
-
159
- Returns:
160
- tuple[str, str]: A tuple containing the local filename of the asset and the working directory
161
- where the asset was downloaded and extracted.
162
- """
163
- working_path = self.get_working_path(object_type, resource_name, resource_version)
164
- local_filepath = os.path.join(working_path, os.path.basename(resource_url))
165
- if not os.path.exists(working_path):
166
- os.makedirs(working_path, exist_ok=True)
167
- self._obj_store.download_file(object_type, resource_url, local_filepath)
168
- _, ext = os.path.splitext(resource_url)
169
- ext = ext.lower().lstrip('.')
170
- if ext not in ASSET_TYPE_TO_EXTENSIONS[resource_type]:
171
- extract_archive(local_filepath, working_path)
172
- local_filename = self.search_resource_file(resource_filename, working_path, resource_type)
173
- if local_filename is None:
174
- raise ValueError(f"Resource filename {resource_filename} not found in {working_path}")
175
- return local_filename, working_path
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