diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 1823745..8a45d40 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -47,11 +47,12 @@ jobs: pytest: name: Run Pytest - runs-on: ubuntu-latest if: "!contains(github.event.head_commit.message, 'Bump version')" strategy: matrix: - python-version: ['3.10'] + python-version: [ '3.10' ] + os: [ 'ubuntu-latest', 'macos-latest' ] + runs-on: ${{ matrix.os }} steps: - name: actions/checkout uses: actions/checkout@v3 @@ -64,29 +65,61 @@ jobs: uses: eifinger/setup-rye@v4 with: enable-cache: true - cache-prefix: ubuntu-latest-rye-test-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }} + 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: ubuntu-latest-system-test-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }} - restore-keys: ubuntu-latest-system-test - - name: Install test and package dependencies + 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 + 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 - sudo apt-get install -y xvfb -y - sudo MUJOCO_PATH=/home/runner/.mujoco/ make install-envs + 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 - ROM_PASSWORD=${{ secrets.ROM_PASSWORD }} make import-roms + # rye sync --features=ray,box_2d,atari,classic-control,test + ROM_PASSWORD=${{ secrets.ROM_PASSWORD }} rye run import-roms + + - name: Run Pytest on MacOS + if: ${{ matrix.os == 'macos-latest' }} + run: | + set -x + Xvfb :1337 & export DISPLAY=:1337 & rye run test - - name: Test with pytest + - 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' }} + # 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) diff --git a/install-lua-macos.sh b/install-lua-macos.sh new file mode 100644 index 0000000..0d381ab --- /dev/null +++ b/install-lua-macos.sh @@ -0,0 +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):" +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 c6eb118..2cab24b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,8 +38,11 @@ nes = [ ] classic-control = ["gymnasium[classic_control]>=0.29.1, == 0.*", "pygame>=2.6.0"] ray = ["ray>=2.35.0"] -dm_control = ["dm-control>=1.0.22", "gym @ git+https://github.com/FragileTech/gym.git"] -retro = ["stable_retro"] +dm_control = ["mujoco>=3.2.2", "dm-control>=1.0.22", "gym @ git+https://github.com/FragileTech/gym.git"] +retro = [ + "stable_retro; sys_platform == 'darwin'", + "stable_retro==0.9.1; sys_platform == 'darwin'" +] jupyter = ["jupyterlab>=3.2.0"] box_2d = ["box2d-py==2.3.5"] test = [ diff --git a/requirements-dev.lock b/requirements-dev.lock index 72c9ece..bbe27bd 100644 --- a/requirements-dev.lock +++ b/requirements-dev.lock @@ -265,6 +265,7 @@ msgpack==1.0.8 # via ray mujoco==3.2.2 # via dm-control + # via plangym myst-nb==1.1.1 # via plangym myst-parser==4.0.0 diff --git a/requirements.lock b/requirements.lock index 278bc03..ed55b81 100644 --- a/requirements.lock +++ b/requirements.lock @@ -265,6 +265,7 @@ msgpack==1.0.8 # via ray mujoco==3.2.2 # via dm-control + # via plangym myst-nb==1.1.1 # via plangym myst-parser==4.0.0 diff --git a/src/plangym/scripts/import_retro_roms.py b/src/plangym/scripts/import_retro_roms.py index 239fed3..f26a6b7 100644 --- a/src/plangym/scripts/import_retro_roms.py +++ b/src/plangym/scripts/import_retro_roms.py @@ -3,6 +3,7 @@ import zipfile import logging import flogging +from pathlib import Path import retro.data @@ -40,7 +41,7 @@ def main(): ".pce": "PCEngine", } EMU_EXTENSIONS.update(emu_extensions) - paths = sys.argv[1:] or [os.getcwd()] + 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()