1{
2 lib,
3 buildPythonPackage,
4 fetchFromGitHub,
5 setuptools,
6 wheel,
7 numpy,
8 pip,
9 termcolor,
10 pytestCheckHook,
11 torch,
12 fetchpatch2,
13}:
14
15buildPythonPackage rec {
16 pname = "rlcard";
17 version = "1.0.7";
18 pyproject = true;
19
20 src = fetchFromGitHub {
21 owner = "datamllab";
22 repo = "rlcard";
23 tag = version;
24 hash = "sha256-SWj6DBItQzSM+nioV54a350Li7tbBaVXsQxNAqVgB0k=";
25 };
26
27 patches = [
28 # Remove distutils to make it compatible with Python 3.12
29 # https://github.com/datamllab/rlcard/pull/323
30 (fetchpatch2 {
31 name = "remove-distutils.patch";
32 url = "https://github.com/datamllab/rlcard/commit/e44378157aaf229ffe2aaef9fafe500c2844045e.patch";
33 hash = "sha256-aQS4d9ETj6pDv26G77mC+0xHQMA2hjspAxtAyz0rA6Y=";
34 })
35 ];
36
37 # AttributeError: 'numpy.ndarray' object has no attribute 'tostring'
38 # tobytes() has the exact same behavior as tostring()
39 # https://github.com/datamllab/rlcard/pull/328
40 postPatch = ''
41 substituteInPlace rlcard/agents/cfr_agent.py \
42 --replace-fail \
43 "state['obs'].tostring()" \
44 "state['obs'].tobytes()"
45 '';
46
47 build-system = [
48 setuptools
49 wheel
50 ];
51
52 dependencies = [
53 numpy
54 # pip is required at runtime (https://github.com/datamllab/rlcard/blob/1.0.7/rlcard/utils/utils.py#L10)
55 pip
56 termcolor
57 ];
58
59 pythonImportsCheck = [ "rlcard" ];
60
61 nativeCheckInputs = [
62 pytestCheckHook
63 torch
64 ];
65
66 disabledTests = [
67 # AttributeError: module 'numpy' has no attribute 'int'.
68 # https://github.com/datamllab/rlcard/issues/266
69 "test_decode_action"
70 "test_get_legal_actions"
71 "test_get_perfect_information"
72 "test_get_player_id"
73 "test_init_game"
74 "test_is_deterministic"
75 "test_proceed_game"
76 "test_reset_and_extract_state"
77 "test_run"
78 "test_step"
79 "test_step"
80 "test_step_back"
81 "test_step_back"
82
83 # ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 3 dimensions. The detected shape was (1, 1, 5) + inhomogeneous part.
84 "test_reorganize"
85 ];
86
87 meta = with lib; {
88 description = "Reinforcement Learning / AI Bots in Card (Poker) Games - Blackjack, Leduc, Texas, DouDizhu, Mahjong, UNO";
89 homepage = "https://github.com/datamllab/rlcard";
90 changelog = "https://github.com/datamllab/rlcard/releases/tag/${version}";
91 license = licenses.mit;
92 maintainers = with maintainers; [ GaetanLepage ];
93 };
94}