nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 fetchFromGitHub,
6 fetchpatch,
7 pythonAtLeast,
8 replaceVars,
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.27";
48 pyproject = true;
49
50 disabled = pythonAtLeast "3.13";
51
52 src = fetchFromGitHub {
53 owner = "django";
54 repo = "django";
55 tag = version;
56 hash = "sha256-vdY85Ib2knRFLPmZZ6ojiD5R9diuvpVut1+nOVXSp0Y=";
57 };
58
59 patches = [
60 (replaceVars ./django_4_set_zoneinfo_dir.patch {
61 zoneinfo = tzdata + "/share/zoneinfo";
62 })
63 # make sure the tests don't remove packages from our pythonpath
64 # and disable failing tests
65 ./django_4_tests.patch
66
67 # fix filename length limit tests on bcachefs
68 # FIXME: remove if ever backported
69 (fetchpatch {
70 url = "https://github.com/django/django/commit/12f4f95405c7857cbf2f4bf4d0261154aac31676.patch";
71 hash = "sha256-+K20/V8sh036Ox9U7CSPgfxue7f28Sdhr3MsB7erVOk=";
72 })
73
74 # backport fix for https://code.djangoproject.com/ticket/36056
75 # FIXME: remove if ever backported upstream
76 (fetchpatch {
77 url = "https://github.com/django/django/commit/ec0e784f91b551c654f0962431cc31091926792d.patch";
78 includes = [ "django/*" ]; # tests don't apply
79 hash = "sha256-8YwdOBNJq6+GNoxzdLyN9HEEIWRXGQk9YbyfPwYVkwU=";
80 })
81
82 ]
83 ++ lib.optionals withGdal [
84 (replaceVars ./django_4_set_geos_gdal_lib.patch {
85 geos = geos;
86 gdal = gdal;
87 extension = stdenv.hostPlatform.extensions.sharedLibrary;
88 })
89 ];
90
91 postPatch = ''
92 substituteInPlace tests/utils_tests/test_autoreload.py \
93 --replace "/usr/bin/python" "${python.interpreter}"
94 ''
95 + lib.optionalString (pythonAtLeast "3.12" && stdenv.hostPlatform.system == "aarch64-linux") ''
96 # Test regression after xz was reverted from 5.6.0 to 5.4.6
97 # https://hydra.nixos.org/build/254630990
98 substituteInPlace tests/view_tests/tests/test_debug.py \
99 --replace-fail "test_files" "dont_test_files"
100 ''
101 + lib.optionalString (pythonAtLeast "3.13") ''
102 # Fixed CommandTypes.test_help_default_options_with_custom_arguments test on Python 3.13+.
103 # https://github.com/django/django/commit/3426a5c33c36266af42128ee9eca4921e68ea876
104 substituteInPlace tests/admin_scripts/tests.py --replace-fail \
105 "test_help_default_options_with_custom_arguments" \
106 "dont_test_help_default_options_with_custom_arguments"
107 '';
108
109 nativeBuildInputs = [ setuptools ];
110
111 propagatedBuildInputs = [
112 asgiref
113 sqlparse
114 ];
115
116 optional-dependencies = {
117 argon2 = [ argon2-cffi ];
118 bcrypt = [ bcrypt ];
119 };
120
121 nativeCheckInputs = [
122 # tests/requirements/py3.txt
123 aiosmtpd
124 docutils
125 geoip2
126 jinja2
127 numpy
128 pillow
129 pylibmc
130 pymemcache
131 pywatchman
132 pyyaml
133 pytz
134 redis
135 selenium
136 tblib
137 tzdata
138 ]
139 ++ lib.concatAttrValues optional-dependencies;
140
141 doCheck =
142 !stdenv.hostPlatform.isDarwin
143 # pywatchman depends on folly which does not support 32bits
144 && !stdenv.hostPlatform.is32bit;
145
146 preCheck = ''
147 # make sure the installed library gets imported
148 rm -rf django
149
150 # provide timezone data, works only on linux
151 export TZDIR=${tzdata}/${python.sitePackages}/tzdata/zoneinfo
152 '';
153
154 checkPhase = ''
155 runHook preCheck
156
157 pushd tests
158 ${python.interpreter} runtests.py --settings=test_sqlite
159 popd
160
161 runHook postCheck
162 '';
163
164 __darwinAllowLocalNetworking = true;
165
166 meta = {
167 changelog = "https://docs.djangoproject.com/en/${lib.versions.majorMinor version}/releases/${version}/";
168 description = "High-level Python Web framework that encourages rapid development and clean, pragmatic design";
169 mainProgram = "django-admin";
170 homepage = "https://www.djangoproject.com";
171 license = lib.licenses.bsd3;
172 maintainers = with lib.maintainers; [ hexa ];
173 };
174}