1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 fetchFromGitHub,
6
7 # build-system
8 setuptools,
9
10 # dependencies
11 cloudpickle,
12 farama-notifications,
13 numpy,
14 typing-extensions,
15 pythonOlder,
16 importlib-metadata,
17
18 # optional-dependencies
19 # atari
20 ale-py,
21
22 # tests
23 array-api-compat,
24 dill,
25 flax,
26 jax,
27 jaxlib,
28 matplotlib,
29 mujoco,
30 moviepy,
31 opencv4,
32 pybox2d,
33 pygame,
34 pytestCheckHook,
35 scipy,
36 torch,
37}:
38
39buildPythonPackage rec {
40 pname = "gymnasium";
41 version = "1.2.1";
42
43 pyproject = true;
44
45 src = fetchFromGitHub {
46 owner = "Farama-Foundation";
47 repo = "gymnasium";
48 tag = "v${version}";
49 hash = "sha256-KevA7AW73ppN6KuE0jAE3xfm/1ZWZxHtHbeNM6RC9yI=";
50 };
51
52 build-system = [ setuptools ];
53
54 dependencies = [
55 cloudpickle
56 farama-notifications
57 numpy
58 typing-extensions
59 ]
60 ++ lib.optionals (pythonOlder "3.10") [ importlib-metadata ];
61
62 optional-dependencies = {
63 atari = [
64 ale-py
65 ];
66 };
67
68 pythonImportsCheck = [ "gymnasium" ];
69
70 nativeCheckInputs = [
71 array-api-compat
72 dill
73 flax
74 jax
75 jaxlib
76 matplotlib
77 moviepy
78 mujoco
79 opencv4
80 pybox2d
81 pygame
82 pytestCheckHook
83 scipy
84 torch
85 ];
86
87 # if `doCheck = true` on Darwin, `jaxlib` is evaluated, which is both
88 # marked as broken and throws an error during evaluation if the package is evaluated anyway.
89 # disabling checks on Darwin avoids this and allows the package to be built.
90 # if jaxlib is ever fixed on Darwin, remove this.
91 doCheck = !stdenv.hostPlatform.isDarwin;
92
93 disabledTestPaths = [
94 # Unpackaged `mujoco-py` (Openai's mujoco) is required for these tests.
95 "tests/envs/mujoco/test_mujoco_custom_env.py"
96 "tests/envs/mujoco/test_mujoco_rendering.py"
97 "tests/envs/mujoco/test_mujoco_v5.py"
98
99 # Rendering tests failing in the sandbox
100 "tests/wrappers/vector/test_human_rendering.py"
101
102 # These tests need to write on the filesystem which cause them to fail.
103 "tests/utils/test_save_video.py"
104 "tests/wrappers/test_record_video.py"
105 ];
106
107 preCheck = ''
108 export SDL_VIDEODRIVER=dummy
109 '';
110
111 disabledTests = [
112 # Succeeds for most environments but `test_render_modes[Reacher-v4]` fails because it requires
113 # OpenGL access which is not possible inside the sandbox.
114 "test_render_mode"
115 ];
116
117 meta = {
118 description = "Standard API for reinforcement learning and a diverse set of reference environments (formerly Gym)";
119 homepage = "https://github.com/Farama-Foundation/Gymnasium";
120 changelog = "https://github.com/Farama-Foundation/Gymnasium/releases/tag/v${version}";
121 license = lib.licenses.mit;
122 maintainers = with lib.maintainers; [ GaetanLepage ];
123 };
124}