kscale 0.1.1__tar.gz → 0.1.2__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. {kscale-0.1.1/kscale.egg-info → kscale-0.1.2}/PKG-INFO +1 -1
  2. {kscale-0.1.1 → kscale-0.1.2}/kscale/__init__.py +1 -1
  3. {kscale-0.1.1 → kscale-0.1.2}/kscale/conf.py +1 -0
  4. {kscale-0.1.1 → kscale-0.1.2}/kscale/web/clients/robot_class.py +18 -2
  5. {kscale-0.1.1 → kscale-0.1.2}/kscale/web/utils.py +6 -0
  6. {kscale-0.1.1 → kscale-0.1.2/kscale.egg-info}/PKG-INFO +1 -1
  7. {kscale-0.1.1 → kscale-0.1.2}/LICENSE +0 -0
  8. {kscale-0.1.1 → kscale-0.1.2}/MANIFEST.in +0 -0
  9. {kscale-0.1.1 → kscale-0.1.2}/README.md +0 -0
  10. {kscale-0.1.1 → kscale-0.1.2}/kscale/api.py +0 -0
  11. {kscale-0.1.1 → kscale-0.1.2}/kscale/artifacts/__init__.py +0 -0
  12. {kscale-0.1.1 → kscale-0.1.2}/kscale/artifacts/plane.obj +0 -0
  13. {kscale-0.1.1 → kscale-0.1.2}/kscale/artifacts/plane.urdf +0 -0
  14. {kscale-0.1.1 → kscale-0.1.2}/kscale/cli.py +0 -0
  15. {kscale-0.1.1 → kscale-0.1.2}/kscale/py.typed +0 -0
  16. {kscale-0.1.1 → kscale-0.1.2}/kscale/requirements-dev.txt +0 -0
  17. {kscale-0.1.1 → kscale-0.1.2}/kscale/requirements.txt +0 -0
  18. {kscale-0.1.1 → kscale-0.1.2}/kscale/utils/__init__.py +0 -0
  19. {kscale-0.1.1 → kscale-0.1.2}/kscale/utils/api_base.py +0 -0
  20. {kscale-0.1.1 → kscale-0.1.2}/kscale/utils/checksum.py +0 -0
  21. {kscale-0.1.1 → kscale-0.1.2}/kscale/utils/cli.py +0 -0
  22. {kscale-0.1.1 → kscale-0.1.2}/kscale/web/__init__.py +0 -0
  23. {kscale-0.1.1 → kscale-0.1.2}/kscale/web/api.py +0 -0
  24. {kscale-0.1.1 → kscale-0.1.2}/kscale/web/cli/__init__.py +0 -0
  25. {kscale-0.1.1 → kscale-0.1.2}/kscale/web/cli/robot.py +0 -0
  26. {kscale-0.1.1 → kscale-0.1.2}/kscale/web/cli/robot_class.py +0 -0
  27. {kscale-0.1.1 → kscale-0.1.2}/kscale/web/cli/token.py +0 -0
  28. {kscale-0.1.1 → kscale-0.1.2}/kscale/web/cli/user.py +0 -0
  29. {kscale-0.1.1 → kscale-0.1.2}/kscale/web/clients/__init__.py +0 -0
  30. {kscale-0.1.1 → kscale-0.1.2}/kscale/web/clients/base.py +0 -0
  31. {kscale-0.1.1 → kscale-0.1.2}/kscale/web/clients/client.py +0 -0
  32. {kscale-0.1.1 → kscale-0.1.2}/kscale/web/clients/robot.py +0 -0
  33. {kscale-0.1.1 → kscale-0.1.2}/kscale/web/clients/user.py +0 -0
  34. {kscale-0.1.1 → kscale-0.1.2}/kscale/web/gen/__init__.py +0 -0
  35. {kscale-0.1.1 → kscale-0.1.2}/kscale/web/gen/api.py +0 -0
  36. {kscale-0.1.1 → kscale-0.1.2}/kscale.egg-info/SOURCES.txt +0 -0
  37. {kscale-0.1.1 → kscale-0.1.2}/kscale.egg-info/dependency_links.txt +0 -0
  38. {kscale-0.1.1 → kscale-0.1.2}/kscale.egg-info/entry_points.txt +0 -0
  39. {kscale-0.1.1 → kscale-0.1.2}/kscale.egg-info/not-zip-safe +0 -0
  40. {kscale-0.1.1 → kscale-0.1.2}/kscale.egg-info/requires.txt +0 -0
  41. {kscale-0.1.1 → kscale-0.1.2}/kscale.egg-info/top_level.txt +0 -0
  42. {kscale-0.1.1 → kscale-0.1.2}/pyproject.toml +0 -0
  43. {kscale-0.1.1 → kscale-0.1.2}/setup.cfg +0 -0
  44. {kscale-0.1.1 → kscale-0.1.2}/setup.py +0 -0
  45. {kscale-0.1.1 → kscale-0.1.2}/tests/test_dummy.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: kscale
