1{
2 lib,
3 buildPythonPackage,
4 fetchFromGitHub,
5 fetchpatch,
6
7 # build-system
8 setuptools,
9
10 # dependencies
11 gymnasium,
12 numpy,
13
14 # tests
15 ale-py,
16 bsuite,
17 dm-control,
18 gym,
19 imageio,
20 pettingzoo,
21 pytestCheckHook,
22}:
23
24buildPythonPackage rec {
25 pname = "shimmy";
26 version = "2.0.0";
27 pyproject = true;
28
29 src = fetchFromGitHub {
30 owner = "Farama-Foundation";
31 repo = "Shimmy";
32 tag = "v${version}";
33 hash = "sha256-/wIXjOGb3UeMQdeifYagd7OcxbBcdGPS09mjvkFsWmk=";
34 };
35
36 patches = [
37 # Shimmy tries to register some environments from `dm-control` that require unpackaged `labmaze`.
38 # This prevents from importing `shimmy` itself by crashing with a `ModuleNotFoundError`.
39 # This patch imports those environments lazily.
40 #
41 # TODO: get rid of this patch at the next release as the issue has been fixed upstream:
42 # https://github.com/Farama-Foundation/Shimmy/pull/125
43 (fetchpatch {
44 name = "prevent-labmaze-import-crash";
45 url = "https://github.com/Farama-Foundation/Shimmy/commit/095d576f6aae15a09a1e426138629ce9f43a3c04.patch";
46 hash = "sha256-rr9l3tHunYFk0j7hfo9IaSRlogAtwXoXcQ0zuU/TL8c=";
47 })
48 ];
49
50 build-system = [
51 setuptools
52 ];
53
54 dependencies = [
55 gymnasium
56 numpy
57 ];
58
59 pythonImportsCheck = [ "shimmy" ];
60
61 nativeCheckInputs = [
62 ale-py
63 bsuite
64 dm-control
65 gym
66 imageio
67 pettingzoo
68 pytestCheckHook
69 ];
70
71 disabledTestPaths = [
72 # Requires unpackaged labmaze
73 "tests/test_dm_control_multi_agent.py"
74
75 # Requires unpackaged pyspiel
76 "tests/test_openspiel.py"
77 ];
78
79 preCheck = ''
80 export HOME=$(mktemp -d)
81 '';
82
83 disabledTests = [
84 # Require network access
85 "test_check_env[bsuite/mnist_noise-v0]"
86 "test_check_env[bsuite/mnist_scale-v0]"
87 "test_check_env[bsuite/mnist-v0]"
88 "test_existing_env"
89 "test_loading_env"
90 "test_pickle[bsuite/mnist-v0]"
91 "test_seeding[bsuite/mnist_noise-v0]"
92 "test_seeding[bsuite/mnist_scale-v0]"
93 "test_seeding[bsuite/mnist-v0]"
94 "test_seeding"
95
96 # RuntimeError: std::exception
97 "test_check_env"
98 "test_seeding[dm_control/quadruped-escape-v0]"
99 "test_rendering_camera_id"
100 "test_rendering_multiple_cameras"
101 "test_rendering_depth"
102 "test_render_height_widths"
103 ];
104
105 meta = {
106 changelog = "https://github.com/Farama-Foundation/Shimmy/releases/tag/v${version}";
107 description = "API conversion tool for popular external reinforcement learning environments";
108 homepage = "https://github.com/Farama-Foundation/Shimmy";
109 license = lib.licenses.mit;
110 maintainers = with lib.maintainers; [ GaetanLepage ];
111 };
112}