Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix importlib-metadata on Python 3.8 + bump ale-py #2428

Merged
merged 2 commits into from
Sep 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions gym/envs/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,18 +248,28 @@ def namespace(ns):
def load_env_plugins(entry_point="gym.envs"):
# Load third-party environments
for plugin in metadata.entry_points().get(entry_point, []):
if plugin.attr is None:
raise error.Error(
f"Gym environment plugin `{plugin.module}` must specify a function to execute, not a root module"
)
# Python 3.8 doesn't support plugin.module, plugin.attr
# So we'll have to try and parse this ourselves
try:
module, attr = plugin.module, plugin.attr
except AttributeError:
if ":" in plugin.value:
module, attr = plugin.value.split(":", maxsplit=1)
else:
module, attr = plugin.value, None
finally:
if attr is None:
raise error.Error(
f"Gym environment plugin `{module}` must specify a function to execute, not a root module"
)

context = namespace(plugin.name)
if plugin.name == "__internal__":
if plugin.module in plugin_internal_whitelist:
if module in plugin_internal_whitelist:
context = contextlib.nullcontext()
else:
logger.warn(
f"Trying to register an internal environment when `{plugin.module}` is not in the whitelist"
f"Trying to register an internal environment when `{module}` is not in the whitelist"
)

with context:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

# Environment-specific dependencies.
extras = {
"atari": ["ale-py~=0.7"],
"atari": ["ale-py~=0.7.1"],
"accept-rom-license": ["autorom[accept-rom-license]~=0.4.2"],
"box2d": ["box2d-py==2.3.5", "pyglet>=1.4.0"],
"classic_control": ["pyglet>=1.4.0"],
Expand Down