From 40c70f1bbf6d24292117a2fb0aa928e4db7716ba Mon Sep 17 00:00:00 2001 From: guillemdb Date: Tue, 3 Sep 2024 10:58:52 +0200 Subject: [PATCH] Update MacOS build Signed-off-by: guillemdb --- .github/workflows/push.yml | 582 ++++++++++++----------- .gitignore | 270 +++++------ .readthedocs.yaml | 80 ++-- install-lua-macos.sh | 108 ++--- pyproject.toml | 480 +++++++++---------- requirements-dev.lock | 4 +- requirements.lock | 4 +- src/plangym/scripts/import_retro_roms.py | 176 +++---- src/plangym/version.py | 6 +- 9 files changed, 859 insertions(+), 851 deletions(-) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index bfc8ffd..3522d73 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -1,289 +1,293 @@ -name: Push - -on: - push: - branches: - - master - pull_request: - branches: - - master - -env: - PROJECT_NAME: plangym - PROJECT_DIR: src/plangym - VERSION_FILE: src/plangym/version.py - DEFAULT_BRANCH: master - BOT_NAME: fragile-bot - BOT_EMAIL: bot@fragile.tech - DOCKER_ORG: fragiletech - LOCAL_CACHE: | - ~/.local/bin - ~/.local/lib/python3.*/site-packages - -jobs: - style-check: - name: Style check - if: "!contains(github.event.head_commit.message, 'Bump version')" - runs-on: ubuntu-latest - steps: - - name: actions/checkout - uses: actions/checkout@v3 - - name: Set up Python 3.10 - uses: actions/setup-python@v2 - with: - python-version: "3.10" - - name: Setup Rye - id: setup-rye - uses: eifinger/setup-rye@v4 - with: - enable-cache: true - cache-prefix: ubuntu-20.04-rye-check-${{ hashFiles('pyproject.toml') }} - - - name: Run style check and linter - run: | - set -x - rye fmt --check - rye lint - - pytest: - name: Run Pytest - if: "!contains(github.event.head_commit.message, 'Bump version')" - strategy: - matrix: - python-version: [ '3.10' ] - os: [ 'ubuntu-latest', 'macos-latest' ] - runs-on: ${{ matrix.os }} - steps: - - name: actions/checkout - uses: actions/checkout@v3 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - name: Setup Rye - id: setup-rye - uses: eifinger/setup-rye@v4 - with: - enable-cache: true - cache-prefix: ${{ matrix.os }}-latest-rye-test-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }} - - name: actions/cache - uses: actions/cache@v3 - with: - path: ${{ env.LOCAL_CACHE }} - key: ${{ matrix.os }}-latest-system-test-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }} - restore-keys: ${{ matrix.os }}-latest-system-test-${{ matrix.python-version }} - - - name: Install Ubuntu test and package dependencies - if: ${{ matrix.os == 'ubuntu-latest' }} - run: | - set -x - sudo apt-get install -y xvfb libglu1-mesa - rye pin --relaxed cpython@${{ matrix.python-version }} - rye sync --all-features - ROM_PASSWORD=${{ secrets.ROM_PASSWORD }} rye run import-roms - - - name: Install MacOS test and package dependencies - if: ${{ matrix.os == 'macos-latest' }} - run: | - set -x - brew install --cask xquartz - brew install swig libzip qt5 capnp - chmod +x install-lua-macos.sh - sudo ./install-lua-macos.sh - # https://docs.github.com/en/actions/learn-github-actions/workflow-commands-for-github-actions#adding-a-system-path - echo "/opt/X11/bin" >> $GITHUB_PATH - # https://github.com/ponty/PyVirtualDisplay/issues/42 - if [ ! -d /tmp/.X11-unix ]; then - mkdir /tmp/.X11-unix - fi - sudo chmod 1777 /tmp/.X11-unix - sudo chown root /tmp/.X11-unix - echo 'export PATH="/opt/homebrew/opt/qt@5/bin:$PATH"' >> ~/.zshrc - export SDKROOT=$(xcrun --sdk macosx --show-sdk-path) - rye pin --relaxed cpython@${{ matrix.python-version }} - rye sync --all-features - # rye sync --features=ray,box_2d,atari,classic-control,test - # Fix a bug in retro - sed -i '' 's/VERSION\.txt/VERSION/g' /Users/runner/work/plangym/plangym/.venv/lib/python3.10/site-packages/retro/__init__.py - echo "0.9.1" > /Users/runner/work/plangym/plangym/.venv/lib/python3.10/site-packages/retro/VERSION - ROM_PASSWORD=${{ secrets.ROM_PASSWORD }} rye run import-roms - - - name: Run Pytest on MacOS - if: ${{ matrix.os == 'macos-latest' }} - run: | - set -x - SKIP_RENDER=True rye run pytest tests/control tests/test_core.py - - - name: Run code coverage on Ubuntu - if: ${{ matrix.os == 'ubuntu-latest' }} - run: | - set -x - xvfb-run -s "-screen 0 1400x900x24" rye run codecov - - - name: Upload coverage report - # if: ${{ matrix.python-version == '3.10' && matrix.os == 'ubuntu-latest' }} - if: ${{ matrix.os == 'ubuntu-latest' }} - uses: codecov/codecov-action@v4 - with: - fail_ci_if_error: false # optional (default = false) - files: ./coverage.xml,./coverage_parallel.xml - flags: unittests # optional - name: codecov-umbrella # optional - token: ${{ secrets.CODECOV_TOKEN }} # required - verbose: true # optional (default = false) - -# test-docker: -# name: Test Docker container -# runs-on: ubuntu-20.04 -# if: "!contains(github.event.head_commit.message, 'Bump version')" -# steps: -# - uses: actions/checkout@v2 -# - name: Build container -# run: | -# set -x -# ROM_PASSWORD=${{ secrets.ROM_PASSWORD }} make docker-build -# - name: Run tests -# run: | -# set -x -# make docker-test - - build-test-package: - name: Build and test the package - needs: style-check - runs-on: ubuntu-latest - if: "!contains(github.event.head_commit.message, 'Bump version')" - steps: - - name: actions/checkout - uses: actions/checkout@v3 - - name: Set up Python 3.10 - uses: actions/setup-python@v2 - with: - python-version: '3.10' - - name: Setup Rye - id: setup-rye - uses: eifinger/setup-rye@v4 - with: - enable-cache: true - cache-prefix: ubuntu-latest-rye-build-3.10-${{ hashFiles('pyproject.toml') }} - - name: actions/cache - uses: actions/cache@v3 - with: - path: ${{ env.LOCAL_CACHE }} - key: ubuntu-latest-system-build-3.10-${{ hashFiles('pyproject.toml') }} - restore-keys: ubuntu-latest-system-test - - name: Install build dependencies - run: | - set -x - pip install uv - rye install bump2version - rye install twine - - - name: Create unique version for test.pypi - run: | - set -x - current_version=$(grep __version__ $VERSION_FILE | cut -d\" -f2) - ts=$(date +%s) - new_version="$current_version$ts" - bumpversion --current-version $current_version --new-version $new_version patch $VERSION_FILE - - - name: Build package - run: | - set -x - rye build --clean - twine check dist/* - -# - name: Publish package to TestPyPI -# env: -# TEST_PYPI_PASS: ${{ secrets.TEST_PYPI_PASS }} -# if: "'$TEST_PYPI_PASS' != ''" -# uses: pypa/gh-action-pypi-publish@release/v1 -# with: -# password: ${{ secrets.TEST_PYPI_PASS }} -# repository-url: https://test.pypi.org/legacy/ -# skip-existing: true - - - name: Install dependencies - env: - UV_SYSTEM_PYTHON: 1 - run: | - set -x - sudo apt-get install -y xvfb - sudo MUJOCO_PATH=/home/runner/.mujoco/ make install-envs - rye lock --all-features - uv pip install -r requirements.lock - uv pip install dist/*.whl -# ROM_PASSWORD=${{ secrets.ROM_PASSWORD }} python -m plangym.scripts.import_retro_roms - -# - name: Test package -# env: -# UV_SYSTEM_PYTHON: 1 -# run: | -# set -x -# rm -rf $PROJECT_DIR -# find . -name "*.pyc" -delete -# make test - - bump-version: - name: Bump package version - env: - BOT_AUTH_TOKEN: ${{ secrets.BOT_AUTH_TOKEN }} - if: "!contains(github.event.head_commit.message, 'Bump version') && github.ref == 'refs/heads/master' && '$BOT_AUTH_TOKEN' != ''" - runs-on: ubuntu-latest - needs: - - pytest - - build-test-package - # - test-docker - steps: - - name: actions/checkout - uses: actions/checkout@v3 - with: - persist-credentials: false - fetch-depth: 100 - - name: current_version - run: | - set -x - echo "current_version=$(grep __version__ $VERSION_FILE | cut -d\" -f2)" >> $GITHUB_ENV - echo "version_file=$VERSION_FILE" >> $GITHUB_ENV - echo 'bot_name="${BOT_NAME}"' >> $GITHUB_ENV - echo 'bot_email="${BOT_EMAIL}"' >> $GITHUB_ENV - - name: FragileTech/bump-version - uses: FragileTech/bump-version@main - with: - current_version: "${{ env.current_version }}" - files: "${{ env.version_file }}" - commit_name: "${{ env.bot_name }}" - commit_email: "${{ env.bot_email }}" - login: "${{ env.bot_name }}" - token: "${{ secrets.BOT_AUTH_TOKEN }}" - -# release-package: -# name: Release PyPI package -# env: -# PYPI_PASS: ${{ secrets.PYPI_PASS }} -# if: "contains(github.event.head_commit.message, 'Bump version') && github.ref == 'refs/heads/master' && '$PYPI_PASS' != ''" -# runs-on: ubuntu-20.04 -# steps: -# - name: actions/checkout -# uses: actions/checkout@v3 -# - name: Set up Python 3.8 -# uses: actions/setup-python@v3 -# with: -# python-version: 3.8 -# - name: Install dependencies -# run: | -# set -x -# python -m pip install -U pip -# python -m pip install -U setuptools twine wheel -# -# - name: Build package -# run: | -# set -x -# python setup.py --version -# python setup.py bdist_wheel sdist --format=gztar -# twine check dist/* -# -# - name: Publish package to PyPI -# uses: pypa/gh-action-pypi-publish@master -# with: -# user: __token__ -# password: ${{ secrets.PYPI_PASS }} +name: Push + +on: + push: + branches: + - master + pull_request: + branches: + - master + +env: + PROJECT_NAME: plangym + PROJECT_DIR: src/plangym + VERSION_FILE: src/plangym/version.py + DEFAULT_BRANCH: master + BOT_NAME: fragile-bot + BOT_EMAIL: bot@fragile.tech + DOCKER_ORG: fragiletech + LOCAL_CACHE: | + ~/.local/bin + ~/.local/lib/python3.*/site-packages + +jobs: + style-check: + name: Style check + if: "!contains(github.event.head_commit.message, 'Bump version')" + runs-on: ubuntu-latest + steps: + - name: actions/checkout + uses: actions/checkout@v3 + - name: Set up Python 3.10 + uses: actions/setup-python@v2 + with: + python-version: "3.10" + - name: Setup Rye + id: setup-rye + uses: eifinger/setup-rye@v4 + with: + enable-cache: true + cache-prefix: ubuntu-20.04-rye-check-${{ hashFiles('pyproject.toml') }} + + - name: Run style check and linter + run: | + set -x + rye fmt --check + rye lint + + pytest: + name: Run Pytest + if: "!contains(github.event.head_commit.message, 'Bump version')" + strategy: + matrix: + python-version: [ '3.10' ] + os: [ 'ubuntu-latest', 'macos-latest' ] + runs-on: ${{ matrix.os }} + steps: + - name: actions/checkout + uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Setup Rye + id: setup-rye + uses: eifinger/setup-rye@v4 + with: + enable-cache: true + cache-prefix: ${{ matrix.os }}-latest-rye-test-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }} + - name: actions/cache + uses: actions/cache@v3 + with: + path: ${{ env.LOCAL_CACHE }} + key: ${{ matrix.os }}-latest-system-test-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }} + restore-keys: ${{ matrix.os }}-latest-system-test-${{ matrix.python-version }} + + - name: Install Ubuntu test and package dependencies + if: ${{ matrix.os == 'ubuntu-latest' }} + run: | + set -x + sudo apt-get install -y xvfb libglu1-mesa + rye pin --relaxed cpython@${{ matrix.python-version }} + rye sync --all-features + ROM_PASSWORD=${{ secrets.ROM_PASSWORD }} rye run import-roms + + - name: Install MacOS test and package dependencies + if: ${{ matrix.os == 'macos-latest' }} + run: | + set -x + brew install --cask xquartz + brew install swig libzip qt5 capnp + # When building retro from source we may need the deprecated version of lua 5.1. + # Retro does not build in MacOS due to ancient requirements, so we will be installing retro==0.9.1 from pypi + # because it contains pre-build wheels for MacOS. + # chmod +x install-lua-macos.sh + # sudo ./install-lua-macos.sh + # https://docs.github.com/en/actions/learn-github-actions/workflow-commands-for-github-actions#adding-a-system-path + echo "/opt/X11/bin" >> $GITHUB_PATH + # https://github.com/ponty/PyVirtualDisplay/issues/42 + if [ ! -d /tmp/.X11-unix ]; then + mkdir /tmp/.X11-unix + fi + sudo chmod 1777 /tmp/.X11-unix + sudo chown root /tmp/.X11-unix + echo 'export PATH="/opt/homebrew/opt/qt@5/bin:$PATH"' >> ~/.zshrc + export SDKROOT=$(xcrun --sdk macosx --show-sdk-path) + rye pin --relaxed cpython@${{ matrix.python-version }} + rye sync --all-features + # Fix a bug in retro.data where it tries to load an inexistent version file + # sed -i '' 's/VERSION\.txt/VERSION/g' /Users/runner/work/plangym/plangym/.venv/lib/python3.10/site-packages/retro/__init__.py + if [ ! -d /Users/runner/work/plangym/plangym/.venv/lib/python3.10/site-packages/retro/VERSION ]; then + echo "0.9.1" > /Users/runner/work/plangym/plangym/.venv/lib/python3.10/site-packages/retro/VERSION + fi + ROM_PASSWORD=${{ secrets.ROM_PASSWORD }} rye run import-roms + + - name: Run Pytest on MacOS + if: ${{ matrix.os == 'macos-latest' }} + run: | + set -x + SKIP_RENDER=True rye run pytest tests/control tests/videogames tests/test_core.py + + - name: Run code coverage on Ubuntu + if: ${{ matrix.os == 'ubuntu-latest' }} + run: | + set -x + xvfb-run -s "-screen 0 1400x900x24" rye run codecov + + - name: Upload coverage report + # if: ${{ matrix.python-version == '3.10' && matrix.os == 'ubuntu-latest' }} + if: ${{ matrix.os == 'ubuntu-latest' }} + uses: codecov/codecov-action@v4 + with: + fail_ci_if_error: false # optional (default = false) + files: ./coverage.xml,./coverage_parallel.xml + flags: unittests # optional + name: codecov-umbrella # optional + token: ${{ secrets.CODECOV_TOKEN }} # required + verbose: true # optional (default = false) + +# test-docker: +# name: Test Docker container +# runs-on: ubuntu-20.04 +# if: "!contains(github.event.head_commit.message, 'Bump version')" +# steps: +# - uses: actions/checkout@v2 +# - name: Build container +# run: | +# set -x +# ROM_PASSWORD=${{ secrets.ROM_PASSWORD }} make docker-build +# - name: Run tests +# run: | +# set -x +# make docker-test + + build-test-package: + name: Build and test the package + needs: style-check + runs-on: ubuntu-latest + if: "!contains(github.event.head_commit.message, 'Bump version')" + steps: + - name: actions/checkout + uses: actions/checkout@v3 + - name: Set up Python 3.10 + uses: actions/setup-python@v2 + with: + python-version: '3.10' + - name: Setup Rye + id: setup-rye + uses: eifinger/setup-rye@v4 + with: + enable-cache: true + cache-prefix: ubuntu-latest-rye-build-3.10-${{ hashFiles('pyproject.toml') }} + - name: actions/cache + uses: actions/cache@v3 + with: + path: ${{ env.LOCAL_CACHE }} + key: ubuntu-latest-system-build-3.10-${{ hashFiles('pyproject.toml') }} + restore-keys: ubuntu-latest-system-test + - name: Install build dependencies + run: | + set -x + pip install uv + rye install bump2version + rye install twine + + - name: Create unique version for test.pypi + run: | + set -x + current_version=$(grep __version__ $VERSION_FILE | cut -d\" -f2) + ts=$(date +%s) + new_version="$current_version$ts" + bumpversion --current-version $current_version --new-version $new_version patch $VERSION_FILE + + - name: Build package + run: | + set -x + rye build --clean + twine check dist/* + + - name: Publish package to TestPyPI + env: + TEST_PYPI_PASS: ${{ secrets.TEST_PYPI_PASS }} + if: "'$TEST_PYPI_PASS' != ''" + uses: pypa/gh-action-pypi-publish@release/v1 + with: + password: ${{ secrets.TEST_PYPI_PASS }} + repository-url: https://test.pypi.org/legacy/ + skip-existing: true + + - name: Install dependencies + env: + UV_SYSTEM_PYTHON: 1 + run: | + set -x + sudo apt-get install -y xvfb + sudo MUJOCO_PATH=/home/runner/.mujoco/ make install-envs + rye lock --all-features + uv pip install -r requirements.lock + uv pip install dist/*.whl +# ROM_PASSWORD=${{ secrets.ROM_PASSWORD }} python -m plangym.scripts.import_retro_roms + +# - name: Test package +# env: +# UV_SYSTEM_PYTHON: 1 +# run: | +# set -x +# rm -rf $PROJECT_DIR +# find . -name "*.pyc" -delete +# make test + + bump-version: + name: Bump package version + env: + BOT_AUTH_TOKEN: ${{ secrets.BOT_AUTH_TOKEN }} + if: "!contains(github.event.head_commit.message, 'Bump version') && github.ref == 'refs/heads/master' && '$BOT_AUTH_TOKEN' != ''" + runs-on: ubuntu-latest + needs: + - pytest + - build-test-package + # - test-docker + steps: + - name: actions/checkout + uses: actions/checkout@v3 + with: + persist-credentials: false + fetch-depth: 100 + - name: current_version + run: | + set -x + echo "current_version=$(grep __version__ $VERSION_FILE | cut -d\" -f2)" >> $GITHUB_ENV + echo "version_file=$VERSION_FILE" >> $GITHUB_ENV + echo 'bot_name="${BOT_NAME}"' >> $GITHUB_ENV + echo 'bot_email="${BOT_EMAIL}"' >> $GITHUB_ENV + - name: FragileTech/bump-version + uses: FragileTech/bump-version@main + with: + current_version: "${{ env.current_version }}" + files: "${{ env.version_file }}" + commit_name: "${{ env.bot_name }}" + commit_email: "${{ env.bot_email }}" + login: "${{ env.bot_name }}" + token: "${{ secrets.BOT_AUTH_TOKEN }}" + +# release-package: +# name: Release PyPI package +# env: +# PYPI_PASS: ${{ secrets.PYPI_PASS }} +# if: "contains(github.event.head_commit.message, 'Bump version') && github.ref == 'refs/heads/master' && '$PYPI_PASS' != ''" +# runs-on: ubuntu-20.04 +# steps: +# - name: actions/checkout +# uses: actions/checkout@v3 +# - name: Set up Python 3.8 +# uses: actions/setup-python@v3 +# with: +# python-version: 3.8 +# - name: Install dependencies +# run: | +# set -x +# python -m pip install -U pip +# python -m pip install -U setuptools twine wheel +# +# - name: Build package +# run: | +# set -x +# python setup.py --version +# python setup.py bdist_wheel sdist --format=gztar +# twine check dist/* +# +# - name: Publish package to PyPI +# uses: pypa/gh-action-pypi-publish@master +# with: +# user: __token__ +# password: ${{ secrets.PYPI_PASS }} diff --git a/.gitignore b/.gitignore index 3f67a48..b25c933 100644 --- a/.gitignore +++ b/.gitignore @@ -1,135 +1,135 @@ -gym_api.py -roms -uncompressed ROMs.zip -uncompressed ROMs -# This file is here just for the reference -WHAT_MLOQ_GENERATED.md - -#Mac OS -*.DS_Store - -#PyCharm IDE -.idea/ - -# Documentation build templates -docs/_build/ -docs/build/ - -# Byte-compiled / optimized / DLL templates -__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -env/ -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -wheels/ -pip-wheel-metadata -*.egg-info/ -.installed.cfg -*.egg - -# PyInstaller -# Usually these templates are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -coverage_parallel.xml -*.cover -.hypothesis/ - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docsrc/_build/ - -# PyBuilder -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# pyenv -.python-version - -# celery beat schedule file -celerybeat-schedule - -# SageMath parsed templates -*.sage.py - -# dotenv -.env - -# virtualenv -.venv -venv/ -ENV/ - -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ - -# CI -.ci - -# Notebooks by default are ignored -*.ipynb - -# lock files -*.lock - -# hydra command history -outputs/ - -*.pck -*.npy +gym_api.py +roms +uncompressed ROMs.zip +uncompressed ROMs +# This file is here just for the reference +WHAT_MLOQ_GENERATED.md + +#Mac OS +*.DS_Store + +#PyCharm IDE +.idea/ + +# Documentation build templates +docs/_build/ +docs/build/ + +# Byte-compiled / optimized / DLL templates +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these templates are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +coverage_parallel.xml +*.cover +.hypothesis/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docsrc/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed templates +*.sage.py + +# dotenv +.env + +# virtualenv +.venv +venv/ +ENV/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ + +# CI +.ci + +# Notebooks by default are ignored +*.ipynb + +# lock files +*.lock + +# hydra command history +outputs/ + +*.pck +*.npy diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 7aa6eb8..f516010 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -1,41 +1,41 @@ -# Read the Docs configuration file for Sphinx projects -# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details - -# Required -version: 2 - -# Set the OS, Python version and other tools you might need -build: - os: ubuntu-22.04 - tools: - python: "3.10" - # You can also specify other tool versions: - # nodejs: "20" - # rust: "1.70" - # golang: "1.20" - apt_packages: - - build-essential - - libglu1-mesa - - xvfb - - clang - - swig - -# Build documentation in the "docs/" directory with Sphinx -sphinx: - configuration: docs/source/conf.py - # You can configure Sphinx to use a different builder, for instance use the dirhtml builder for simpler URLs - # builder: "dirhtml" - # Fail on all warnings to avoid broken references - # fail_on_warning: true - -# Optionally build your docs in additional formats such as PDF and ePub -# formats: -# - pdf -# - epub - -# Optional but recommended, declare the Python requirements required -# to build your documentation -# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html -python: - install: +# Read the Docs configuration file for Sphinx projects +# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details + +# Required +version: 2 + +# Set the OS, Python version and other tools you might need +build: + os: ubuntu-22.04 + tools: + python: "3.10" + # You can also specify other tool versions: + # nodejs: "20" + # rust: "1.70" + # golang: "1.20" + apt_packages: + - build-essential + - libglu1-mesa + - xvfb + - clang + - swig + +# Build documentation in the "docs/" directory with Sphinx +sphinx: + configuration: docs/source/conf.py + # You can configure Sphinx to use a different builder, for instance use the dirhtml builder for simpler URLs + # builder: "dirhtml" + # Fail on all warnings to avoid broken references + # fail_on_warning: true + +# Optionally build your docs in additional formats such as PDF and ePub +# formats: +# - pdf +# - epub + +# Optional but recommended, declare the Python requirements required +# to build your documentation +# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html +python: + install: - requirements: requirements.lock \ No newline at end of file diff --git a/install-lua-macos.sh b/install-lua-macos.sh index 0d381ab..97cacb5 100644 --- a/install-lua-macos.sh +++ b/install-lua-macos.sh @@ -1,55 +1,55 @@ -#!/bin/bash - -# This scripts installs Lua, LuaRocks, and some Lua libraries on macOS. -# The main purpose is to install Busted for testing Neovim plugins. -# After the installation, you will be able to run test using busted: -# busted --lua nlua spec/mytest_spec.lua - -################################################################################ -# Dependencies -################################################################################ - -xcode-select --install - -# Lua Directory: where Lua and Luarocks will be installed -# You can change installation location by changing this variable -LUA_DIR="$HOME/Developer/lua" - -mkdir -p $LUA_DIR - -################################################################################ -# Lua -################################################################################ - -# Download and Extract Lua Sources -cd /tmp -rm -rf lua-5.1.5.* -wget https://www.lua.org/ftp/lua-5.1.5.tar.gz -LUA_SHA='2640fc56a795f29d28ef15e13c34a47e223960b0240e8cb0a82d9b0738695333' -shasum -a 256 lua-5.1.5.tar.gz | grep -q $LUA_SHA && echo "Hash matches" || echo "Hash don't match" -tar xvf lua-5.1.5.tar.gz -cd lua-5.1.5/ - -# Modify Makefile to set destination dir -sed -i '' "s#/usr/local#${LUA_DIR}/#g" Makefile - -# Compile and install Lua -make macosx -make test && make install - -# Export PATHs -export PATH="$PATH:$LUA_DIR/bin" -export LUA_CPATH="$LUA_DIR/lib/lua/5.1/?.so" -export LUA_PATH="$LUA_DIR/share/lua/5.1/?.lua;;" -export MANPATH="$LUA_DIR/share/man:$MANPATH" - -# Verify Lua Installation -which lua -echo "Expected Output:" -echo " ${LUA_DIR}/bin/lua" -lua -v -echo 'Expected Output:' -echo ' Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio' -file ${LUA_DIR}/bin/lua -echo "Expected Output (on Apple Silicon):" +#!/bin/bash + +# This scripts installs Lua, LuaRocks, and some Lua libraries on macOS. +# The main purpose is to install Busted for testing Neovim plugins. +# After the installation, you will be able to run test using busted: +# busted --lua nlua spec/mytest_spec.lua + +################################################################################ +# Dependencies +################################################################################ + +xcode-select --install + +# Lua Directory: where Lua and Luarocks will be installed +# You can change installation location by changing this variable +LUA_DIR="$HOME/Developer/lua" + +mkdir -p $LUA_DIR + +################################################################################ +# Lua +################################################################################ + +# Download and Extract Lua Sources +cd /tmp +rm -rf lua-5.1.5.* +wget https://www.lua.org/ftp/lua-5.1.5.tar.gz +LUA_SHA='2640fc56a795f29d28ef15e13c34a47e223960b0240e8cb0a82d9b0738695333' +shasum -a 256 lua-5.1.5.tar.gz | grep -q $LUA_SHA && echo "Hash matches" || echo "Hash don't match" +tar xvf lua-5.1.5.tar.gz +cd lua-5.1.5/ + +# Modify Makefile to set destination dir +sed -i '' "s#/usr/local#${LUA_DIR}/#g" Makefile + +# Compile and install Lua +make macosx +make test && make install + +# Export PATHs +export PATH="$PATH:$LUA_DIR/bin" +export LUA_CPATH="$LUA_DIR/lib/lua/5.1/?.so" +export LUA_PATH="$LUA_DIR/share/lua/5.1/?.lua;;" +export MANPATH="$LUA_DIR/share/man:$MANPATH" + +# Verify Lua Installation +which lua +echo "Expected Output:" +echo " ${LUA_DIR}/bin/lua" +lua -v +echo 'Expected Output:' +echo ' Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio' +file ${LUA_DIR}/bin/lua +echo "Expected Output (on Apple Silicon):" echo " ${LUA_DIR}/bin/lua: Mach-O 64-bit executable arm64" \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 2146178..bffe9ea 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,240 +1,240 @@ -[project] -name = "plangym" -dynamic = ["version"] -description = "Plangym is an interface to use gymnasium for planning problems. It extends the standard interface to allow setting and recovering the environment states." -authors = [{ name = "Guillem Duran Ballester", email = "guillem@fragile.tech" }] -maintainers = [{ name = "Guillem Duran Ballester", email = "guillem@fragile.tech" }] -license = {file = "LICENSE"} -readme = "README.md" -requires-python = ">=3.10" -packages = [{ include = "plangym", from = "src" }] -include = ["tests/**/*", "tests/**/.*"] -homepage = "https://github.com/FragileTech/plangym" -repository = "https://github.com/FragileTech/plangym" -documentation = "https://github.com/FragileTech/plangym" -keywords = ["RL", "gymnasium", "planning", "plangym"] -classifiers = [ - "Development Status :: 3 - Alpha", - "Intended Audience :: Developers", - "License :: OSI Approved :: MIT License", - "Programming Language :: Python :: 3.10", - "Topic :: Software Development :: Libraries", - ] -dependencies = [ - "numpy", - "pillow", - "fragile-gym", - "opencv-python>=4.10.0.84", - "pyglet==1.5.11", - "pyvirtualdisplay>=3.0", - "imageio>=2.35.1", - "flogging>=0.0.22", -] -[project.optional-dependencies] -atari = ["ale-py", "gymnasium[accept-rom-license,atari]>=0.29.1, == 0.*"] -nes = [ - "fragile-gym[accept-rom-license]", - "fragile-nes-py>=10.0.1", # Requires clang, build-essential - "fragile-gym-super-mario-bros", -] -classic-control = ["gymnasium[classic_control]>=0.29.1, == 0.*", "pygame>=2.6.0"] -ray = ["ray>=2.35.0"] -dm_control = ["mujoco>=3.2.2", "dm-control>=1.0.22"] -retro = [ - "stable-retro==0.9.2; sys_platform != 'darwin'", - "stable-retro==0.9.1; sys_platform == 'darwin'" -] -jupyter = ["jupyterlab>=3.2.0"] -box_2d = ["box2d-py==2.3.5"] -test = [ - "psutil>=5.8.0", - "pytest>=6.2.5", - "pytest-cov>=3.0.0", - "pytest-xdist>=2.4.0", - "pytest-rerunfailures>=10.2", - "pyvirtualdisplay>=1.3.2", - "tomli>=1.2.3", - "hypothesis>=6.24.6" -] -docs = [ - "sphinx", - "linkify-it-py", - "myst-parser", - "myst-nb", - "ruyaml", - "sphinx-autoapi", - "pydata-sphinx-theme", - "sphinx-autodoc2", - "sphinxcontrib-mermaid", - "sphinx_book_theme", - "sphinx_rtd_theme", - "jupyter-cache", - "sphinx-copybutton", - "sphinx-togglebutton", - "sphinxext-opengraph", - "sphinxcontrib-bibtex", -] - -[build-system] -requires = ["hatchling"] -build-backend = "hatchling.build" -[tool.hatch.metadata] -allow-direct-references = true -[tool.hatch.version] -path = "src/plangym/version.py" - -[tool.rye] -dev-dependencies = ["ruff"] -#excluded-dependencies = ["gym"] -universal = true - -[tool.rye.scripts] -style = { chain = ["ruff check --fix-only --unsafe-fixes tests src", "ruff format tests src"] } -check = { chain = ["ruff check --diff tests src", "ruff format --diff tests src"]} #,"mypy src tests" ] } -test = { chain = ["test:doctest", "test:parallel", "test:singlecore"] } -codecov = { chain = ["codecov:singlecore", "codecov:parallel"] } -import-roms = { cmd = "python3 src/plangym/scripts/import_retro_roms.py" } -"test:parallel" = { cmd = "pytest -n auto -s -o log_cli=true -o log_cli_level=info tests", env-file = ".multicore.env" } -"test:singlecore" = { cmd = "pytest -s -o log_cli=true -o log_cli_level=info tests/control/test_classic_control.py", env-file = ".onecore.env" } -"test:doctest" = { cmd = "pytest --doctest-modules -n 0 -s -o log_cli=true -o log_cli_level=info src", env-file = ".multicore.env" } -"codecov:parallel" = { cmd = "pytest -n auto -s -o log_cli=true -o log_cli_level=info --cov=./ --cov-report=xml:coverage_parallel.xml --cov-config=pyproject.toml tests", env-file = ".multicore.env" } -"codecov:singlecore" = { cmd = "pytest --doctest-modules -s -o log_cli=true -o log_cli_level=info --cov=./ --cov-report=xml --cov-config=pyproject.toml tests/control/test_classic_control.py", env-file = ".onecore.env" } -docs = {chain = ["build-docs", "serve-docs"]} -build-docs = { cmd = "sphinx-build -b html docs/source docs/build"} -serve-docs = { cmd = "python3 -m http.server --directory docs/build" } - -[tool.ruff] -# Assume Python 3.10 -target-version = "py310" -preview = true -include = ["*.py", "*.pyi", "**/pyproject.toml"]#, "*.ipynb"] -# Exclude a variety of commonly ignored directories. -exclude = [ - ".bzr", - ".direnv", - ".eggs", - ".git", - ".git-rewrite", - ".hg", - ".mypy_cache", - ".nox", - ".pants.d", - ".pytype", - ".ruff_cache", - ".svn", - ".tox", - ".venv", - ".idea", - "__pypackages__", - "_build", - "buck-out", - "build", - "dist", - "node_modules", - "output", - "venv", - "experimental", - ".pytest_cache", - "**/.ipynb_checkpoints/**", - "**/proto/**", - "data", - "config", -] -# Same as Black. -line-length = 99 -[tool.ruff.lint] -# Allow unused variables when underscore-prefixed. -dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" -select = [ - "ARG", "C4", "D", "E", "EM", "F", "FBT", - "FLY", "FIX", "FURB", "N", "NPY", - "INP", "ISC", "PERF", "PIE", "PL", - "PTH", "RET", "RUF", "S", "T10", - "TD", "T20", "UP", "YTT", "W", -] -ignore = [ - "D100", "D211", "D213", "D104", "D203", "D301", "D407", "S101", - "FBT001", "FBT002", "FIX002", "ISC001", "PLR0913", "RUF012", "TD003", - "PTH123", "PLR6301", "PLR0917", "S311", "S403", "PLR0914", "PLR0915", "S608", - "EM102", "PTH111", "FIX004", "UP035", "PLW2901", "S318", "S408", 'S405', - 'E902', "TD001", "TD002", "FIX001", -] -# Allow autofix for all enabled rules (when `--fix`) is provided. -fixable = ["ALL"] -unfixable = ["I"] - -[tool.ruff.lint.flake8-quotes] -docstring-quotes = "double" - -[tool.ruff.lint.per-file-ignores] -"__init__.py" = ["E402", "F401"] -"cli.py" = ["PLC0415", "D205", "D400", "D415"] -"core.py" = ["ARG002", "PLR0904"] -"_old_core.py" = ["ALL"] -"lunar_lander.py" = ["PLR2004", "FBT003", "N806"] -"api_tests.py" = ["D", "ARG002", "PLW1508", "FBT003", "PLR2004"] -"montezuma.py" = ["PLR2004", "S101", "ARG002", "TD002"] -"registry.py" = ["PLC0415", "PLR0911"] -"**/docs/**" = ["INP001", "PTH100"] -"**/super_mario_gym/**" = ["ALL"] -"**/{tests,docs,tools}/*" = [ - "E402", "F401", "F811", "D", "S101", "PLR2004", "S105", - "PLW1514", "PTH123", "PTH107", "N811", "PLC0415", "ARG002", -] -# Enable reformatting of code snippets in docstrings. -[tool.ruff.format] -docstring-code-line-length = 80 -docstring-code-format = true -indent-style = "space" -line-ending = "auto" -preview = true -quote-style = "double" - -[tool.mypy] -exclude = ["experimental.*", "deprecated.*"] -ignore_missing_imports = true - -# isort orders and lints imports -[tool.isort] -profile = "black" -line_length = 99 -multi_line_output = 3 -order_by_type = false -force_alphabetical_sort_within_sections = true -force_sort_within_sections = true -combine_as_imports = true -include_trailing_comma = true -color_output = true -lines_after_imports = 2 -honor_noqa = true -skip = ["venv", ".venv"] -skip_glob = ["*.pyx"] - -[tool.pylint.master] -ignore = 'tests' -load-plugins =' pylint.extensions.docparams' - -[tool.pylint.messages_control] -disable = 'all,' -enable = """, - missing-param-doc, - differing-param-doc, - differing-type-doc, - missing-return-doc, - """ - -[tool.pytest.ini_options] -# To disable a specific warning --> action:message:category:module:line -filterwarnings = ["ignore::UserWarning", 'ignore::DeprecationWarning'] -addopts = "--ignore=scripts --doctest-continue-on-failure" - -# Code coverage config -[tool.coverage.run] -branch = true - -[tool.coverage.report] -exclude_lines =["no cover", - 'raise NotImplementedError', - 'if __name__ == "__main__":'] -ignore_errors = true -omit = ["tests/*"] +[project] +name = "plangym" +dynamic = ["version"] +description = "Plangym is an interface to use gymnasium for planning problems. It extends the standard interface to allow setting and recovering the environment states." +authors = [{ name = "Guillem Duran Ballester", email = "guillem@fragile.tech" }] +maintainers = [{ name = "Guillem Duran Ballester", email = "guillem@fragile.tech" }] +license = {file = "LICENSE"} +readme = "README.md" +requires-python = ">=3.10" +packages = [{ include = "plangym", from = "src" }] +include = ["tests/**/*", "tests/**/.*"] +homepage = "https://github.com/FragileTech/plangym" +repository = "https://github.com/FragileTech/plangym" +documentation = "https://github.com/FragileTech/plangym" +keywords = ["RL", "gymnasium", "planning", "plangym"] +classifiers = [ + "Development Status :: 3 - Alpha", + "Intended Audience :: Developers", + "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 3.10", + "Topic :: Software Development :: Libraries", + ] +dependencies = [ + "numpy", + "pillow", + "fragile-gym", + "opencv-python>=4.10.0.84", + "pyglet==1.5.11", + "pyvirtualdisplay>=3.0", + "imageio>=2.35.1", + "flogging>=0.0.22", +] +[project.optional-dependencies] +atari = ["ale-py", "gymnasium[accept-rom-license,atari]>=0.29.1, == 0.*"] +nes = [ + "fragile-gym[accept-rom-license]", + "fragile-nes-py>=10.0.1", # Requires clang, build-essential + "fragile-gym-super-mario-bros", +] +classic-control = ["gymnasium[classic_control]>=0.29.1, == 0.*", "pygame>=2.6.0"] +ray = ["ray>=2.35.0"] +dm_control = ["mujoco>=3.2.2", "dm-control>=1.0.22"] +retro = [ + "stable-retro==0.9.2; sys_platform != 'darwin'", + "stable-retro==0.9.1; sys_platform == 'darwin'" +] +jupyter = ["jupyterlab>=3.2.0"] +box_2d = ["box2d-py==2.3.5"] +test = [ + "psutil>=5.8.0", + "pytest>=6.2.5", + "pytest-cov>=3.0.0", + "pytest-xdist>=2.4.0", + "pytest-rerunfailures>=10.2", + "pyvirtualdisplay>=1.3.2", + "tomli>=1.2.3", + "hypothesis>=6.24.6" +] +docs = [ + "sphinx", + "linkify-it-py", + "myst-parser", + "myst-nb", + "ruyaml", + "sphinx-autoapi", + "pydata-sphinx-theme", + "sphinx-autodoc2", + "sphinxcontrib-mermaid", + "sphinx_book_theme", + "sphinx_rtd_theme", + "jupyter-cache", + "sphinx-copybutton", + "sphinx-togglebutton", + "sphinxext-opengraph", + "sphinxcontrib-bibtex", +] + +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" +[tool.hatch.metadata] +allow-direct-references = true +[tool.hatch.version] +path = "src/plangym/version.py" + +[tool.rye] +dev-dependencies = ["ruff"] +#excluded-dependencies = ["gym"] +universal = true + +[tool.rye.scripts] +style = { chain = ["ruff check --fix-only --unsafe-fixes tests src", "ruff format tests src"] } +check = { chain = ["ruff check --diff tests src", "ruff format --diff tests src"]} #,"mypy src tests" ] } +test = { chain = ["test:doctest", "test:parallel", "test:singlecore"] } +codecov = { chain = ["codecov:singlecore", "codecov:parallel"] } +import-roms = { cmd = "python3 src/plangym/scripts/import_retro_roms.py" } +"test:parallel" = { cmd = "pytest -n auto -s -o log_cli=true -o log_cli_level=info tests", env-file = ".multicore.env" } +"test:singlecore" = { cmd = "pytest -s -o log_cli=true -o log_cli_level=info tests/control/test_classic_control.py", env-file = ".onecore.env" } +"test:doctest" = { cmd = "pytest --doctest-modules -n 0 -s -o log_cli=true -o log_cli_level=info src", env-file = ".multicore.env" } +"codecov:parallel" = { cmd = "pytest -n auto -s -o log_cli=true -o log_cli_level=info --cov=./ --cov-report=xml:coverage_parallel.xml --cov-config=pyproject.toml tests", env-file = ".multicore.env" } +"codecov:singlecore" = { cmd = "pytest --doctest-modules -s -o log_cli=true -o log_cli_level=info --cov=./ --cov-report=xml --cov-config=pyproject.toml tests/control/test_classic_control.py", env-file = ".onecore.env" } +docs = {chain = ["build-docs", "serve-docs"]} +build-docs = { cmd = "sphinx-build -b html docs/source docs/build"} +serve-docs = { cmd = "python3 -m http.server --directory docs/build" } + +[tool.ruff] +# Assume Python 3.10 +target-version = "py310" +preview = true +include = ["*.py", "*.pyi", "**/pyproject.toml"]#, "*.ipynb"] +# Exclude a variety of commonly ignored directories. +exclude = [ + ".bzr", + ".direnv", + ".eggs", + ".git", + ".git-rewrite", + ".hg", + ".mypy_cache", + ".nox", + ".pants.d", + ".pytype", + ".ruff_cache", + ".svn", + ".tox", + ".venv", + ".idea", + "__pypackages__", + "_build", + "buck-out", + "build", + "dist", + "node_modules", + "output", + "venv", + "experimental", + ".pytest_cache", + "**/.ipynb_checkpoints/**", + "**/proto/**", + "data", + "config", +] +# Same as Black. +line-length = 99 +[tool.ruff.lint] +# Allow unused variables when underscore-prefixed. +dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" +select = [ + "ARG", "C4", "D", "E", "EM", "F", "FBT", + "FLY", "FIX", "FURB", "N", "NPY", + "INP", "ISC", "PERF", "PIE", "PL", + "PTH", "RET", "RUF", "S", "T10", + "TD", "T20", "UP", "YTT", "W", +] +ignore = [ + "D100", "D211", "D213", "D104", "D203", "D301", "D407", "S101", + "FBT001", "FBT002", "FIX002", "ISC001", "PLR0913", "RUF012", "TD003", + "PTH123", "PLR6301", "PLR0917", "S311", "S403", "PLR0914", "PLR0915", "S608", + "EM102", "PTH111", "FIX004", "UP035", "PLW2901", "S318", "S408", 'S405', + 'E902', "TD001", "TD002", "FIX001", +] +# Allow autofix for all enabled rules (when `--fix`) is provided. +fixable = ["ALL"] +unfixable = ["I"] + +[tool.ruff.lint.flake8-quotes] +docstring-quotes = "double" + +[tool.ruff.lint.per-file-ignores] +"__init__.py" = ["E402", "F401"] +"cli.py" = ["PLC0415", "D205", "D400", "D415"] +"core.py" = ["ARG002", "PLR0904"] +"_old_core.py" = ["ALL"] +"lunar_lander.py" = ["PLR2004", "FBT003", "N806"] +"api_tests.py" = ["D", "ARG002", "PLW1508", "FBT003", "PLR2004"] +"montezuma.py" = ["PLR2004", "S101", "ARG002", "TD002"] +"registry.py" = ["PLC0415", "PLR0911"] +"**/docs/**" = ["INP001", "PTH100"] +"**/super_mario_gym/**" = ["ALL"] +"**/{tests,docs,tools}/*" = [ + "E402", "F401", "F811", "D", "S101", "PLR2004", "S105", + "PLW1514", "PTH123", "PTH107", "N811", "PLC0415", "ARG002", +] +# Enable reformatting of code snippets in docstrings. +[tool.ruff.format] +docstring-code-line-length = 80 +docstring-code-format = true +indent-style = "space" +line-ending = "auto" +preview = true +quote-style = "double" + +[tool.mypy] +exclude = ["experimental.*", "deprecated.*"] +ignore_missing_imports = true + +# isort orders and lints imports +[tool.isort] +profile = "black" +line_length = 99 +multi_line_output = 3 +order_by_type = false +force_alphabetical_sort_within_sections = true +force_sort_within_sections = true +combine_as_imports = true +include_trailing_comma = true +color_output = true +lines_after_imports = 2 +honor_noqa = true +skip = ["venv", ".venv"] +skip_glob = ["*.pyx"] + +[tool.pylint.master] +ignore = 'tests' +load-plugins =' pylint.extensions.docparams' + +[tool.pylint.messages_control] +disable = 'all,' +enable = """, + missing-param-doc, + differing-param-doc, + differing-type-doc, + missing-return-doc, + """ + +[tool.pytest.ini_options] +# To disable a specific warning --> action:message:category:module:line +filterwarnings = ["ignore::UserWarning", 'ignore::DeprecationWarning'] +addopts = "--ignore=scripts --doctest-continue-on-failure" + +# Code coverage config +[tool.coverage.run] +branch = true + +[tool.coverage.report] +exclude_lines =["no cover", + 'raise NotImplementedError', + 'if __name__ == "__main__":'] +ignore_errors = true +omit = ["tests/*"] diff --git a/requirements-dev.lock b/requirements-dev.lock index f0cf65f..e579c60 100644 --- a/requirements-dev.lock +++ b/requirements-dev.lock @@ -507,7 +507,9 @@ sphinxext-opengraph==0.9.1 # via plangym sqlalchemy==2.0.32 # via jupyter-cache -stable-retro==0.9.1 +stable-retro==0.9.1 ; sys_platform == 'darwin' + # via plangym +stable-retro==0.9.2 ; sys_platform != 'darwin' # via plangym stack-data==0.6.3 # via ipython diff --git a/requirements.lock b/requirements.lock index 9fb8762..6029d34 100644 --- a/requirements.lock +++ b/requirements.lock @@ -506,7 +506,9 @@ sphinxext-opengraph==0.9.1 # via plangym sqlalchemy==2.0.32 # via jupyter-cache -stable-retro==0.9.1 +stable-retro==0.9.1 ; sys_platform == 'darwin' + # via plangym +stable-retro==0.9.2 ; sys_platform != 'darwin' # via plangym stack-data==0.6.3 # via ipython diff --git a/src/plangym/scripts/import_retro_roms.py b/src/plangym/scripts/import_retro_roms.py index f26a6b7..f000df7 100644 --- a/src/plangym/scripts/import_retro_roms.py +++ b/src/plangym/scripts/import_retro_roms.py @@ -1,88 +1,88 @@ -import os -import sys -import zipfile -import logging -import flogging -from pathlib import Path - -import retro.data - -flogging.setup() -logger = logging.getLogger("import-roms") - - -def _check_zipfile(f, process_f): - with zipfile.ZipFile(f) as zf: - for entry in zf.infolist(): - _root, ext = os.path.splitext(entry.filename) # noqa: PTH122 - with zf.open(entry) as innerf: - if ext == ".zip": - _check_zipfile(innerf, process_f) - else: - process_f(entry.filename, innerf) - - -def main(): - """Import ROMs from a directory into the retro data directory.""" - from retro.data import EMU_EXTENSIONS # noqa: PLC0415 - - # This avoids a bug when loading the emu_extensions. - - emu_extensions = { - ".sfc": "Snes", - ".md": "Genesis", - ".sms": "Sms", - ".gg": "GameGear", - ".nes": "Nes", - ".gba": "GbAdvance", - ".gb": "GameBoy", - ".gbc": "GbColor", - ".a26": "Atari2600", - ".pce": "PCEngine", - } - EMU_EXTENSIONS.update(emu_extensions) - paths = sys.argv[1:] or [Path.cwd()] - logger.info(f"Importing ROMs from: {paths}") - logger.info("Fetching known hashes") - known_hashes = retro.data.get_known_hashes() - logger.info(f"Found {len(known_hashes)} known hashes") - imported_games = 0 - - def save_if_matches(filename, f): - nonlocal imported_games - try: - data, hash = retro.data.groom_rom(filename, f) - except (OSError, ValueError): - logging.warning(f"Failed to process file: {filename}") - return - if hash in known_hashes: - game, ext, curpath = known_hashes[hash] - # print('Importing', game) - rompath = os.path.join(curpath, game, f"rom{ext}") # noqa: PTH118 - # print("ROM PATH", rompath) - with open(rompath, "wb") as file: # noqa: FURB103 - file.write(data) - imported_games += 1 - logger.info(f"Imported game: {game}") - logger.debug(f"to {rompath}") - - for path in paths: # noqa: PLR1702 - logger.info(f"Processing path: {path}") - for root, dirs, files in os.walk(path): - for filename in files: - logger.debug(f"Processing file: {root}/{filename}") - filepath = os.path.join(root, filename) # noqa: PTH118 - with open(filepath, "rb") as f: - _root, ext = os.path.splitext(filename) # noqa: PTH122 - if ext == ".zip": - try: - _check_zipfile(f, save_if_matches) - except (zipfile.BadZipFile, RuntimeError, OSError): - logger.warning(f"Failed to process zip file: {filepath}") - else: - save_if_matches(filename, f) - logger.info(f"Total imported games: {imported_games}") - - -if __name__ == "__main__": - sys.exit(main()) +import os +import sys +import zipfile +import logging +import flogging +from pathlib import Path + +import retro.data + +flogging.setup() +logger = logging.getLogger("import-roms") + + +def _check_zipfile(f, process_f): + with zipfile.ZipFile(f) as zf: + for entry in zf.infolist(): + _root, ext = os.path.splitext(entry.filename) # noqa: PTH122 + with zf.open(entry) as innerf: + if ext == ".zip": + _check_zipfile(innerf, process_f) + else: + process_f(entry.filename, innerf) + + +def main(): + """Import ROMs from a directory into the retro data directory.""" + from retro.data import EMU_EXTENSIONS # noqa: PLC0415 + + # This avoids a bug when loading the emu_extensions. + + emu_extensions = { + ".sfc": "Snes", + ".md": "Genesis", + ".sms": "Sms", + ".gg": "GameGear", + ".nes": "Nes", + ".gba": "GbAdvance", + ".gb": "GameBoy", + ".gbc": "GbColor", + ".a26": "Atari2600", + ".pce": "PCEngine", + } + EMU_EXTENSIONS.update(emu_extensions) + paths = sys.argv[1:] or [Path.cwd()] + logger.info(f"Importing ROMs from: {paths}") + logger.info("Fetching known hashes") + known_hashes = retro.data.get_known_hashes() + logger.info(f"Found {len(known_hashes)} known hashes") + imported_games = 0 + + def save_if_matches(filename, f): + nonlocal imported_games + try: + data, hash = retro.data.groom_rom(filename, f) + except (OSError, ValueError): + logging.warning(f"Failed to process file: {filename}") + return + if hash in known_hashes: + game, ext, curpath = known_hashes[hash] + # print('Importing', game) + rompath = os.path.join(curpath, game, f"rom{ext}") # noqa: PTH118 + # print("ROM PATH", rompath) + with open(rompath, "wb") as file: # noqa: FURB103 + file.write(data) + imported_games += 1 + logger.info(f"Imported game: {game}") + logger.debug(f"to {rompath}") + + for path in paths: # noqa: PLR1702 + logger.info(f"Processing path: {path}") + for root, dirs, files in os.walk(path): + for filename in files: + logger.debug(f"Processing file: {root}/{filename}") + filepath = os.path.join(root, filename) # noqa: PTH118 + with open(filepath, "rb") as f: + _root, ext = os.path.splitext(filename) # noqa: PTH122 + if ext == ".zip": + try: + _check_zipfile(f, save_if_matches) + except (zipfile.BadZipFile, RuntimeError, OSError): + logger.warning(f"Failed to process zip file: {filepath}") + else: + save_if_matches(filename, f) + logger.info(f"Total imported games: {imported_games}") + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/src/plangym/version.py b/src/plangym/version.py index bcbc2e5..1fdb88d 100644 --- a/src/plangym/version.py +++ b/src/plangym/version.py @@ -1,3 +1,3 @@ -"""Current version of the project. Do not modify manually.""" - -__version__ = "0.1.5" +"""Current version of the project. Do not modify manually.""" + +__version__ = "0.1.5"