Skip to content

Commit

Permalink
Fix/dependencies (#156)
Browse files Browse the repository at this point in the history
* feat: added custom  function taken from movipy github repo

* fix: box2d is now an extra dependency + fix readme

* feat: update cpu-tests github workflow

* feat: update imports.py
  • Loading branch information
michele-milesi authored Nov 23, 2023
1 parent 65d0caf commit dcc3959
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/cpu-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ jobs:
- name: Install packages
run: |
python -m pip install -U pip
python -m pip install -e .[atari,test,dev]
python -m pip install swig
python -m pip install -e .[atari,box2d,test,dev]
- name: Run tests
run: |
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ source .venv/bin/activate
pip install "sheeprl @ git+https://github.com/Eclectic-Sheep/sheeprl.git"
# or, to install with atari and mujuco environment support, do
pip install "sheeprl[atari,mujoco,dev] @ git+https://github.com/Eclectic-Sheep/sheeprl.git"
# or, to install with box2d environment support, do
pip install swig
pip install "sheeprl[box2d] @ git+https://github.com/Eclectic-Sheep/sheeprl.git"
# or, to install with minedojo environment support, do
pip install "sheeprl[minedojo,dev] @ git+https://github.com/Eclectic-Sheep/sheeprl.git"
# or, to install with minerl environment support, do
Expand Down Expand Up @@ -208,7 +211,7 @@ It is recommended to use [homebrew](https://brew.sh/) to install [SWIG](https://
# then, do
brew install swig
# then attempt to pip install with the preferred method, such as
pip install "sheeprl[atari,mujoco,dev,test] @ git+https://github.com/Eclectic-Sheep/sheeprl.git"
pip install "sheeprl[atari,box2d,mujoco,dev,test] @ git+https://github.com/Eclectic-Sheep/sheeprl.git"
```

</details>
Expand Down
6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ create = true
in-project = true

[build-system]
requires = ["setuptools >= 61.0.0", "swig==4.*"]
requires = ["setuptools >= 61.0.0"]
build-backend = "setuptools.build_meta"

[project]
Expand All @@ -27,7 +27,8 @@ readme = { file = "docs/README.md", content-type = "text/markdown" }
requires-python = ">=3.8,<3.11"
classifiers = ["Programming Language :: Python", "Topic :: Scientific/Engineering :: Artificial Intelligence"]
dependencies = [
"gymnasium[box2d]==0.29.*",
"gymnasium==0.29.*",
"pygame >=2.1.3",
"moviepy>=1.0.3",
"tensordict==0.2.*",
"tensorboard>=2.10",
Expand Down Expand Up @@ -72,6 +73,7 @@ dev = [
]
mujoco = ["mujoco>=2.3.3", "gymnasium[mujoco]==0.29.*"]
dmc = ["dm_control>=1.0.12"]
box2d = ["gymnasium[box2d]==0.29.*"]
atari = [
"gymnasium[atari]==0.29.*",
"gymnasium[accept-rom-license]==0.29.*",
Expand Down
34 changes: 34 additions & 0 deletions sheeprl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

ROOT_DIR = os.path.dirname(__file__)

import decorator
from dotenv import load_dotenv

load_dotenv()
Expand Down Expand Up @@ -50,3 +51,36 @@
np.bool = bool

__version__ = "0.4.6dev1"


# Replace `moviepy.decorators.use_clip_fps_by_default` method to work with python 3.8, 3.9, and 3.10
import moviepy.decorators


# Taken from https://github.com/Zulko/moviepy/blob/master/moviepy/decorators.py#L118
@decorator.decorator
def custom_use_clip_fps_by_default(func, clip, *args, **kwargs):
"""Will use ``clip.fps`` if no ``fps=...`` is provided in **kwargs**."""
import inspect

def find_fps(fps):
if fps is not None:
return fps
elif getattr(clip, "fps", None):
return clip.fps
raise AttributeError(
"No 'fps' (frames per second) attribute specified"
" for function %s and the clip has no 'fps' attribute. Either"
" provide e.g. fps=24 in the arguments of the function, or define"
" the clip's fps with `clip.fps=24`" % func.__name__
)

names = inspect.getfullargspec(func).args[1:]

new_args = [find_fps(arg) if (name == "fps") else arg for (arg, name) in zip(args, names)]
new_kwargs = {kwarg: find_fps(value) if kwarg == "fps" else value for (kwarg, value) in kwargs.items()}

return func(clip, *new_args, **new_kwargs)


moviepy.decorators.use_clip_fps_by_default = custom_use_clip_fps_by_default
1 change: 1 addition & 0 deletions sheeprl/utils/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

_IS_ATARI_AVAILABLE = RequirementCache("gymnasium[atari]")
_IS_ATARI_ROMS_AVAILABLE = RequirementCache("gymnasium[accept-rom-license]")
_IS_BOX2D_AVAILABLE = RequirementCache("gymnasium[box2d]")
_IS_CRAFTER_AVAILABLE = RequirementCache("crafter")
_IS_DIAMBRA_AVAILABLE = RequirementCache("diambra")
_IS_DIAMBRA_ARENA_AVAILABLE = RequirementCache("diambra-arena")
Expand Down

0 comments on commit dcc3959

Please sign in to comment.