Skip to content

Commit d43b396

Browse files
committed
Better automatic loading of environments
- A bug prevented environments to automatically register when no explicit import to the environment was made
1 parent 77c9f01 commit d43b396

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

arlie/arlie/envs/manage.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@
77
from tempfile import NamedTemporaryFile
88

99

10+
def _envs_dir(base_dir):
11+
envs = next(os.walk(base_dir))[1]
12+
try:
13+
envs.remove("__pycache__")
14+
except ValueError:
15+
pass
16+
17+
return envs
18+
19+
1020
def _download_extract_zip(url, path):
1121
"""
1222
Download a ZIP file and extract its contents in path
@@ -18,14 +28,17 @@ def _download_extract_zip(url, path):
1828
zfile.extractall(path)
1929

2030

31+
def _load_envs(base_dir, envs):
32+
module_prefix = ".".join(__name__.split(".")[:-1]) + "."
33+
env_modules = [module_prefix + e for e in envs]
34+
for modname in env_modules:
35+
__import__(modname)
36+
37+
2138
def check_envs():
2239
base_dir = Path(os.path.dirname(os.path.abspath(__file__)))
2340

24-
envs = next(os.walk(base_dir))[1]
25-
try:
26-
envs.remove("__pycache__")
27-
except ValueError:
28-
pass
41+
envs = _envs_dir(base_dir)
2942

3043
if not envs:
3144
tag = "v" + __version__
@@ -40,9 +53,13 @@ def check_envs():
4053
_download_extract_zip(url, base_dir)
4154
print("..install complete.")
4255

43-
if platform.system() == "Linux":
56+
if platform.system() == "Linux":
4457
import stat
4558

4659
for name in base_dir.rglob("*.exe"):
4760
st = os.stat(name)
4861
os.chmod(name, st.st_mode | stat.S_IEXEC)
62+
63+
envs = _envs_dir(base_dir)
64+
65+
_load_envs(base_dir, envs)

min-environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ dependencies:
1313
- pip:
1414
- gym
1515
- keyboard
16-
- arlie==1.0.0
16+
- arlie==1.0.1

0 commit comments

Comments
 (0)