1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 fetchFromGitHub,
6 hatchling,
7 aiosqlite,
8 arrow,
9 babel,
10 cacert,
11 colour,
12 fasteners,
13 httpx,
14 jinja2,
15 mongoengine,
16 motor,
17 passlib,
18 phonenumbers,
19 pillow,
20 psycopg2,
21 pydantic,
22 pytest-asyncio,
23 pytestCheckHook,
24 python-multipart,
25 requests,
26 sqlalchemy,
27 sqlalchemy-file,
28 sqlalchemy-utils,
29 sqlmodel,
30 starlette,
31}:
32
33buildPythonPackage rec {
34 pname = "starlette-admin";
35 version = "0.14.1";
36 pyproject = true;
37
38 src = fetchFromGitHub {
39 owner = "jowilf";
40 repo = "starlette-admin";
41 rev = version;
42 hash = "sha256-DoYD8Hc5pd68+BhASw3mwwCdhu0vYHiELjVmVwU8FHs=";
43 };
44
45 # recreates https://github.com/jowilf/starlette-admin/pull/630 which cannot be cherry-picked
46 postPatch = ''
47 test_files_to_fix=(
48 tests/mongoengine/test_auth.py
49 tests/odmantic/test_async_engine.py
50 tests/odmantic/test_auth.py
51 tests/odmantic/test_sync_engine.py
52 tests/sqla/test_async_engine.py
53 tests/sqla/test_auth.py
54 tests/sqla/test_multiple_pks.py
55 tests/sqla/test_sqla_and_pydantic.py
56 tests/sqla/test_sqla_utils.py
57 tests/sqla/test_sqlmodel.py
58 tests/sqla/test_sync_engine.py
59 tests/sqla/test_view_serialization.py
60 tests/test_auth.py
61 )
62 substituteInPlace "''${test_files_to_fix[@]}" \
63 --replace-fail \
64 'from httpx import AsyncClient' \
65 'from httpx import AsyncClient, ASGITransport' \
66 --replace-fail \
67 'AsyncClient(app=app,' \
68 'AsyncClient(transport=ASGITransport(app=app),'
69 '';
70
71 build-system = [ hatchling ];
72
73 dependencies = [
74 jinja2
75 python-multipart
76 starlette
77 ];
78
79 optional-dependencies = {
80 i18n = [ babel ];
81 };
82
83 nativeCheckInputs = [
84 aiosqlite
85 arrow
86 babel
87 cacert
88 colour
89 fasteners
90 httpx
91 mongoengine
92 motor
93 passlib
94 phonenumbers
95 pillow
96 psycopg2
97 pydantic
98 pytest-asyncio
99 pytestCheckHook
100 requests
101 sqlalchemy
102 sqlalchemy-file
103 sqlalchemy-utils
104 sqlmodel
105 ];
106
107 preCheck = ''
108 # used in get_test_container in tests/sqla/utils.py
109 # fixes FileNotFoundError: [Errno 2] No such file or directory: '/tmp/storage/...'
110 mkdir .storage
111 export LOCAL_PATH="$PWD/.storage"
112 '';
113
114 disabledTests = lib.optionals stdenv.hostPlatform.isDarwin [
115 # flaky, depends on test order
116 "test_ensuring_pk"
117 # flaky, of-by-one
118 "test_api"
119 ];
120
121 disabledTestPaths =
122 [
123 # odmantic is not packaged
124 "tests/odmantic"
125 # needs mongodb running on port 27017
126 "tests/mongoengine"
127 ]
128 ++ lib.optionals stdenv.hostPlatform.isDarwin [
129 # very flaky, sandbox issues?
130 # libcloud.storage.types.ContainerDoesNotExistError
131 # sqlite3.OperationalError: attempt to write a readonly database
132 "tests/sqla/test_sync_engine.py"
133 "tests/sqla/test_async_engine.py"
134 ];
135
136 pythonImportsCheck = [
137 "starlette_admin"
138 "starlette_admin.actions"
139 "starlette_admin.base"
140 "starlette_admin.fields"
141 "starlette_admin.i18n"
142 "starlette_admin.tools"
143 "starlette_admin.views"
144 ];
145
146 meta = with lib; {
147 description = "Fast, beautiful and extensible administrative interface framework for Starlette & FastApi applications";
148 homepage = "https://github.com/jowilf/starlette-admin";
149 changelog = "https://github.com/jowilf/starlette-admin/blob/${src.rev}/CHANGELOG.md";
150 license = licenses.mit;
151 maintainers = with maintainers; [ pbsds ];
152 };
153}