1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 fetchFromGitHub,
6 fetchpatch,
7 pythonOlder,
8 replaceVars,
9
10 # build-system
11 setuptools,
12
13 # patched in
14 geos,
15 gdal,
16 withGdal ? false,
17
18 # dependencies
19 asgiref,
20 sqlparse,
21
22 # optional-dependencies
23 argon2-cffi,
24 bcrypt,
25
26 # tests
27 aiosmtpd,
28 docutils,
29 geoip2,
30 jinja2,
31 numpy,
32 pillow,
33 pylibmc,
34 pymemcache,
35 python,
36 pywatchman,
37 pyyaml,
38 pytz,
39 redis,
40 selenium,
41 tblib,
42 tzdata,
43}:
44
45buildPythonPackage rec {
46 pname = "django";
47 version = "5.1.9";
48 pyproject = true;
49
50 disabled = pythonOlder "3.10";
51
52 src = fetchFromGitHub {
53 owner = "django";
54 repo = "django";
55 rev = "refs/tags/${version}";
56 hash = "sha256-uBP6MoVjPUtNu6KxLjaYmKTN42JIUCTJSuSnQWSxyQU=";
57 };
58
59 patches =
60 [
61 (replaceVars ./django_5_set_zoneinfo_dir.patch {
62 zoneinfo = tzdata + "/share/zoneinfo";
63 })
64 # prevent tests from messing with our pythonpath
65 ./django_5_tests_pythonpath.patch
66 # disable test that expects timezone issues
67 ./django_5_disable_failing_tests.patch
68
69 # fix filename length limit tests on bcachefs
70 # FIXME: remove in 5.2
71 (fetchpatch {
72 url = "https://github.com/django/django/commit/12f4f95405c7857cbf2f4bf4d0261154aac31676.patch";
73 hash = "sha256-+K20/V8sh036Ox9U7CSPgfxue7f28Sdhr3MsB7erVOk=";
74 })
75 ]
76 ++ lib.optionals withGdal [
77 (replaceVars ./django_5_set_geos_gdal_lib.patch {
78 geos = geos;
79 gdal = gdal;
80 extension = stdenv.hostPlatform.extensions.sharedLibrary;
81 })
82 ];
83
84 postPatch = ''
85 substituteInPlace tests/utils_tests/test_autoreload.py \
86 --replace-fail "/usr/bin/python" "${python.interpreter}"
87 '';
88
89 build-system = [ setuptools ];
90
91 dependencies = [
92 asgiref
93 sqlparse
94 ];
95
96 optional-dependencies = {
97 argon2 = [ argon2-cffi ];
98 bcrypt = [ bcrypt ];
99 };
100
101 nativeCheckInputs = [
102 # tests/requirements/py3.txt
103 aiosmtpd
104 docutils
105 geoip2
106 jinja2
107 numpy
108 pillow
109 pylibmc
110 pymemcache
111 pywatchman
112 pyyaml
113 pytz
114 redis
115 selenium
116 tblib
117 tzdata
118 ] ++ lib.flatten (lib.attrValues optional-dependencies);
119
120 doCheck =
121 !stdenv.hostPlatform.isDarwin
122 # pywatchman depends on folly which does not support 32bits
123 && !stdenv.hostPlatform.is32bit;
124
125 preCheck = ''
126 # make sure the installed library gets imported
127 rm -rf django
128
129 # fails to import github_links from docs/_ext/github_links.py
130 rm tests/sphinx/test_github_links.py
131
132 # provide timezone data, works only on linux
133 export TZDIR=${tzdata}/${python.sitePackages}/tzdata/zoneinfo
134
135 export PYTHONPATH=$PWD/docs/_ext:$PYTHONPATH
136 '';
137
138 checkPhase = ''
139 runHook preCheck
140
141 pushd tests
142 ${python.interpreter} runtests.py --settings=test_sqlite
143 popd
144
145 runHook postCheck
146 '';
147
148 __darwinAllowLocalNetworking = true;
149
150 meta = with lib; {
151 changelog = "https://docs.djangoproject.com/en/${lib.versions.majorMinor version}/releases/${version}/";
152 description = "High-level Python Web framework that encourages rapid development and clean, pragmatic design";
153 homepage = "https://www.djangoproject.com";
154 license = licenses.bsd3;
155 maintainers = with maintainers; [ hexa ];
156 };
157}