From 6501cd13ed89151b9d618d541cdc46a5e1074855 Mon Sep 17 00:00:00 2001 From: Mark Towers Date: Sat, 11 Jan 2025 22:16:58 +0000 Subject: [PATCH] Update CI, pre-commit and website (#121) --- .github/ISSUE_TEMPLATE/bug.md | 2 +- .github/ISSUE_TEMPLATE/proposal.md | 4 +-- .github/ISSUE_TEMPLATE/question.md | 10 +++---- .github/dependabot.yml | 14 +++++++++ {bin => .github/docker}/docker_entrypoint | 0 .github/docker/testing-old.Dockerfile | 20 +++++++++++++ .../docker/testing.Dockerfile | 6 ++-- .github/stale.yml | 2 +- .github/workflows/build-docs-dev.yml | 4 +-- .github/workflows/build-docs-version.yml | 4 +-- .github/workflows/build-publish.yml | 15 ++-------- .../workflows/manual-build-docs-version.yml | 4 +-- .github/workflows/pre-commit.yml | 2 +- .github/workflows/{build.yml => pytest.yml} | 21 +++++++++---- .pre-commit-config.yaml | 28 +++++++++++++---- CODE_OF_CONDUCT.rst | 2 -- README.md | 6 ++-- docs/.gitignore | 2 +- docs/404.md | 2 +- docs/_scripts/gen_env_docs.py | 5 ++-- docs/_scripts/gen_envs_display.py | 8 +++-- docs/_static/img/miniworld-text.svg | 2 +- docs/_static/img/miniworld-white.svg | 2 +- docs/_static/img/miniworld.svg | 2 +- docs/content/create_env.md | 2 +- docs/content/env_list.md | 5 ---- docs/content/environments.md | 24 +++++++++++++++ docs/content/installation.md | 2 +- docs/content/troubleshooting.md | 30 +++++++++---------- docs/index.md | 13 ++------ docs/release_notes.md | 2 +- requirements.txt | 13 -------- setup.py | 8 ++--- tests/test_miniworld.py | 19 +++++------- 34 files changed, 165 insertions(+), 120 deletions(-) create mode 100644 .github/dependabot.yml rename {bin => .github/docker}/docker_entrypoint (100%) mode change 100644 => 100755 create mode 100644 .github/docker/testing-old.Dockerfile rename py.Dockerfile => .github/docker/testing.Dockerfile (76%) rename .github/workflows/{build.yml => pytest.yml} (59%) delete mode 100644 docs/content/env_list.md create mode 100644 docs/content/environments.md delete mode 100644 requirements.txt mode change 100755 => 100644 tests/test_miniworld.py diff --git a/.github/ISSUE_TEMPLATE/bug.md b/.github/ISSUE_TEMPLATE/bug.md index 465bb83d..02c30c5e 100644 --- a/.github/ISSUE_TEMPLATE/bug.md +++ b/.github/ISSUE_TEMPLATE/bug.md @@ -24,4 +24,4 @@ Add any other context about the problem here. ### Checklist -- [ ] I have checked that there is no similar [issue](https://github.com/Farama-Foundation/gym-miniworld/issues) in the repo (**required**) \ No newline at end of file +- [ ] I have checked that there is no similar [issue](https://github.com/Farama-Foundation/miniworld/issues) in the repo (**required**) diff --git a/.github/ISSUE_TEMPLATE/proposal.md b/.github/ISSUE_TEMPLATE/proposal.md index 079d8bb9..2b893241 100644 --- a/.github/ISSUE_TEMPLATE/proposal.md +++ b/.github/ISSUE_TEMPLATE/proposal.md @@ -6,7 +6,7 @@ title: "[Proposal] Proposal title" -### Proposal +### Proposal A clear and concise description of the proposal. @@ -30,4 +30,4 @@ Add any other context or screenshots about the feature request here. ### Checklist -- [ ] I have checked that there is no similar [issue](https://github.com/Farama-Foundation/gym-miniworld/issues) in the repo (**required**) +- [ ] I have checked that there is no similar [issue](https://github.com/Farama-Foundation/miniworld/issues) in the repo (**required**) diff --git a/.github/ISSUE_TEMPLATE/question.md b/.github/ISSUE_TEMPLATE/question.md index df5c247c..cdca42a0 100644 --- a/.github/ISSUE_TEMPLATE/question.md +++ b/.github/ISSUE_TEMPLATE/question.md @@ -7,11 +7,11 @@ title: "[Question] Question title" ### Question -If you're a beginner and have basic questions, please ask on -[r/reinforcementlearning](https://www.reddit.com/r/reinforcementlearning/) -or in the [RL Discord](https://discord.com/invite/xhfNqQv) -(if you're new please use the beginners channel). -Basic questions that are not bugs or feature requests will be closed without reply, +If you're a beginner and have basic questions, please ask on +[r/reinforcementlearning](https://www.reddit.com/r/reinforcementlearning/) +or in the [RL Discord](https://discord.com/invite/xhfNqQv) +(if you're new please use the beginners channel). +Basic questions that are not bugs or feature requests will be closed without reply, because GitHub issues are not an appropriate venue for these. Advanced/nontrivial questions, especially in areas where documentation is lacking, are very much welcome. diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..ea7c7d78 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,14 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + # Enable version updates for GitHub Actions + - package-ecosystem: "github-actions" + # Look for GitHub Actions workflows in the `root` directory + directory: "/" + # Check the for updates once a week + schedule: + interval: "weekly" diff --git a/bin/docker_entrypoint b/.github/docker/docker_entrypoint old mode 100644 new mode 100755 similarity index 100% rename from bin/docker_entrypoint rename to .github/docker/docker_entrypoint diff --git a/.github/docker/testing-old.Dockerfile b/.github/docker/testing-old.Dockerfile new file mode 100644 index 00000000..ff915f09 --- /dev/null +++ b/.github/docker/testing-old.Dockerfile @@ -0,0 +1,20 @@ +# A Dockerfile that sets up a full Gym install with test dependencies +ARG PYTHON_VERSION +FROM python:$PYTHON_VERSION + +SHELL ["/bin/bash", "-o", "pipefail", "-c"] + +RUN apt-get -y update +RUN apt-get install -y freeglut3-dev xvfb + +COPY ../.. /usr/local/miniworld/ +WORKDIR /usr/local/miniworld/ + +RUN pip install .[testing] gymnasium==0.29.1 numpy==1.26.4 + +RUN ["chmod", "+x", "/usr/local/miniworld/.github/docker/docker_entrypoint"] + +ENTRYPOINT ["/usr/local/miniworld/.github/docker/docker_entrypoint"] + +#RUN cd pytorch-a2c-ppo-acktr +#RUN xvfb-run -a -s "-screen 0 1024x768x24 -ac +extension GLX +render -noreset" time python3 main.py --no-cuda --algo a2c --log-interval 1 --num-frames 200 --num-processes 1 --num-steps 80 --lr 0.00005 --env-name MiniWorld-Hallway-v0 diff --git a/py.Dockerfile b/.github/docker/testing.Dockerfile similarity index 76% rename from py.Dockerfile rename to .github/docker/testing.Dockerfile index 07d8533d..0b7a9656 100644 --- a/py.Dockerfile +++ b/.github/docker/testing.Dockerfile @@ -7,14 +7,14 @@ SHELL ["/bin/bash", "-o", "pipefail", "-c"] RUN apt-get -y update RUN apt-get install -y freeglut3-dev xvfb -COPY . /usr/local/miniworld/ +COPY ../.. /usr/local/miniworld/ WORKDIR /usr/local/miniworld/ RUN pip install .[testing] --no-cache-dir -RUN ["chmod", "+x", "/usr/local/miniworld/bin/docker_entrypoint"] +RUN ["chmod", "+x", "/usr/local/miniworld/.github/docker/docker_entrypoint"] -ENTRYPOINT ["/usr/local/miniworld/bin/docker_entrypoint"] +ENTRYPOINT ["/usr/local/miniworld/.github/docker/docker_entrypoint"] #RUN cd pytorch-a2c-ppo-acktr #RUN xvfb-run -a -s "-screen 0 1024x768x24 -ac +extension GLX +render -noreset" time python3 main.py --no-cuda --algo a2c --log-interval 1 --num-frames 200 --num-processes 1 --num-steps 80 --lr 0.00005 --env-name MiniWorld-Hallway-v0 diff --git a/.github/stale.yml b/.github/stale.yml index 52d6499f..9df56402 100644 --- a/.github/stale.yml +++ b/.github/stale.yml @@ -59,4 +59,4 @@ only: issues # issues: # exemptLabels: -# - confirmed \ No newline at end of file +# - confirmed diff --git a/.github/workflows/build-docs-dev.yml b/.github/workflows/build-docs-dev.yml index 672201b0..9541b47a 100644 --- a/.github/workflows/build-docs-dev.yml +++ b/.github/workflows/build-docs-dev.yml @@ -15,7 +15,7 @@ jobs: - uses: actions/setup-python@v4 with: - python-version: '3.9' + python-version: '3.11' - name: Install freeglut run: sudo apt-get install -y freeglut3-dev xvfb @@ -49,4 +49,4 @@ jobs: with: folder: _build target-folder: main - clean: false \ No newline at end of file + clean: false diff --git a/.github/workflows/build-docs-version.yml b/.github/workflows/build-docs-version.yml index e776e341..942bc942 100644 --- a/.github/workflows/build-docs-version.yml +++ b/.github/workflows/build-docs-version.yml @@ -16,7 +16,7 @@ jobs: - uses: actions/setup-python@v4 with: - python-version: '3.9' + python-version: '3.11' - name: Get tag id: tag @@ -62,4 +62,4 @@ jobs: folder: _build clean-exclude: | *.*.*/ - main \ No newline at end of file + main diff --git a/.github/workflows/build-publish.yml b/.github/workflows/build-publish.yml index ea03ac18..8949c1fc 100644 --- a/.github/workflows/build-publish.yml +++ b/.github/workflows/build-publish.yml @@ -23,20 +23,11 @@ jobs: - name: Set up Python uses: actions/setup-python@v4 with: - python-version: '3.x' + python-version: '3.11' - name: Install pypa/build - run: >- - python -m - pip install -U - build + run: python -m pip install -U build - name: Build a binary wheel and a source tarball - run: >- - python -m - build - --sdist - --wheel - --outdir dist/ - . + run: python -m build --sdist --wheel --outdir dist/ . - name: Store wheels uses: actions/upload-artifact@v3 with: diff --git a/.github/workflows/manual-build-docs-version.yml b/.github/workflows/manual-build-docs-version.yml index 91134246..6211e88e 100644 --- a/.github/workflows/manual-build-docs-version.yml +++ b/.github/workflows/manual-build-docs-version.yml @@ -31,7 +31,7 @@ jobs: - uses: actions/setup-python@v4 with: - python-version: '3.9' + python-version: '3.11' - name: Install freeglut run: sudo apt-get install -y freeglut3-dev xvfb @@ -74,4 +74,4 @@ jobs: folder: _build clean-exclude: | *.*.*/ - main \ No newline at end of file + main diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 703d7844..5433785e 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -11,4 +11,4 @@ jobs: - run: pip install pre-commit - run: pre-commit --version - run: pre-commit install - - run: pre-commit run --all-files \ No newline at end of file + - run: pre-commit run --all-files diff --git a/.github/workflows/build.yml b/.github/workflows/pytest.yml similarity index 59% rename from .github/workflows/build.yml rename to .github/workflows/pytest.yml index 9b3cf694..967f6ac7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/pytest.yml @@ -2,7 +2,7 @@ name: build on: [pull_request, push] jobs: - build: + build-latest: runs-on: ubuntu-latest strategy: matrix: @@ -10,11 +10,22 @@ jobs: steps: - uses: actions/checkout@v2 - run: | - docker build -f py.Dockerfile \ + docker build -f .github/docker/testing.Dockerfile \ --build-arg PYTHON_VERSION=${{ matrix.python-version }} \ - --tag gym-miniworld-docker . + --tag miniworld-docker . - name: Run tests - run: docker run gym-miniworld-docker pytest + run: docker run miniworld-docker pytest + + build-old: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - run: | + docker build -f .github/docker/testing-old.Dockerfile \ + --build-arg PYTHON_VERSION='3.11' \ + --tag miniworld-docker . + - name: Run tests + run: docker run miniworld-docker pytest # Old Travis testing @@ -22,4 +33,4 @@ jobs: # xvfb-run -a -s "-screen 0 1024x768x24 -ac +extension GLX +render -noreset" ./run_tests.py # # Test RL code quickly -# cd pytorch-a2c-ppo-acktr && xvfb-run -a -s "-screen 0 1024x768x24 -ac +extension GLX +render -noreset" time python3 main.py --no-cuda --algo a2c --log-interval 1 --num-frames 200 --num-processes 1 --num-steps 80 --lr 0.00005 --env-name MiniWorld-Hallway-v0 \ No newline at end of file +# cd pytorch-a2c-ppo-acktr && xvfb-run -a -s "-screen 0 1024x768x24 -ac +extension GLX +render -noreset" time python3 main.py --no-cuda --algo a2c --log-interval 1 --num-frames 200 --num-processes 1 --num-steps 80 --lr 0.00005 --env-name MiniWorld-Hallway-v0 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 595af7f3..2fbe56aa 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,18 +1,34 @@ --- repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v5.0.0 + hooks: + - id: check-symlinks + - id: destroyed-symlinks + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-toml + - id: check-ast + - id: check-added-large-files + - id: check-merge-conflict + - id: check-executables-have-shebangs + - id: check-shebang-scripts-are-executable + - id: detect-private-key + - id: debug-statements - repo: https://github.com/python/black - rev: 23.3.0 + rev: 24.10.0 hooks: - id: black - repo: https://github.com/codespell-project/codespell - rev: v2.2.4 + rev: v2.3.0 hooks: - id: codespell args: - --skip=*.svg # - --ignore-words-list= - repo: https://github.com/PyCQA/flake8 - rev: 6.0.0 + rev: 7.1.1 hooks: - id: flake8 args: @@ -23,7 +39,7 @@ repos: - --show-source - --statistics - repo: https://github.com/PyCQA/isort - rev: 5.12.0 + rev: 5.13.2 hooks: - id: isort args: ["--profile", "black"] @@ -37,10 +53,10 @@ repos: # - --convention=google # additional_dependencies: ["toml"] - repo: https://github.com/asottile/pyupgrade - rev: v3.3.1 + rev: v3.19.1 hooks: - id: pyupgrade - args: ["--py37-plus"] + args: ["--py38-plus"] # - repo: local # hooks: # - id: pyright diff --git a/CODE_OF_CONDUCT.rst b/CODE_OF_CONDUCT.rst index e78793c7..06942265 100644 --- a/CODE_OF_CONDUCT.rst +++ b/CODE_OF_CONDUCT.rst @@ -65,5 +65,3 @@ Attribution ----------- This Code of Conduct is adapted from `Python's Code of Conduct `_, which is under a `Creative Commons License `_. - - diff --git a/README.md b/README.md index ef8a148a..801e687c 100644 --- a/README.md +++ b/README.md @@ -10,9 +10,9 @@ Contents: - [Introduction](#introduction) - [Installation](#installation) - [Usage](#usage) -- [Environments](docs/environments.md) -- [Design and Customization](docs/content/design.md) -- [Troubleshooting](docs/content/troubleshooting.md) +- [Environments](https://miniworld.farama.org/content/env_list/) +- [Design and Customization](https://miniworld.farama.org/content/design/) +- [Troubleshooting](https://miniworld.farama.org/content/troubleshooting/) ## Introduction diff --git a/docs/.gitignore b/docs/.gitignore index f04e39f7..30075925 100644 --- a/docs/.gitignore +++ b/docs/.gitignore @@ -1,2 +1,2 @@ environments/**/*.md -content/env_list.html \ No newline at end of file +content/env_list.html diff --git a/docs/404.md b/docs/404.md index 6c69ef60..d5baf9a5 100644 --- a/docs/404.md +++ b/docs/404.md @@ -1,3 +1,3 @@ # 404 - Page Not Found -## The requested page could not be found. \ No newline at end of file +## The requested page could not be found. diff --git a/docs/_scripts/gen_env_docs.py b/docs/_scripts/gen_env_docs.py index 657d7a64..12bed094 100644 --- a/docs/_scripts/gen_env_docs.py +++ b/docs/_scripts/gen_env_docs.py @@ -3,7 +3,9 @@ import gymnasium as gym -import miniworld # noqa: F401 +import miniworld + +gym.register_envs(miniworld) # From python docs @@ -75,7 +77,6 @@ def trim(docstring): |---|---| | Action Space | `{re.sub(' +', ' ', action_space_table)}` | | Observation Space | `{re.sub(' +', ' ', observation_space_table)}` | -| Reward Range | `{env.reward_range}` | | Creation | `gymnasium.make("{env_spec.id}")` | """ res_env_md += f"{env_attributes}\n" diff --git a/docs/_scripts/gen_envs_display.py b/docs/_scripts/gen_envs_display.py index a880b172..7ec3e4a7 100644 --- a/docs/_scripts/gen_envs_display.py +++ b/docs/_scripts/gen_envs_display.py @@ -2,16 +2,18 @@ import gymnasium as gym -import miniworld # noqa: F401 +import miniworld + +gym.register_envs(miniworld) def create_grid_cell(env_id): env_name = env_id.split("-")[-2] return f""" - +
- +
{env_name} diff --git a/docs/_static/img/miniworld-text.svg b/docs/_static/img/miniworld-text.svg index 176bcadc..ab70b593 100644 --- a/docs/_static/img/miniworld-text.svg +++ b/docs/_static/img/miniworld-text.svg @@ -93,7 +93,7 @@ inkscape:label="Layer 1"> - + - + - + =1.18.0", - "pyglet==1.5.27", - "gymnasium>=0.26.2", + "numpy>=1.22.0", + "pyglet>=1.5.27,<2.0", + "gymnasium>=0.29.1", ], - extras_require={"testing": ["pytest==7.0.1", "torch"]}, + extras_require={"testing": ["pytest>=7.0.1", "torch"]}, # Include textures and meshes in the package include_package_data=True, classifiers=[ diff --git a/tests/test_miniworld.py b/tests/test_miniworld.py old mode 100755 new mode 100644 index f4712e07..04b8578e --- a/tests/test_miniworld.py +++ b/tests/test_miniworld.py @@ -1,4 +1,3 @@ -import importlib import math import pickle import warnings @@ -12,7 +11,7 @@ from miniworld.miniworld import MiniWorldEnv from miniworld.wrappers import PyTorchObsWrapper, StochasticActionWrapper -miniworld_env_ids = [env_id for env_id in gym.envs.registry if "MiniWorld" in env_id] +miniworld_env_ids = [env_id for env_id in gym.registry if "MiniWorld" in env_id] def test_miniworld(): @@ -28,7 +27,7 @@ def test_miniworld(): first_render = env.render() m0 = first_obs.mean() m1 = first_render.mean() - assert m0 > 0 and m0 < 255 + assert 0 < m0 < 255 assert abs(m0 - m1) < 5 # Check that the observation shapes match in reset and step @@ -83,15 +82,15 @@ def _gen_world(self): def test_collision_detection(): # Basic collision detection test # Make sure the agent can never get outside the room - env = gym.make("MiniWorld-OneRoom-v0") + env = gym.make("MiniWorld-OneRoom-v0").env.env for _ in range(30): env.reset() room = env.rooms[0] for _ in range(30): env.step(env.actions.move_forward) x, _, z = env.agent.pos - assert x >= room.min_x and x <= room.max_x - assert z >= room.min_z and z <= room.max_z + assert room.min_x <= x <= room.max_x + assert room.min_z <= z <= room.max_z env.close() @@ -103,12 +102,8 @@ def test_all_envs(env_id): return env = gym.make(env_id) - - spec_entry_point = env.spec.entry_point - mod_name, attr_name = spec_entry_point.split(":") - mode = importlib.import_module(mod_name) - attr = getattr(mode, attr_name) - assert isinstance(attr(), MiniWorldEnv) + assert isinstance(env.unwrapped, MiniWorldEnv) + env = env.env.env env.domain_rand = True # Try multiple random restarts