3
- Version: 0.1.1
3
+ Version: 0.1.2
4
4
  Summary: The kscale project
5
5
  Home-page: https://github.com/kscalelabs/kscale
6
6
  Author: Benjamin Bolte
@@ -1,6 +1,6 @@
1
1
  """Defines the common interface for the K-Scale Python API."""
2
2
 
3
- __version__ = "0.1.1"
3
+ __version__ = "0.1.2"
4
4
 
5
5
  from pathlib import Path
6
6
 
@@ -22,6 +22,7 @@ def get_path() -> Path:
22
22
  class WWWSettings:
23
23
  api_root: str = field(default=DEFAULT_API_ROOT)
24
24
  cache_dir: str = field(default=II("oc.env:KSCALE_CACHE_DIR,'~/.kscale/cache/'"))
25
+ refresh_interval_minutes: int = field(default=60 * 24)
25
26
 
26
27
 
27
28
  @dataclass
@@ -1,6 +1,7 @@
1
1
  """Defines the client for interacting with the K-Scale robot class endpoints."""
2
2
 
3
3
  import hashlib
4
+ import json
4
5
  import logging
5
6
  from pathlib import Path
6
7
 
@@ -8,7 +9,7 @@ import httpx
8
9
 
9
10
  from kscale.web.clients.base import BaseClient
10
11
  from kscale.web.gen.api import RobotClass, RobotDownloadURDFResponse, RobotUploadURDFResponse
11
- from kscale.web.utils import get_cache_dir
12
+ from kscale.web.utils import get_cache_dir, should_refresh_file
12
13
 
13
14
  logger = logging.getLogger(__name__)
14
15
 
@@ -94,13 +95,22 @@ class RobotClassClient(BaseClient):
94
95
 
95
96
  async def download_robot_class_urdf(self, class_name: str, *, cache: bool = True) -> Path:
96
97
  cache_path = get_cache_dir() / class_name / "robot.tgz"
97
- if cache and cache_path.exists():
98
+ if cache and cache_path.exists() and not should_refresh_file(cache_path):
98
99
  return cache_path
99
100
  data = await self._request("GET", f"/robots/urdf/{class_name}", auth=True)
100
101
  response = RobotDownloadURDFResponse.model_validate(data)
101
102
  expected_hash = response.md5_hash
102
103
  cache_path.parent.mkdir(parents=True, exist_ok=True)
103
104
 
105
+ # Checks the md5 hash of the file.
106
+ cache_path_info = cache_path.parent / "info.json"
107
+ if cache_path_info.exists():
108
+ with open(cache_path_info, "r") as f:
109
+ info = json.load(f)
110
+ if info["md5_hash"] == expected_hash:
111
+ cache_path.touch()
112
+ return cache_path
113
+
104
114
  logger.info("Downloading URDF file from %s", response.url)
105
115
  async with httpx.AsyncClient(
106
116
  timeout=httpx.Timeout(DOWNLOAD_TIMEOUT),
@@ -118,4 +128,10 @@ class RobotClassClient(BaseClient):
118
128
  if hash_value_hex != expected_hash:
119
129
  raise ValueError(f"MD5 hash mismatch: {hash_value_hex} != {expected_hash}")
120
130
 
131
+ # Updates the info file.
132
+ logger.info("Updating downloaded file information")
133
+ info = {"md5_hash": hash_value_hex}
134
+ with open(cache_path_info, "w") as f:
135
+ json.dump(info, f)
136
+
121
137
  return cache_path
@@ -2,6 +2,7 @@
2
2
 
3
3
  import functools
4
4
  import logging
5
+ import time
5
6
  from pathlib import Path
6
7
 
7
8
  from kscale.conf import Settings
@@ -17,6 +18,11 @@ def get_cache_dir() -> Path:
17
18
  return Path(Settings.load().www.cache_dir).expanduser().resolve()
18
19
 
19
20
 
21
+ def should_refresh_file(file: Path) -> bool:
22
+ """Returns whether the file should be refreshed."""
23
+ return file.exists() and file.stat().st_mtime < time.time() - Settings.load().www.refresh_interval_minutes * 60
24
+
25
+
20
26
  @functools.lru_cache
21
27
  def get_artifact_dir(artifact_id: str) -> Path:
22
28
  """Returns the directory for a specific artifact."""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: kscale
3
- Version: 0.1.1
3
+ Version: 0.1.2
4
4
  Summary: The kscale project
5
5
  Home-page: https://github.com/kscalelabs/kscale
6
6
  Author: Benjamin Bolte
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