8bitkick commited on
Commit
691ba96
·
1 Parent(s): 33a4562

Remove asset downloading logic and simplify static server setup

Browse files
pyproject.toml CHANGED
@@ -21,4 +21,4 @@ reachy_mini_web_viz = "reachy_mini_app_example.main:ExampleApp"
21
  packages = ["reachy_mini_app_example"]
22
 
23
  [tool.setuptools.package-data]
24
- reachy_mini_app_example = ["*.html", "*.css", "*.js", "assets/*.stl"]
 
21
  packages = ["reachy_mini_app_example"]
22
 
23
  [tool.setuptools.package-data]
24
+ reachy_mini_app_example = ["*.html", "*.css", "src/*.js"]
reachy_mini_app_example/main.py CHANGED
@@ -18,40 +18,11 @@ class ExampleApp(ReachyMiniApp):
18
  def start_static_server(host="127.0.0.1", port=8080, directory=None):
19
  directory = directory or Path(__file__).resolve().parent
20
 
21
- # Use local assets folder
22
- assets_path = directory / "assets"
23
-
24
- # Download assets if they don't exist
25
- if not assets_path.exists() or not list(assets_path.glob("*.stl")):
26
- print("📥 Assets not found, downloading...")
27
- from . import setup_assets
28
- setup_assets.setup_assets()
29
-
30
- # Create custom handler that serves from both directories
31
- class CustomHandler(SimpleHTTPRequestHandler):
32
- def __init__(self, *args, **kwargs):
33
- super().__init__(*args, directory=str(directory), **kwargs)
34
-
35
- def translate_path(self, path):
36
- # Parse the URL to remove query parameters
37
- from urllib.parse import urlparse, unquote
38
- path = urlparse(path).path
39
- path = unquote(path)
40
-
41
- # If requesting /assets/, serve from local assets folder
42
- if path.startswith('/assets/'):
43
- # Remove '/assets/' prefix and any leading slashes
44
- asset_file = path[8:].lstrip('/')
45
- asset_full_path = assets_path / asset_file
46
- return str(asset_full_path)
47
- # Otherwise serve from app directory
48
- return super().translate_path(path)
49
-
50
- server = HTTPServer((host, port), CustomHandler)
51
 
52
  print("📄 Open: http://127.0.0.1:8080/stream.html")
53
  print("📄 3D Viz: http://127.0.0.1:8080/robot_viz.html")
54
- print(f"📦 Serving assets from: {assets_path}\n")
55
  server.serve_forever()
56
 
