From 2cf8f8e95f55ff5beb04b529552c8aad29d9714c Mon Sep 17 00:00:00 2001 From: Steven Morad Date: Fri, 5 Jan 2024 13:44:35 +0000 Subject: [PATCH] Remove call to deprecated importlib find_loader (#31) * remove call to deprecated importlib find_loader * bump version for release * edit readme for mazelib issue and add small example --- .pre-commit-config.yaml | 2 +- README.md | 21 ++++++++++++++++++--- popgym/envs/__init__.py | 4 ++-- setup.cfg | 2 +- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4155ffe..c4f6b76 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,7 +13,7 @@ repos: name: isort (python) args: ["--profile", "black"] - repo: https://github.com/pycqa/flake8 - rev: 4.0.1 + rev: 7.0.0 hooks: - id: flake8 args: diff --git a/README.md b/README.md index 50dd49b..8c1685d 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,24 @@ Please see the [documentation](https://popgym.readthedocs.io/en/latest/) for adv ## Quickstart Install ```python -pip install popgym # base environments only, only requires numpy and gymnasium -pip install --use-pep517 "popgym[navigation]" # also include navigation environments, which require mazelib -pip install "popgym[baselines]" # environments and memory baselines +# Install base environments, only requires numpy and gymnasium +pip install popgym +# Also include navigation environments, which require mazelib +# NOTE: navigation envs require python <3.12 due to mazelib not supporting 3.12 +pip install "popgym[navigation]" +# Install memory baselines w/ RLlib +pip install "popgym[baselines]" +``` + +## Quickstart Usage + +```python +import popgym +from popgym.wrappers import PreviousAction, Antialias, Flatten, DiscreteAction +env = popgym.envs.position_only_cartpole.PositionOnlyCartPoleEasy() +print(env.reset(seed=0)) +wrapped = DiscreteAction(Flatten(PreviousAction(env))) # Append prev action to obs, flatten obs/action spaces, then map the multidiscrete action space to a single discrete action for Q learning +print(wrapped.reset(seed=0)) ``` ## POPGym Environments diff --git a/popgym/envs/__init__.py b/popgym/envs/__init__.py index ffa1a60..4df6d00 100644 --- a/popgym/envs/__init__.py +++ b/popgym/envs/__init__.py @@ -2,7 +2,7 @@ """ import inspect -from importlib import find_loader +from importlib.util import find_spec from typing import Any, Dict import gymnasium as gym @@ -255,7 +255,7 @@ # def has_mazelib(): # noqa: E302 """Check if mazelib is installed""" - return find_loader("mazelib") is not None + return find_spec("mazelib") is not None if has_mazelib(): diff --git a/setup.cfg b/setup.cfg index 02e7b38..1f2c3f2 100644 --- a/setup.cfg +++ b/setup.cfg @@ -4,7 +4,7 @@ description = A collection of partially-observable procedural gym environments long_description = file: README.md long_description_content_type = text/markdown author = Steven Morad -version = 1.0.4 +version = 1.0.5 license = MIT readme = README.md requires_python = >=3.7