Python 2.7: separate output for tkinter

This commit is contained in:
Frederik Rietdijk 2016-10-06 18:44:07 +02:00
parent 1f72d9c424
commit bee439207b
2 changed files with 32 additions and 112 deletions

View File

@ -1,8 +1,5 @@
{ stdenv, fetchurl, fetchpatch, self, callPackage, python27Packages { stdenv, fetchurl, fetchpatch, self, callPackage, python27Packages
, bzip2, openssl, gettext , bzip2, openssl, gettext
, includeModules ? false
, db, gdbm, ncurses, sqlite, readline , db, gdbm, ncurses, sqlite, readline
, tcl ? null, tk ? null, xlibsWrapper ? null, libX11 ? null, x11Support ? !stdenv.isCygwin , tcl ? null, tk ? null, xlibsWrapper ? null, libX11 ? null, x11Support ? !stdenv.isCygwin
@ -27,6 +24,7 @@ let
pythonVersion = majorVersion; pythonVersion = majorVersion;
version = "${majorVersion}.${minorVersion}${minorVersionSuffix}"; version = "${majorVersion}.${minorVersion}${minorVersionSuffix}";
libPrefix = "python${majorVersion}"; libPrefix = "python${majorVersion}";
sitePackages = "lib/${libPrefix}/site-packages";
src = fetchurl { src = fetchurl {
url = "https://www.python.org/ftp/python/${majorVersion}.${minorVersion}/Python-${version}.tar.xz"; url = "https://www.python.org/ftp/python/${majorVersion}.${minorVersion}/Python-${version}.tar.xz";
@ -113,10 +111,8 @@ let
optional (stdenv ? cc && stdenv.cc.libc != null) stdenv.cc.libc ++ optional (stdenv ? cc && stdenv.cc.libc != null) stdenv.cc.libc ++
[ bzip2 openssl ] [ bzip2 openssl ]
++ optionals stdenv.isCygwin [ expat libffi ] ++ optionals stdenv.isCygwin [ expat libffi ]
++ optionals includeModules ( ++ [ db gdbm ncurses sqlite readline ]
[ db gdbm ncurses sqlite readline ++ optionals x11Support [ tcl tk xlibsWrapper libX11 ]
] ++ optionals x11Support [ tcl tk xlibsWrapper libX11 ]
)
++ optional zlibSupport zlib ++ optional zlibSupport zlib
++ optional stdenv.isDarwin CF; ++ optional stdenv.isDarwin CF;
@ -129,7 +125,8 @@ let
# Build the basic Python interpreter without modules that have # Build the basic Python interpreter without modules that have
# external dependencies. # external dependencies.
python = stdenv.mkDerivation {
in stdenv.mkDerivation {
name = "python-${version}"; name = "python-${version}";
pythonVersion = majorVersion; pythonVersion = majorVersion;
@ -165,20 +162,25 @@ let
# Python on Nix is not manylinux1 compatible. https://github.com/NixOS/nixpkgs/issues/18484 # Python on Nix is not manylinux1 compatible. https://github.com/NixOS/nixpkgs/issues/18484
echo "manylinux1_compatible=False" >> $out/lib/${libPrefix}/_manylinux.py echo "manylinux1_compatible=False" >> $out/lib/${libPrefix}/_manylinux.py
${optionalString includeModules "$out/bin/python ./setup.py build_ext"}
rm "$out"/lib/python*/plat-*/regen # refers to glibc.dev rm "$out"/lib/python*/plat-*/regen # refers to glibc.dev
''; '';
postFixup = optionalString x11Support ''
# tkinter goes in a separate output
mkdir -p $tkinter/${sitePackages}
mv $out/lib/${libPrefix}/lib-dynload/_tkinter* $tkinter/${sitePackages}/
'';
outputs = ["out"] ++ optional x11Support "tkinter";
passthru = rec { passthru = rec {
inherit libPrefix; inherit libPrefix sitePackages;
inherit zlibSupport; inherit zlibSupport;
isPy2 = true; isPy2 = true;
isPy27 = true; isPy27 = true;
buildEnv = callPackage ../../wrapper.nix { python = self; }; buildEnv = callPackage ../../wrapper.nix { python = self; };
withPackages = import ../../with-packages.nix { inherit buildEnv; pythonPackages = python27Packages; }; withPackages = import ../../with-packages.nix { inherit buildEnv; pythonPackages = python27Packages; };
executable = libPrefix; executable = libPrefix;
sitePackages = "lib/${libPrefix}/site-packages";
interpreter = "${self}/bin/${executable}"; interpreter = "${self}/bin/${executable}";
}; };
@ -200,99 +202,4 @@ let
platforms = stdenv.lib.platforms.all; platforms = stdenv.lib.platforms.all;
maintainers = with stdenv.lib.maintainers; [ chaoflow domenkozar ]; maintainers = with stdenv.lib.maintainers; [ chaoflow domenkozar ];
}; };
}; }
# This function builds a Python module included in the main Python
# distribution in a separate derivation.
buildInternalPythonModule =
{ moduleName
, internalName ? "_" + moduleName
, deps
}:
if includeModules then null else stdenv.mkDerivation rec {
name = "python-${moduleName}-${python.version}";
inherit src patches preConfigure postConfigure configureFlags;
buildInputs = [ python ] ++ deps;
# We need to set this for python.buildEnv
pythonPath = [];
inherit (mkPaths buildInputs) C_INCLUDE_PATH LIBRARY_PATH;
# non-python gdbm has a libintl dependency on i686-cygwin, not on x86_64-cygwin
buildPhase = (if (stdenv.system == "i686-cygwin" && moduleName == "gdbm") then ''
sed -i setup.py -e "s:libraries = \['gdbm'\]:libraries = ['gdbm', 'intl']:"
'' else '''') + ''
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
[ -z "$(find build -name '*_failed.so' -print)" ]
'';
installPhase =
''
dest=$out/lib/${python.libPrefix}/site-packages
mkdir -p $dest
cp -p $(find . -name "*.${if stdenv.isCygwin then "dll" else "so"}") $dest/
'';
};
# The Python modules included in the main Python distribution, built
# as separate derivations.
modules = {
bsddb = buildInternalPythonModule {
moduleName = "bsddb";
deps = [ db ];
};
curses = buildInternalPythonModule {
moduleName = "curses";
deps = [ ncurses ];
};
curses_panel = buildInternalPythonModule {
moduleName = "curses_panel";
deps = [ ncurses modules.curses ];
};
crypt = buildInternalPythonModule {
moduleName = "crypt";
internalName = "crypt";
deps = optional (stdenv ? glibc) stdenv.glibc;
};
gdbm = buildInternalPythonModule {
moduleName = "gdbm";
internalName = "gdbm";
deps = [ gdbm ] ++ stdenv.lib.optional stdenv.isCygwin gettext;
};
sqlite3 = buildInternalPythonModule {
moduleName = "sqlite3";
deps = [ sqlite ];
};
} // optionalAttrs x11Support {
tkinter = if stdenv.isCygwin then null else (buildInternalPythonModule {
moduleName = "tkinter";
deps = [ tcl tk xlibsWrapper libX11 ];
});
} // {
readline = buildInternalPythonModule {
moduleName = "readline";
internalName = "readline";
deps = [ readline ];
};
};
in python // { inherit modules; }

View File

@ -1659,6 +1659,7 @@ in
fontforge = lowPrio (callPackage ../tools/misc/fontforge { fontforge = lowPrio (callPackage ../tools/misc/fontforge {
inherit (darwin.apple_sdk.frameworks) Carbon Cocoa; inherit (darwin.apple_sdk.frameworks) Carbon Cocoa;
python = pythonSmall;
}); });
fontforge-gtk = callPackage ../tools/misc/fontforge { fontforge-gtk = callPackage ../tools/misc/fontforge {
withGTK = true; withGTK = true;
@ -5494,6 +5495,11 @@ in
python2 = python27; python2 = python27;
python3 = python35; python3 = python35;
# Python uses multiple outputs, and by default `python` is without X11/tkinter.
# This package only exists to prevent an infinite recursion and should only be used
# for packages Python itself depends on.
pythonSmall = python.override {x11Support = false;};
# pythonPackages further below, but assigned here because they need to be in sync # pythonPackages further below, but assigned here because they need to be in sync
pythonPackages = python2Packages; pythonPackages = python2Packages;
python2Packages = python27Packages; python2Packages = python27Packages;
@ -7143,7 +7149,9 @@ in
gtkmathview = callPackage ../development/libraries/gtkmathview { }; gtkmathview = callPackage ../development/libraries/gtkmathview { };
glib = callPackage ../development/libraries/glib { }; glib = callPackage ../development/libraries/glib {
python = pythonSmall;
};
glib-tested = glib.override { # checked version separate to break cycles glib-tested = glib.override { # checked version separate to break cycles
doCheck = true; doCheck = true;
libffi = libffi.override { doCheck = true; }; libffi = libffi.override { doCheck = true; };
@ -8262,7 +8270,9 @@ in
libxmi = callPackage ../development/libraries/libxmi { }; libxmi = callPackage ../development/libraries/libxmi { };
libxml2 = callPackage ../development/libraries/libxml2 { }; libxml2 = callPackage ../development/libraries/libxml2 {
python = pythonSmall;
};
libxml2Python = pkgs.buildEnv { # slightly hacky libxml2Python = pkgs.buildEnv { # slightly hacky
name = "libxml2+py-${self.libxml2.version}"; name = "libxml2+py-${self.libxml2.version}";
paths = with libxml2; [ dev bin py ]; paths = with libxml2; [ dev bin py ];
@ -10345,11 +10355,12 @@ in
inherit clangStdenv fetchurl fetchgit fetchpatch stdenv pkgconfig intltool freetype fontconfig inherit clangStdenv fetchurl fetchgit fetchpatch stdenv pkgconfig intltool freetype fontconfig
libxslt expat libpng zlib perl mesa_drivers spice_protocol libunwind libxslt expat libpng zlib perl mesa_drivers spice_protocol libunwind
dbus libuuid openssl gperf m4 libevdev tradcpp libinput mcpp makeWrapper autoreconfHook dbus libuuid openssl gperf m4 libevdev tradcpp libinput mcpp makeWrapper autoreconfHook
autoconf automake libtool xmlto asciidoc flex bison python mtdev pixman autoconf automake libtool xmlto asciidoc flex bison mtdev pixman
cairo epoxy; cairo epoxy;
inherit (darwin) apple_sdk cf-private libobjc; inherit (darwin) apple_sdk cf-private libobjc;
bootstrap_cmds = if stdenv.isDarwin then darwin.bootstrap_cmds else null; bootstrap_cmds = if stdenv.isDarwin then darwin.bootstrap_cmds else null;
mesa = mesa_noglu; mesa = mesa_noglu;
python = pythonSmall;
udev = if stdenv.isLinux then udev else null; udev = if stdenv.isLinux then udev else null;
libdrm = if stdenv.isLinux then libdrm else null; libdrm = if stdenv.isLinux then libdrm else null;
fglrxCompat = config.xorg.fglrxCompat or false; # `config` because we have no `xorg.override` fglrxCompat = config.xorg.fglrxCompat or false; # `config` because we have no `xorg.override`
@ -11502,7 +11513,9 @@ in
bgnet = callPackage ../data/documentation/bgnet { }; bgnet = callPackage ../data/documentation/bgnet { };
cacert = callPackage ../data/misc/cacert { }; cacert = callPackage ../data/misc/cacert {
python = pythonSmall;
};
caladea = callPackage ../data/fonts/caladea {}; caladea = callPackage ../data/fonts/caladea {};