1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 fetchFromGitHub,
6
7 # build-system
8 cmake,
9 ninja,
10 pybind11,
11 setuptools,
12
13 # buildInputs
14 SDL2,
15 opencv,
16 zlib,
17
18 # dependencies
19 importlib-resources,
20 numpy,
21 typing-extensions,
22
23 # tests
24 gymnasium,
25 opencv-python,
26 pytestCheckHook,
27
28 # Whether to enable recently added vector environments:
29 # https://github.com/Farama-Foundation/Arcade-Learning-Environment/blob/v0.11.0/docs/vector-environment.md
30 # FIXME: Disabled by default as it mysteriously causes stable-baselines3's tests to hang indefinitely.
31 withVectorEnv ? false,
32}:
33
34buildPythonPackage rec {
35 pname = "ale-py";
36 version = "0.11.0";
37 pyproject = true;
38
39 src = fetchFromGitHub {
40 owner = "Farama-Foundation";
41 repo = "Arcade-Learning-Environment";
42 tag = "v${version}";
43 hash = "sha256-RgFVpbjJp54FncQzFtdZM7p/1GBMsQ2HvLgIoaokiQc=";
44 };
45
46 build-system = [
47 cmake
48 ninja
49 pybind11
50 setuptools
51 ];
52
53 buildInputs =
54 [
55 SDL2
56 zlib
57 ]
58 ++ lib.optionals withVectorEnv [
59 opencv
60 ];
61
62 dependencies = [
63 gymnasium
64 importlib-resources
65 numpy
66 typing-extensions
67 ];
68
69 postPatch =
70 # Relax the pybind11 version
71 ''
72 substituteInPlace src/ale/python/CMakeLists.txt \
73 --replace-fail \
74 'find_package(pybind11 ''${PYBIND11_VER} QUIET)' \
75 'find_package(pybind11 QUIET)'
76 ''
77 + lib.optionalString (!withVectorEnv) ''
78 substituteInPlace setup.py \
79 --replace-fail \
80 "-DBUILD_VECTOR_LIB=ON" \
81 "-DBUILD_VECTOR_LIB=OFF"
82 '';
83
84 dontUseCmakeConfigure = true;
85
86 pythonImportsCheck = [ "ale_py" ];
87
88 doCheck = false;
89
90 nativeCheckInputs =
91 [
92 gymnasium
93 pytestCheckHook
94 ]
95 + lib.optionals withVectorEnv [
96 opencv-python
97 ];
98
99 disabledTests = [
100 # Fatal Python error: Aborted
101 # line 414 in test_display_screen
102 "test_display_screen"
103
104 # test_atari_env.py tests fail on the majority of the environments because the ROM are missing.
105 # The user is expected to manually download the roms:
106 # https://github.com/Farama-Foundation/Arcade-Learning-Environment/blob/v0.9.0/docs/faq.md#i-downloaded-ale-and-i-installed-it-successfully-but-i-cannot-find-any-rom-file-at-roms-do-i-have-to-get-them-somewhere-else
107 "test_check_env"
108 "test_reset_step_shapes"
109 "test_rollout_consistency"
110 "test_sound_obs"
111 ];
112
113 meta = {
114 description = "Simple framework that allows researchers and hobbyists to develop AI agents for Atari 2600 games";
115 mainProgram = "ale-import-roms";
116 homepage = "https://github.com/mgbellemare/Arcade-Learning-Environment";
117 changelog = "https://github.com/Farama-Foundation/Arcade-Learning-Environment/releases/tag/v${version}";
118 license = lib.licenses.gpl2;
119 maintainers = with lib.maintainers; [ billhuang ];
120 badPlatforms = [
121 # FAILED: src/ale/libale.a
122 # /bin/sh: CMAKE_CXX_COMPILER_AR-NOTFOUND: command not found
123 lib.systems.inspect.patterns.isDarwin
124 ];
125 };
126}