2014-10-12 14:58:07 +02:00
|
|
|
{ stdenv, fetchurl, zlib ? null, zlibSupport ? true, bzip2, includeModules ? false
|
2014-10-19 19:48:07 +02:00
|
|
|
, sqlite, tcl, tk, x11, openssl, readline, db, ncurses, gdbm, libX11, self, callPackage }:
|
2010-08-11 17:49:03 +02:00
|
|
|
|
|
|
|
assert zlibSupport -> zlib != null;
|
|
|
|
|
|
|
|
with stdenv.lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
majorVersion = "2.7";
|
2014-07-02 18:44:54 +02:00
|
|
|
version = "${majorVersion}.8";
|
2010-08-11 17:49:03 +02:00
|
|
|
|
|
|
|
src = fetchurl {
|
2014-02-20 00:44:27 +01:00
|
|
|
url = "http://www.python.org/ftp/python/${version}/Python-${version}.tar.xz";
|
2014-07-02 18:44:54 +02:00
|
|
|
sha256 = "0nh7d3dp75f1aj0pamn4hla8s0l7nbaq4a38brry453xrfh11ppd";
|
2010-08-11 17:49:03 +02:00
|
|
|
};
|
2011-05-05 16:41:08 +02:00
|
|
|
|
2011-01-04 15:47:36 +01:00
|
|
|
patches =
|
|
|
|
[ # Look in C_INCLUDE_PATH and LIBRARY_PATH for stuff.
|
|
|
|
./search-path.patch
|
2011-01-04 16:10:03 +01:00
|
|
|
|
|
|
|
# Python recompiles a Python if the mtime stored *in* the
|
|
|
|
# pyc/pyo file differs from the mtime of the source file. This
|
|
|
|
# doesn't work in Nix because Nix changes the mtime of files in
|
|
|
|
# the Nix store to 1. So treat that as a special case.
|
|
|
|
./nix-store-mtime.patch
|
2013-06-22 07:52:27 +02:00
|
|
|
|
|
|
|
# patch python to put zero timestamp into pyc
|
|
|
|
# if DETERMINISTIC_BUILD env var is set
|
|
|
|
./deterministic-build.patch
|
2010-08-11 17:49:03 +02:00
|
|
|
|
2014-09-30 09:37:19 +02:00
|
|
|
# http://bugs.python.org/issue21963
|
|
|
|
./remove-avoid-daemon-thread-shutdown.patch
|
2011-01-04 15:47:36 +01:00
|
|
|
];
|
2014-10-12 14:58:07 +02:00
|
|
|
|
|
|
|
preConfigure = ''
|
2011-05-05 16:41:15 +02:00
|
|
|
# Purity.
|
|
|
|
for i in /usr /sw /opt /pkg; do
|
|
|
|
substituteInPlace ./setup.py --replace $i /no-such-path
|
|
|
|
done
|
2014-10-12 14:58:07 +02:00
|
|
|
'' + optionalString (stdenv ? gcc && stdenv.gcc.libc != null) ''
|
|
|
|
for i in Lib/plat-*/regen; do
|
|
|
|
substituteInPlace $i --replace /usr/include/ ${stdenv.gcc.libc}/include/
|
|
|
|
done
|
|
|
|
'' + optionalString stdenv.isCygwin ''
|
|
|
|
# On Cygwin, `make install' tries to read this Makefile.
|
|
|
|
mkdir -p $out/lib/python${majorVersion}/config
|
|
|
|
touch $out/lib/python${majorVersion}/config/Makefile
|
|
|
|
mkdir -p $out/include/python${majorVersion}
|
|
|
|
touch $out/include/python${majorVersion}/pyconfig.h
|
2011-05-05 16:41:15 +02:00
|
|
|
'';
|
2011-05-05 16:41:08 +02:00
|
|
|
|
2014-10-12 14:58:07 +02:00
|
|
|
buildInputs =
|
|
|
|
optional (stdenv ? gcc && stdenv.gcc.libc != null) stdenv.gcc.libc ++
|
|
|
|
[ bzip2 openssl ] ++ optionals includeModules [ db openssl ncurses gdbm libX11 readline x11 tcl tk sqlite ]
|
|
|
|
++ optional zlibSupport zlib;
|
|
|
|
|
2011-03-28 11:48:57 +02:00
|
|
|
# Build the basic Python interpreter without modules that have
|
|
|
|
# external dependencies.
|
|
|
|
python = stdenv.mkDerivation {
|
|
|
|
name = "python-${version}";
|
2011-05-05 16:41:08 +02:00
|
|
|
|
2014-10-12 14:58:07 +02:00
|
|
|
inherit majorVersion version src patches buildInputs preConfigure;
|
2011-03-28 11:48:57 +02:00
|
|
|
|
2014-07-02 19:55:39 +02:00
|
|
|
LDFLAGS = stdenv.lib.optionalString (!stdenv.isDarwin) "-lgcc_s";
|
2011-03-28 11:48:57 +02:00
|
|
|
C_INCLUDE_PATH = concatStringsSep ":" (map (p: "${p}/include") buildInputs);
|
|
|
|
LIBRARY_PATH = concatStringsSep ":" (map (p: "${p}/lib") buildInputs);
|
|
|
|
|
2013-06-21 14:05:46 +02:00
|
|
|
configureFlags = "--enable-shared --with-threads --enable-unicode";
|
2011-03-28 11:48:57 +02:00
|
|
|
|
|
|
|
NIX_CFLAGS_COMPILE = optionalString stdenv.isDarwin "-msse2";
|
2014-04-09 01:04:50 +02:00
|
|
|
DETERMINISTIC_BUILD = 1;
|
2011-03-28 11:48:57 +02:00
|
|
|
|
|
|
|
setupHook = ./setup-hook.sh;
|
|
|
|
|
|
|
|
postInstall =
|
|
|
|
''
|
2014-10-23 12:07:07 +02:00
|
|
|
# needed for some packages, especially packages that backport
|
|
|
|
# functionality to 2.x from 3.x
|
|
|
|
for item in $out/lib/python${majorVersion}/test/*; do
|
|
|
|
if [[ "$item" != */test_support.py* ]]; then
|
|
|
|
rm -rf "$item"
|
|
|
|
else
|
|
|
|
echo $item
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
touch $out/lib/python${majorVersion}/test/__init__.py
|
2012-07-20 20:11:04 +02:00
|
|
|
ln -s $out/lib/python${majorVersion}/pdb.py $out/bin/pdb
|
|
|
|
ln -s $out/lib/python${majorVersion}/pdb.py $out/bin/pdb${majorVersion}
|
2012-12-22 03:26:19 +01:00
|
|
|
ln -s $out/share/man/man1/{python2.7.1.gz,python.1.gz}
|
2014-03-17 19:10:00 +01:00
|
|
|
|
|
|
|
paxmark E $out/bin/python${majorVersion}
|
2014-10-12 14:58:07 +02:00
|
|
|
|
|
|
|
${ optionalString includeModules "$out/bin/python ./setup.py build_ext"}
|
2011-03-28 11:48:57 +02:00
|
|
|
'';
|
|
|
|
|
2014-07-07 18:39:57 +02:00
|
|
|
passthru = rec {
|
2011-03-28 11:48:57 +02:00
|
|
|
inherit zlibSupport;
|
2014-07-09 17:34:08 +02:00
|
|
|
isPy2 = true;
|
|
|
|
isPy27 = true;
|
2014-10-19 19:48:07 +02:00
|
|
|
buildEnv = callPackage ../wrapper.nix { python = self; };
|
2011-03-28 11:48:57 +02:00
|
|
|
libPrefix = "python${majorVersion}";
|
2014-07-07 18:39:57 +02:00
|
|
|
executable = libPrefix;
|
|
|
|
sitePackages = "lib/${libPrefix}/site-packages";
|
2014-11-13 00:42:12 +01:00
|
|
|
interpreter = "${self}/bin/${executable}";
|
2011-03-28 11:48:57 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
enableParallelBuilding = true;
|
|
|
|
|
|
|
|
meta = {
|
|
|
|
homepage = "http://python.org";
|
2012-02-26 18:23:16 +01:00
|
|
|
description = "a high-level dynamically-typed programming language";
|
2011-03-28 11:48:57 +02:00
|
|
|
longDescription = ''
|
|
|
|
Python is a remarkably powerful dynamic programming language that
|
|
|
|
is used in a wide variety of application domains. Some of its key
|
|
|
|
distinguishing features include: clear, readable syntax; strong
|
|
|
|
introspection capabilities; intuitive object orientation; natural
|
|
|
|
expression of procedural code; full modularity, supporting
|
|
|
|
hierarchical packages; exception-based error handling; and very
|
|
|
|
high level dynamic data types.
|
|
|
|
'';
|
2012-02-26 18:23:16 +01:00
|
|
|
license = stdenv.lib.licenses.psfl;
|
2011-03-28 11:48:57 +02:00
|
|
|
platforms = stdenv.lib.platforms.all;
|
2014-10-12 14:58:07 +02:00
|
|
|
maintainers = with stdenv.lib.maintainers; [ simons chaoflow iElectric ];
|
2011-03-28 11:48:57 +02:00
|
|
|
};
|
|
|
|
};
|
2010-08-11 17:49:03 +02:00
|
|
|
|
|
|
|
|
2011-03-28 11:48:57 +02:00
|
|
|
# This function builds a Python module included in the main Python
|
|
|
|
# distribution in a separate derivation.
|
|
|
|
buildInternalPythonModule =
|
|
|
|
{ moduleName
|
|
|
|
, internalName ? "_" + moduleName
|
|
|
|
, deps
|
|
|
|
}:
|
2014-10-12 18:24:16 +02:00
|
|
|
if includeModules then null else stdenv.mkDerivation rec {
|
2011-03-28 11:48:57 +02:00
|
|
|
name = "python-${moduleName}-${python.version}";
|
|
|
|
|
2014-10-12 14:58:07 +02:00
|
|
|
inherit src patches preConfigure;
|
2011-03-28 11:48:57 +02:00
|
|
|
|
|
|
|
buildInputs = [ python ] ++ deps;
|
|
|
|
|
|
|
|
C_INCLUDE_PATH = concatStringsSep ":" (map (p: "${p}/include") buildInputs);
|
|
|
|
LIBRARY_PATH = concatStringsSep ":" (map (p: "${p}/lib") buildInputs);
|
|
|
|
|
2014-10-12 14:58:07 +02:00
|
|
|
buildPhase = ''
|
2011-03-28 11:48:57 +02:00
|
|
|
substituteInPlace setup.py --replace 'self.extensions = extensions' \
|
|
|
|
'self.extensions = [ext for ext in self.extensions if ext.name in ["${internalName}"]]'
|
|
|
|
|
|
|
|
python ./setup.py build_ext
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase =
|
|
|
|
''
|
|
|
|
dest=$out/lib/${python.libPrefix}/site-packages
|
|
|
|
mkdir -p $dest
|
2011-04-05 16:29:11 +02:00
|
|
|
cp -p $(find . -name "*.${if stdenv.isCygwin then "dll" else "so"}") $dest/
|
2011-03-28 11:48:57 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
# The Python modules included in the main Python distribution, built
|
|
|
|
# as separate derivations.
|
|
|
|
modules = {
|
|
|
|
|
|
|
|
bsddb = buildInternalPythonModule {
|
|
|
|
moduleName = "bsddb";
|
2014-01-31 21:05:37 +01:00
|
|
|
deps = [ db ];
|
2011-03-28 11:48:57 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
curses = buildInternalPythonModule {
|
|
|
|
moduleName = "curses";
|
|
|
|
deps = [ ncurses ];
|
|
|
|
};
|
|
|
|
|
2013-10-18 09:11:47 +02:00
|
|
|
curses_panel = buildInternalPythonModule {
|
|
|
|
moduleName = "curses_panel";
|
|
|
|
deps = [ ncurses modules.curses ];
|
|
|
|
};
|
|
|
|
|
2013-08-13 11:13:59 +02:00
|
|
|
crypt = buildInternalPythonModule {
|
|
|
|
moduleName = "crypt";
|
|
|
|
internalName = "crypt";
|
|
|
|
deps = [ ];
|
|
|
|
};
|
|
|
|
|
2011-03-28 11:48:57 +02:00
|
|
|
gdbm = buildInternalPythonModule {
|
|
|
|
moduleName = "gdbm";
|
|
|
|
internalName = "gdbm";
|
|
|
|
deps = [ gdbm ];
|
|
|
|
};
|
|
|
|
|
|
|
|
sqlite3 = buildInternalPythonModule {
|
|
|
|
moduleName = "sqlite3";
|
|
|
|
deps = [ sqlite ];
|
|
|
|
};
|
|
|
|
|
|
|
|
tkinter = buildInternalPythonModule {
|
|
|
|
moduleName = "tkinter";
|
2013-06-30 01:49:55 +02:00
|
|
|
deps = [ tcl tk x11 libX11 ];
|
2011-03-28 11:48:57 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
readline = buildInternalPythonModule {
|
|
|
|
moduleName = "readline";
|
|
|
|
internalName = "readline";
|
|
|
|
deps = [ readline ];
|
|
|
|
};
|
2010-08-11 17:49:03 +02:00
|
|
|
|
|
|
|
};
|
2011-05-05 16:41:08 +02:00
|
|
|
|
2011-03-28 11:48:57 +02:00
|
|
|
in python // { inherit modules; }
|