1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 fetchFromGitHub,
6 pythonAtLeast,
7 pythonOlder,
8 substituteAll,
9
10 # build
11 setuptools,
12
13 # patched in
14 geos,
15 gdal,
16 withGdal ? false,
17
18 # propagates
19 asgiref,
20 sqlparse,
21
22 # extras
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 = "4.2.12";
48 format = "pyproject";
49
50 disabled = pythonOlder "3.8";
51
52 src = fetchFromGitHub {
53 owner = "django";
54 repo = "django";
55 rev = "refs/tags/${version}";
56 hash = "sha256-n6esWUpZpCP4J4bNckNKJ9E61qFjTPS7XF+WgxNS2JE=";
57 };
58
59 patches =
60 [
61 (substituteAll {
62 src = ./django_4_set_zoneinfo_dir.patch;
63 zoneinfo = tzdata + "/share/zoneinfo";
64 })
65 # make sure the tests don't remove packages from our pythonpath
66 # and disable failing tests
67 ./django_4_tests.patch
68 ]
69 ++ lib.optionals withGdal [
70 (substituteAll {
71 src = ./django_4_set_geos_gdal_lib.patch;
72 geos = geos;
73 gdal = gdal;
74 extension = stdenv.hostPlatform.extensions.sharedLibrary;
75 })
76 ];
77
78 postPatch =
79 ''
80 substituteInPlace tests/utils_tests/test_autoreload.py \
81 --replace "/usr/bin/python" "${python.interpreter}"
82 ''
83 + lib.optionalString (pythonAtLeast "3.12" && stdenv.hostPlatform.system == "aarch64-linux") ''
84 # Test regression after xz was reverted from 5.6.0 to 5.4.6
85 # https://hydra.nixos.org/build/254630990
86 substituteInPlace tests/view_tests/tests/test_debug.py \
87 --replace-fail "test_files" "dont_test_files"
88 '';
89
90 nativeBuildInputs = [ setuptools ];
91
92 propagatedBuildInputs = [
93 asgiref
94 sqlparse
95 ];
96
97 passthru.optional-dependencies = {
98 argon2 = [ argon2-cffi ];
99 bcrypt = [ bcrypt ];
100 };
101
102 nativeCheckInputs = [
103 # tests/requirements/py3.txt
104 aiosmtpd
105 docutils
106 geoip2
107 jinja2
108 numpy
109 pillow
110 pylibmc
111 pymemcache
112 pywatchman
113 pyyaml
114 pytz
115 redis
116 selenium
117 tblib
118 tzdata
119 ] ++ lib.flatten (lib.attrValues passthru.optional-dependencies);
120
121 doCheck = !stdenv.isDarwin;
122
123 preCheck = ''
124 # make sure the installed library gets imported
125 rm -rf django
126
127 # provide timezone data, works only on linux
128 export TZDIR=${tzdata}/${python.sitePackages}/tzdata/zoneinfo
129 '';
130
131 checkPhase = ''
132 runHook preCheck
133
134 pushd tests
135 ${python.interpreter} runtests.py --settings=test_sqlite
136 popd
137
138 runHook postCheck
139 '';
140
141 __darwinAllowLocalNetworking = true;
142
143 meta = with lib; {
144 changelog = "https://docs.djangoproject.com/en/${lib.versions.majorMinor version}/releases/${version}/";
145 description = "A high-level Python Web framework that encourages rapid development and clean, pragmatic design.";
146 mainProgram = "django-admin";
147 homepage = "https://www.djangoproject.com";
148 license = licenses.bsd3;
149 maintainers = with maintainers; [ hexa ];
150 };
151}