mirror of
https://github.com/Farama-Foundation/Gymnasium.git
synced 2025-08-01 14:10:30 +00:00
Add a compatibility layer for the new registration mechanism (#2818)
* Added some compat methods * Some missing methods * Update registration.py * Style fix
This commit is contained in:
committed by
GitHub
parent
fd9cffedfb
commit
1b09191535
@@ -12,6 +12,7 @@ from dataclasses import dataclass, field
|
||||
from typing import (
|
||||
Any,
|
||||
Callable,
|
||||
Iterable,
|
||||
Optional,
|
||||
Sequence,
|
||||
SupportsFloat,
|
||||
@@ -337,8 +338,55 @@ def make(id: EnvSpec, **kwargs) -> Env: ...
|
||||
# fmt: on
|
||||
|
||||
|
||||
class EnvRegistry(dict):
|
||||
"""A glorified dictionary for compatibility reasons.
|
||||
Turns out that some existing code directly used the old `EnvRegistry` code,
|
||||
even though the intended API was just `register` and `make`. This reimplements some
|
||||
of the old methods, so that e.g. pybullet environments will still work.
|
||||
Ideally, nobody should ever use these methods, and they will be removed soon."""
|
||||
|
||||
# TODO: remove this at 1.0
|
||||
|
||||
def make(self, path: str, **kwargs) -> Env:
|
||||
logger.warn(
|
||||
"The `registry.make` method is deprecated. Please use `gym.make` instead."
|
||||
)
|
||||
return make(path, **kwargs)
|
||||
|
||||
def register(self, id: str, **kwargs) -> None:
|
||||
logger.warn(
|
||||
"The `registry.register` method is deprecated. Please use `gym.register` instead."
|
||||
)
|
||||
return register(id, **kwargs)
|
||||
|
||||
def all(self) -> Iterable[EnvSpec]:
|
||||
logger.warn(
|
||||
"The `registry.all` method is deprecated. Please use `registry.values` instead."
|
||||
)
|
||||
return self.values()
|
||||
|
||||
def spec(self, path: str) -> EnvSpec:
|
||||
logger.warn(
|
||||
"The `registry.spec` method is deprecated. Please use `gym.spec` instead."
|
||||
)
|
||||
return spec(path)
|
||||
|
||||
def namespace(self, ns: str):
|
||||
logger.warn(
|
||||
"The `registry.namespace` method is deprecated. Please use `gym.namespace` instead."
|
||||
)
|
||||
return namespace(ns)
|
||||
|
||||
@property
|
||||
def env_specs(self):
|
||||
logger.warn(
|
||||
"The `registry.env_specs` property along with `EnvSpecTree` is deprecated. Please use `registry` directly as a dictionary instead."
|
||||
)
|
||||
return self
|
||||
|
||||
|
||||
# Global registry of environments. Meant to be accessed through `register` and `make`
|
||||
registry: dict[str, EnvSpec] = dict()
|
||||
registry: dict[str, EnvSpec] = EnvRegistry()
|
||||
current_namespace: Optional[str] = None
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user