1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 fetchFromGitHub,
6 pythonAtLeast,
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 pyyaml,
37 pytz,
38 redis,
39 selenium,
40 tblib,
41 tzdata,
42}:
43
44buildPythonPackage rec {
45 pname = "django";
46 version = "5.2.5";
47 pyproject = true;
48
49 disabled = pythonOlder "3.10";
50
51 src = fetchFromGitHub {
52 owner = "django";
53 repo = "django";
54 rev = "refs/tags/${version}";
55 hash = "sha256-1Lw0L+mPynf9CmioiTQhePgqCLniUkv9E0ZIoHhhBTs=";
56 };
57
58 patches = [
59 (replaceVars ./django_5_set_zoneinfo_dir.patch {
60 zoneinfo = tzdata + "/share/zoneinfo";
61 })
62 # prevent tests from messing with our pythonpath
63 ./django_5_tests_pythonpath.patch
64 # disable test that expects timezone issues
65 ./django_5_disable_failing_tests.patch
66 ]
67 ++ lib.optionals (pythonAtLeast "3.13") [
68 # https://code.djangoproject.com/ticket/36499
69 # https://github.com/django/django/pull/19639
70 ./3.13.6-html-parser.patch
71 ]
72 ++ lib.optionals withGdal [
73 (replaceVars ./django_5_set_geos_gdal_lib.patch {
74 geos = geos;
75 gdal = gdal;
76 extension = stdenv.hostPlatform.extensions.sharedLibrary;
77 })
78 ];
79
80 postPatch = ''
81 substituteInPlace tests/utils_tests/test_autoreload.py \
82 --replace-fail "/usr/bin/python" "${python.interpreter}"
83 '';
84
85 build-system = [ setuptools ];
86
87 dependencies = [
88 asgiref
89 sqlparse
90 ];
91
92 optional-dependencies = {
93 argon2 = [ argon2-cffi ];
94 bcrypt = [ bcrypt ];
95 };
96
97 nativeCheckInputs = [
98 # tests/requirements/py3.txt
99 aiosmtpd
100 docutils
101 geoip2
102 jinja2
103 numpy
104 pillow
105 pylibmc
106 pymemcache
107 pyyaml
108 pytz
109 redis
110 selenium
111 tblib
112 tzdata
113 ]
114 ++ lib.flatten (lib.attrValues optional-dependencies);
115
116 preCheck = ''
117 # make sure the installed library gets imported
118 rm -rf django
119
120 # fails to import github_links from docs/_ext/github_links.py
121 rm tests/sphinx/test_github_links.py
122
123 # provide timezone data, works only on linux
124 export TZDIR=${tzdata}/${python.sitePackages}/tzdata/zoneinfo
125
126 export PYTHONPATH=$PWD/docs/_ext:$PYTHONPATH
127 '';
128
129 checkPhase = ''
130 runHook preCheck
131
132 pushd tests
133 # without --parallel=1, tests fail with an "unexpected error due to a database lock" on Darwin
134 ${python.interpreter} runtests.py --settings=test_sqlite ${lib.optionalString stdenv.hostPlatform.isDarwin "--parallel=1"}
135 popd
136
137 runHook postCheck
138 '';
139
140 __darwinAllowLocalNetworking = true;
141
142 meta = with lib; {
143 changelog = "https://docs.djangoproject.com/en/${lib.versions.majorMinor version}/releases/${version}/";
144 description = "High-level Python Web framework that encourages rapid development and clean, pragmatic design";
145 homepage = "https://www.djangoproject.com";
146 license = licenses.bsd3;
147 maintainers = with maintainers; [ hexa ];
148 };
149}