tianheng.wu commited on
Commit
41d7e8f
·
1 Parent(s): 2dd090c

update env.py

Browse files
Files changed (1) hide show
  1. env.py +45 -5
env.py CHANGED
@@ -1,15 +1,55 @@
 
1
  import logging
2
  from typing import Any
3
 
 
 
 
4
  import os
5
  import sys
6
 
7
- # Ensure the repository root is on sys.path
8
- _REPO_ROOT = os.path.dirname(os.path.abspath(__file__))
9
- if _REPO_ROOT not in sys.path:
10
- sys.path.insert(0, _REPO_ROOT)
11
 
12
- from isaaclab_env_wrapper import IsaacLabEnvWrapper
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
 
15
  def make_env(n_envs: int = 1, use_async_envs: bool = False, **kwargs: Any):
 
1
+ from __future__ import annotations
2
  import logging
3
  from typing import Any
4
 
5
+ import importlib
6
+ import importlib.util
7
+ import logging
8
  import os
9
  import sys
10
 
 
 
 
 
11
 
12
+ # Hub constants for downloading additional files
13
+ HUB_REPO_ID = "LightwheelAI/lw_benchhub_env"
14
+
15
+
16
+ def _download_and_import(filename: str):
17
+ """Download file from Hub and import as module."""
18
+ from huggingface_hub import hf_hub_download
19
+
20
+ local_path = hf_hub_download(repo_id=HUB_REPO_ID, filename=filename)
21
+ module_dir = os.path.dirname(local_path)
22
+
23
+ # Add directory to sys.path so modules can import each other
24
+ if module_dir not in sys.path:
25
+ sys.path.insert(0, module_dir)
26
+
27
+ module_name = filename.replace(".py", "")
28
+
29
+ # Read file content and replace relative imports with absolute imports
30
+ with open(local_path) as f:
31
+ content = f.read()
32
+
33
+ # Replace relative imports (e.g., "from .errors" -> "from errors")
34
+ # content = content.replace("from .errors import", "from errors import")
35
+ content = content.replace("from .isaaclab_env_wrapper import", "from isaaclab_env_wrapper import")
36
+
37
+ # Create module and execute modified content
38
+ module = importlib.util.module_from_spec(importlib.util.spec_from_file_location(module_name, local_path))
39
+ sys.modules[module_name] = module
40
+
41
+ # Compile and execute the modified code
42
+ code = compile(content, local_path, "exec")
43
+ exec(code, module.__dict__) # noqa: S102
44
+
45
+ return module
46
+
47
+
48
+ try:
49
+ from .isaaclab_env_wrapper import IsaacLabEnvWrapper
50
+ except ImportError:
51
+ _isaaclab_wrapper = _download_and_import("isaaclab_env_wrapper.py")
52
+ IsaacLabEnvWrapper = _isaaclab_wrapper.IsaacLabEnvWrapper
53
 
54
 
55
  def make_env(n_envs: int = 1, use_async_envs: bool = False, **kwargs: Any):