1{ stdenv, fetchurl
2, glibc
3, bzip2
4, db
5, gdbm
6, libX11, xproto
7, lzma
8, ncurses
9, openssl
10, readline
11, sqlite
12, tcl, tk
13, zlib
14, callPackage
15, self
16, python36Packages
17
18, CF, configd
19}:
20
21assert readline != null -> ncurses != null;
22
23with stdenv.lib;
24
25let
26 majorVersion = "3.6";
27 pythonVersion = majorVersion;
28 version = "${majorVersion}.0a3";
29 fullVersion = "${version}";
30
31 buildInputs = filter (p: p != null) [
32 glibc
33 zlib
34 bzip2
35 lzma
36 gdbm
37 sqlite
38 db
39 readline
40 ncurses
41 openssl
42 tcl
43 tk
44 libX11
45 xproto
46 ] ++ optionals stdenv.isDarwin [ CF configd ];
47in
48stdenv.mkDerivation {
49 name = "python3-${fullVersion}";
50 pythonVersion = majorVersion;
51 inherit majorVersion version;
52
53 inherit buildInputs;
54
55 src = fetchurl {
56 url = "https://www.python.org/ftp/python/${majorVersion}.0/Python-${fullVersion}.tar.xz";
57 sha256 = "08c3598bwihibwca9lwxq923sjq9shvgv3wxv4vkga2n6hf63l1c";
58 };
59
60 NIX_LDFLAGS = optionalString stdenv.isLinux "-lgcc_s";
61
62 prePatch = optionalString stdenv.isDarwin ''
63 substituteInPlace configure --replace '`/usr/bin/arch`' '"i386"'
64 '';
65
66 preConfigure = ''
67 for i in /usr /sw /opt /pkg; do # improve purity
68 substituteInPlace ./setup.py --replace $i /no-such-path
69 done
70 ${optionalString stdenv.isDarwin ''
71 export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -msse2"
72 export MACOSX_DEPLOYMENT_TARGET=10.6
73 ''}
74
75 substituteInPlace ./Lib/plat-generic/regen --replace "/usr/include" ${glibc.dev}/include
76
77 configureFlagsArray=( --enable-shared --with-threads
78 CPPFLAGS="${concatStringsSep " " (map (p: "-I${getDev p}/include") buildInputs)}"
79 LDFLAGS="${concatStringsSep " " (map (p: "-L${getLib p}/lib") buildInputs)}"
80 LIBS="${optionalString (!stdenv.isDarwin) "-lcrypt"} ${optionalString (ncurses != null) "-lncurses"}"
81 )
82 '';
83
84 setupHook = ./setup-hook.sh;
85
86 postInstall = ''
87 # needed for some packages, especially packages that backport functionality
88 # to 2.x from 3.x
89 for item in $out/lib/python${majorVersion}/test/*; do
90 if [[ "$item" != */test_support.py* ]]; then
91 rm -rf "$item"
92 else
93 echo $item
94 fi
95 done
96 touch $out/lib/python${majorVersion}/test/__init__.py
97
98 ln -s "$out/include/python${majorVersion}m" "$out/include/python${majorVersion}"
99 paxmark E $out/bin/python${majorVersion}
100 '';
101
102 passthru = rec {
103 zlibSupport = zlib != null;
104 sqliteSupport = sqlite != null;
105 dbSupport = db != null;
106 readlineSupport = readline != null;
107 opensslSupport = openssl != null;
108 tkSupport = (tk != null) && (tcl != null) && (libX11 != null) && (xproto != null);
109 libPrefix = "python${majorVersion}";
110 executable = "python${majorVersion}m";
111 buildEnv = callPackage ../../wrapper.nix { python = self; };
112 withPackages = import ../../with-packages.nix { inherit buildEnv; pythonPackages = python36Packages; };
113 isPy3 = true;
114 isPy35 = true;
115 is_py3k = true; # deprecated
116 sitePackages = "lib/${libPrefix}/site-packages";
117 interpreter = "${self}/bin/${executable}";
118 };
119
120 enableParallelBuilding = true;
121
122 meta = {
123 homepage = http://python.org;
124 description = "A high-level dynamically-typed programming language";
125 longDescription = ''
126 Python is a remarkably powerful dynamic programming language that
127 is used in a wide variety of application domains. Some of its key
128 distinguishing features include: clear, readable syntax; strong
129 introspection capabilities; intuitive object orientation; natural
130 expression of procedural code; full modularity, supporting
131 hierarchical packages; exception-based error handling; and very
132 high level dynamic data types.
133 '';
134 license = licenses.psfl;
135 platforms = with platforms; linux ++ darwin;
136 maintainers = with maintainers; [ chaoflow domenkozar cstrahan kragniz ];
137 };
138}