57
  threading.Thread(
 
18
  def start_static_server(host="127.0.0.1", port=8080, directory=None):
19
  directory = directory or Path(__file__).resolve().parent
20
 
21
+ server = HTTPServer((host, port), partial(SimpleHTTPRequestHandler, directory=str(directory)))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
  print("📄 Open: http://127.0.0.1:8080/stream.html")
24
  print("📄 3D Viz: http://127.0.0.1:8080/robot_viz.html")
25
+ print()
26
  server.serve_forever()
27
 
28
  threading.Thread(
reachy_mini_app_example/robot_viz.html CHANGED
File without changes
reachy_mini_app_example/setup_assets.py DELETED
@@ -1,133 +0,0 @@
1
- #!/usr/bin/env python3
2
- """
3
- Download URDF mesh assets from the reachy_mini repository using Git LFS.
4
-
5
- There is definitely a more elegant way to do this...
6
- """
7
- import subprocess
8
- import shutil
9
- from pathlib import Path
10
-
11
-
12
- def setup_assets():
13
- """Download STL assets from the reachy_mini repository."""
14
- assets_dir = Path(__file__).parent / "assets"
15
-
16
- # If assets already exist and have .stl files, skip
17
- if assets_dir.exists() and list(assets_dir.glob("*.stl")):
18
- print(f"✅ Assets already exist in {assets_dir}")
19
- return
20
-
21
- print("📥 Downloading mesh assets from reachy_mini repository...")
22
-
23
- # Create assets directory
24
- assets_dir.mkdir(exist_ok=True)
25
-
26
- # Clone just the assets folder using sparse checkout
27
- temp_dir = Path(__file__).parent / ".temp_repo"
28
- temp_dir.mkdir(exist_ok=True)
29
-
30
- try:
31
- # Initialize git repo
32
- subprocess.run(
33
- ["git", "init"],
34
- cwd=temp_dir,
35
- check=False,
36
- capture_output=True
37
- )
38
-
39
- # Add remote
40
- subprocess.run(
41
- ["git", "remote", "add", "origin",
42
- "https://github.com/pollen-robotics/reachy_mini.git"],
43
- cwd=temp_dir,
44
- check=False,
45
- capture_output=True
46
- )
47
-
48
- # Configure sparse checkout
49
- subprocess.run(
50
- ["git", "config", "core.sparseCheckout", "true"],
51
- cwd=temp_dir,
52
- check=False,
53
- capture_output=True
54
- )
55
-
56
- # Specify the path to checkout
57
- sparse_file = temp_dir / ".git" / "info" / "sparse-checkout"
58
- sparse_file.parent.mkdir(parents=True, exist_ok=True)
59
- sparse_file.write_text("src/reachy_mini/descriptions/reachy_mini/urdf/assets\n")
60
-
61
- # Pull the files
62
- result = subprocess.run(
63
- ["git", "pull", "--depth=1", "origin", "develop"],
64
- cwd=temp_dir,
65
- capture_output=True,
66
- text=True
67
- )
68
-
69
- if result.returncode != 0:
70
- print(f"⚠️ Git pull failed: {result.stderr}")
71
- print("Trying direct download instead...")
72
- download_directly(assets_dir)
73
- else:
74
- # Copy assets
75
- source_assets = temp_dir / "src" / "reachy_mini" / "descriptions" / "reachy_mini" / "urdf" / "assets"
76
- if source_assets.exists():
77
- for file in source_assets.glob("*.stl"):
78
- shutil.copy(file, assets_dir / file.name)
79
- print(f"✅ Downloaded {len(list(assets_dir.glob('*.stl')))} STL files")
80
- else:
81
- print("⚠️ Assets folder not found in cloned repo")
82
- download_directly(assets_dir)
83
-
84
- finally:
85
- # Cleanup
86
- if temp_dir.exists():
87
- shutil.rmtree(temp_dir, ignore_errors=True)
88
-
89
-
90
- def download_directly(assets_dir):
91
- """Fallback: download files directly from GitHub raw URL."""
92
- import urllib.request
93
-
94
- # List of STL files (from the GitHub repo structure you showed)
95
- stl_files = [
96
- "5w_speaker.stl", "antenna.stl", "antenna_body_3dprint.stl",
97
- "antenna_holder_l_3dprint.stl", "antenna_holder_r_3dprint.stl",
98
- "antenna_interface_3dprint.stl", "arducam.stl", "arm.stl",
99
- "b3b_eh.stl", "b3b_eh_1.stl", "ball.stl", "bearing_85x110x13.stl",
100
- "big_lens.stl", "big_lens_d40.stl", "body_down_3dprint.stl",
101
- "body_foot_3dprint.stl", "body_turning_3dprint.stl",
102
- "dc15_a01_horn_dummy.stl", "dc15_a01_led_cap2_dummy.stl",
103
- "glasses_dolder_3dprint.stl", "head_back_3dprint.stl",
104
- "head_front_3dprint.stl", "head_mic_3dprint.stl",
105
- "lens_cap_d40_3dprint.stl", "m12_fisheye_lens_1_8mm.stl",
106
- "mp01062_stewart_arm_3.stl", "neck_reference_3dprint.stl",
107
- "phs_1_7x20_5_dc10.stl", "phs_1_7x20_5_dc10_1.stl",
108
- "phs_1_7x20_5_dc10_3.stl", "pp01102_arducam_carter.stl",
109
- "small_lens_d30.stl", "stewart_link_ball.stl",
110
- "stewart_link_ball_2.stl", "stewart_link_rod.stl",
111
- "stewart_tricap_3dprint.stl"
112
- ]
113
-
114
- base_url = "https://github.com/pollen-robotics/reachy_mini/raw/develop/src/reachy_mini/descriptions/reachy_mini/urdf/assets"
115
-
116
- print(f"📥 Downloading {len(stl_files)} STL files directly...")
117
- success_count = 0
118
-
119
- for filename in stl_files:
120
- url = f"{base_url}/{filename}"
121
- dest = assets_dir / filename
122
- try:
123
- urllib.request.urlretrieve(url, dest)
124
- success_count += 1
125
- print(f" ✓ {filename}")
126
- except Exception as e:
127
- print(f" ✗ {filename}: {e}")
128
-
129
- print(f"✅ Downloaded {success_count}/{len(stl_files)} files")
130
-
131
-
132
- if __name__ == "__main__":
133
- setup_assets()