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