Skip to content

Commit

Permalink
Includes roms within build for pypi and testing (#513)
Browse files Browse the repository at this point in the history
Co-authored-by: Mark Towers <mark.m.towers@gmail.com>
  • Loading branch information
jjshoots and pseudo-rnd-thoughts authored Mar 2, 2024
1 parent 36603b8 commit 14a8711
Show file tree
Hide file tree
Showing 18 changed files with 386 additions and 535 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,11 @@ jobs:
# https://github.com/microsoft/vcpkg/issues/20121
doNotCache: true

- name: Download tar.gz.b64
run: ./curl_tar_gz_b64.sh

- name: Build
run: python -m pip install --user --verbose .[test]
run: python -m pip install --verbose .[test]

- name: Test
run: python -m pytest
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:
- name: Unzip wheels asset
run: |
unzip wheels.zip -d dist
- name: Download tar.gz.b64
run: ./curl_tar_gz_b64.sh
- name: Publish to PyPi
uses: pypa/gh-action-pypi-publish@release/v1
with:
Expand Down
153 changes: 141 additions & 12 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
## ALE

ale
build
doc/examples/*Example

## Generic

# Emacs temp files
*~
.*
*#
# Don't save roms in repo
*.tar.gz.b64
*.tar.gz
*.bin
!tetris.bin

# Auto-generated dependency files
.deps
Expand All @@ -20,15 +18,146 @@ doc/examples/*Example
*.o
*.d

# Compiled Dynamic libraries
*.so

# Compiled Static libraries
*.lai
*.la
*.a

# Python
*.pyc
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files 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/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/
6 changes: 6 additions & 0 deletions curl_tar_gz_b64.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

this_directory="$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)"
curl \
"https://gist.githubusercontent.com/jjshoots/61b22aefce4456920ba99f2c36906eda/raw/00046ac3403768bfe45857610a3d333b8e35e026/Roms.tar.gz.b64" \
-o "${this_directory}/src/python/roms/Roms.tar.gz.b64"
106 changes: 0 additions & 106 deletions md5.txt

This file was deleted.

6 changes: 1 addition & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,13 @@ homepage = "https://github.com/mgbellemare/Arcade-Learning-Environment"
documentation = "https://github.com/mgbellemare/Arcade-Learning-Environment/tree/master/docs"
changelog = "https://github.com/mgbellemare/Arcade-Learning-Environment/blob/master/CHANGELOG.md"

[project.scripts]
ale-import-roms = "ale_py.scripts.import_roms:main"

[tool.setuptools]
packages = [
"ale_py",
"ale_py.roms",
"ale_py.scripts"
]
package-dir = {ale_py = "src/python"}
package-data = {"ale_py" = ["py.typed", "*.pyi", "**/*.pyi"], "ale_py.roms" = ["*.bin", "md5.txt"]}
package-data = {"ale_py" = ["py.typed", "*.pyi", "**/*.pyi"], "ale_py.roms" = ["md5.json", "Roms.tar.gz.b64"]}

[tool.pytest.ini_options]
minversion = "7.0"
Expand Down
4 changes: 2 additions & 2 deletions src/python/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__(
Default parameters are taken from Machado et al., 2018.
Args:
game: str => Game to initialize env with.
game: str => Game to initialize env with, in snake_case.
mode: Optional[int] => Game mode, see Machado et al., 2018
difficulty: Optional[int] => Game difficulty,see Machado et al., 2018
obs_type: str => Observation type in { 'rgb', 'grayscale', 'ram' }
Expand Down Expand Up @@ -186,7 +186,7 @@ def seed_game(self, seed: int | None = None) -> tuple[int, int]:

def load_game(self) -> None:
"""This function initializes the ROM and sets the corresponding mode and difficulty."""
self.ale.loadROM(getattr(roms, self._game))
self.ale.loadROM(roms.get_rom_path(self._game))

if self._game_mode is not None:
self.ale.setMode(self._game_mode)
Expand Down
18 changes: 15 additions & 3 deletions src/python/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import ale_py.roms as roms
import gymnasium
from ale_py.roms import utils as rom_utils


class EnvFlavour(NamedTuple):
Expand All @@ -19,6 +18,19 @@ class EnvConfig(NamedTuple):
flavours: Sequence[EnvFlavour]


def _rom_id_to_name(rom: str) -> str:
"""
Let the ROM ID be the ROM identifier in snake_case.
For example, `space_invaders`
The ROM name is the ROM ID in pascalcase.
For example, `SpaceInvaders`
This function converts the ROM ID to the ROM name.
i.e., snakecase -> pascalcase
"""
return rom.title().replace("_", "")


def _register_rom_configs(
roms: Sequence[str],
obs_types: Sequence[str],
Expand All @@ -32,7 +44,7 @@ def _register_rom_configs(
for obs_type in obs_types:
for config in configs:
for flavour in config.flavours:
name = rom_utils.rom_id_to_name(rom)
name = _rom_id_to_name(rom)
name = f"{name}-ram" if obs_type == "ram" else name

# Parse config kwargs
Expand Down Expand Up @@ -165,7 +177,7 @@ def register_v0_v4_envs():


def register_v5_envs():
all_games = list(map(rom_utils.rom_name_to_id, dir(roms)))
all_games = roms.get_all_rom_ids()
obs_types = ["rgb", "ram"]

# max_episode_steps is 108k frames which is 30 mins of gameplay.
Expand Down
Loading

0 comments on commit 14a8711

Please sign in to comment.