Skip to content

Commit 02a75df

Browse files
authored
python312Packages.gym: cleanup & patch to fix shimmy (#385183)
2 parents 7e714eb + 6e0b6f7 commit 02a75df

File tree

1 file changed

+98
-10
lines changed

1 file changed

+98
-10
lines changed
Lines changed: 98 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,129 @@
11
{
22
lib,
3+
stdenv,
34
buildPythonPackage,
45
fetchFromGitHub,
5-
numpy,
6+
7+
# build-system
8+
setuptools,
9+
10+
# dependencies
611
cloudpickle,
12+
numpy,
713
gym-notices,
814
importlib-metadata,
915
pythonOlder,
16+
17+
# tests
18+
moviepy,
19+
pybox2d,
20+
pygame,
21+
pytestCheckHook,
22+
opencv-python,
1023
}:
1124

1225
buildPythonPackage rec {
1326
pname = "gym";
1427
version = "0.26.2";
15-
format = "setuptools";
28+
pyproject = true;
1629

1730
src = fetchFromGitHub {
1831
owner = "openai";
19-
repo = pname;
32+
repo = "gym";
2033
tag = version;
2134
hash = "sha256-uJgm8l1SxIRC5PV6BIH/ht/1ucGT5UaUhkFMdusejgA=";
2235
};
2336

24-
propagatedBuildInputs = [
37+
# Fix numpy2 compatibility
38+
postPatch = ''
39+
substituteInPlace gym/envs/classic_control/acrobot.py \
40+
--replace-fail "np.float_" "np.float64"
41+
42+
substituteInPlace gym/utils/passive_env_checker.py \
43+
--replace-fail "np.bool8" "np.bool"
44+
45+
substituteInPlace tests/envs/test_action_dim_check.py \
46+
--replace-fail "np.cast[dtype](OOB_VALUE)" "np.asarray(OOB_VALUE, dtype=dtype)" \
47+
--replace-fail "np.alltrue" "np.all"
48+
49+
substituteInPlace tests/spaces/test_box.py \
50+
--replace-fail "np.bool8" "np.bool" \
51+
--replace-fail "np.complex_" "np.complex128"
52+
53+
substituteInPlace tests/wrappers/test_record_episode_statistics.py \
54+
--replace-fail "np.alltrue" "np.all"
55+
'';
56+
57+
build-system = [
58+
setuptools
59+
];
60+
61+
dependencies = [
2562
cloudpickle
2663
numpy
2764
gym-notices
2865
] ++ lib.optionals (pythonOlder "3.10") [ importlib-metadata ];
2966

30-
# The test needs MuJoCo that is not free library.
31-
doCheck = false;
32-
3367
pythonImportsCheck = [ "gym" ];
3468

35-
meta = with lib; {
69+
nativeCheckInputs = [
70+
moviepy
71+
opencv-python
72+
pybox2d
73+
pygame
74+
pytestCheckHook
75+
];
76+
77+
disabledTests =
78+
[
79+
# TypeError: Converting from sequence to b2Vec2, expected int/float arguments index 0
80+
"test_box_actions_out_of_bound"
81+
"test_env_determinism_rollout"
82+
"test_envs_pass_env_checker"
83+
"test_frame_stack"
84+
"test_make_autoreset_true"
85+
"test_passive_checker_wrapper_warnings"
86+
"test_pickle_env"
87+
"test_render_modes"
88+
89+
# TypeError: in method 'b2RevoluteJoint___SetMotorSpeed', argument 2 of type 'float32'
90+
"test_box_actions_out_of_bound"
91+
92+
# TypeError: exceptions must be derived from Warning, not <class 'NoneType'>
93+
"test_dict_init"
94+
95+
# ValueError: setting an array element with a sequence.
96+
# The requested array has an inhomogeneous shape after 1 dimensions.
97+
# The detected shape was (2,) + inhomogeneous part
98+
"test_sample_contains"
99+
]
100+
++ lib.optionals stdenv.hostPlatform.isDarwin [
101+
# Fatal Python error: Aborted
102+
# gym/envs/classic_control/cartpole.py", line 227 in render
103+
"test_autoclose"
104+
"test_call_async_vector_env"
105+
"test_call_sync_vector_env"
106+
"test_human_rendering"
107+
"test_make_render_mode"
108+
"test_order_enforcing"
109+
"test_record_simple"
110+
"test_record_video_reset"
111+
"test_record_video_step_trigger"
112+
"test_record_video_using_default_trigger"
113+
"test_record_video_within_vecto"
114+
"test_text_envs"
115+
];
116+
117+
disabledTestPaths = lib.optionals stdenv.hostPlatform.isDarwin [
118+
# Fatal Python error: Aborted
119+
# gym/utils/play.py", line 62 in __init__
120+
"tests/utils/test_play.py"
121+
];
122+
123+
meta = {
36124
description = "Toolkit for developing and comparing your reinforcement learning agents";
37125
homepage = "https://www.gymlibrary.dev/";
38-
license = licenses.mit;
39-
maintainers = with maintainers; [ hyphon81 ];
126+
license = lib.licenses.mit;
127+
maintainers = with lib.maintainers; [ GaetanLepage ];
40128
};
41129
}

0 commit comments

Comments
 (0)