python3Packages.tkinter: build standalone from python source tree

Why? python3Full must die.

Changed files
+106 -23
pkgs
development
python-modules
top-level
+82 -20
pkgs/development/python-modules/tkinter/default.nix
···
{
lib,
-
stdenv,
buildPythonPackage,
python,
-
py,
-
isPyPy,
}:
buildPythonPackage {
pname = "tkinter";
version = python.version;
-
src = py;
-
format = "other";
-
# tkinter is included in PyPy, making this package a no-op.
-
installPhase = lib.optionalString (!isPyPy) (
-
''
-
# Move the tkinter module
-
mkdir -p $out/${py.sitePackages}
-
mv lib/${py.libPrefix}/lib-dynload/_tkinter* $out/${py.sitePackages}/
-
''
-
+ lib.optionalString (!stdenv.hostPlatform.isDarwin) ''
-
# Update the rpath to point to python without x11Support
-
old_rpath=$(patchelf --print-rpath $out/${py.sitePackages}/_tkinter*)
-
new_rpath=$(sed "s#${py}#${python}#g" <<< "$old_rpath" )
-
patchelf --set-rpath $new_rpath $out/${py.sitePackages}/_tkinter*
-
''
-
);
-
meta = py.meta // {
# Based on first sentence from https://docs.python.org/3/library/tkinter.html
description = "Standard Python interface to the Tcl/Tk GUI toolkit";
longDescription = ''
···
these additions and changes, and refer to the official Tcl/Tk
documentation for details that are unchanged.
'';
};
}
···
{
lib,
buildPythonPackage,
+
replaceVars,
+
setuptools,
python,
+
pythonOlder,
+
tcl,
+
tclPackages,
+
tk,
+
tkinter,
+
xvfb-run,
}:
buildPythonPackage {
pname = "tkinter";
version = python.version;
+
pyproject = true;
+
+
src = python.src;
+
+
prePatch = ''
+
mkdir $NIX_BUILD_TOP/tkinter
+
+
# copy the module bits and pieces from the python source
+
cp -v Modules/{_tkinter.c,tkinter.h} ../tkinter/
+
cp -rv Modules/clinic ../tkinter/
+
cp -rv Lib/tkinter ../tkinter/
+
+
pushd $NIX_BUILD_TOP/tkinter
+
# install our custom pyproject.toml
+
cp ${
+
replaceVars ./pyproject.toml {
+
python_version = python.version;
+
python_internal_dir = "${python}/include/${python.libPrefix}/internal";
+
}
+
} ./pyproject.toml
+
''
+
+ lib.optionalString (pythonOlder "3.13") ''
+
substituteInPlace "tkinter/tix.py" --replace-fail \
+
"os.environ.get('TIX_LIBRARY')" \
+
"os.environ.get('TIX_LIBRARY') or '${tclPackages.tix}/lib'"
+
'';
+
+
build-system = [ setuptools ];
+
+
buildInputs = [
+
tcl
+
tk
+
];
+
+
env = {
+
TCLTK_LIBS = toString [
+
"-L${lib.getLib tcl}/lib"
+
"-L${lib.getLib tk}/lib"
+
"-l${tcl.libPrefix}"
+
"-l${tk.libPrefix}"
+
];
+
TCLTK_CFLAGS = toString [
+
"-I${lib.getDev tcl}/include"
+
"-I${lib.getDev tk}/include"
+
];
+
};
+
+
doCheck = false;
+
+
nativeCheckInputs = [ xvfb-run ];
+
+
preCheck = ''
+
cd $NIX_BUILD_TOP/Python-*/Lib
+
export HOME=$TMPDIR
+
'';
+
+
checkPhase = ''
+
runHook preCheck
+
xvfb-run -w 10 -s "-screen 0 1920x1080x24" \
+
python -m unittest test.test_tkinter
+
+
runHook postCheck
+
'';
+
+
passthru.tests.unittests = tkinter.overridePythonAttrs { doCheck = true; };
+
+
pythonImportsCheck = [ "tkinter" ];
+
+
meta = {
# Based on first sentence from https://docs.python.org/3/library/tkinter.html
description = "Standard Python interface to the Tcl/Tk GUI toolkit";
longDescription = ''
···
these additions and changes, and refer to the official Tcl/Tk
documentation for details that are unchanged.
'';
+
homepage = "https://docs.python.org/3/library/tkinter.html";
+
inherit (python.meta)
+
license
+
maintainers
+
;
};
}
+16
pkgs/development/python-modules/tkinter/pyproject.toml
···
···
+
[build-system]
+
requires = ["setuptools"]
+
build-backend = "setuptools.build_meta"
+
+
[project]
+
name = "tkinter"
+
version = "@python_version@"
+
description = "Tkinter."
+
requires-python = ">=@python_version@"
+
+
[tool.setuptools]
+
packages = ["tkinter"]
+
ext-modules = [
+
{ name = "_tkinter", sources = ["_tkinter.c"], libraries = ["tcl9.0", "tcl9tk9.0"], include-dirs = ["@python_internal_dir@/"] }
+
]
+
+8 -3
pkgs/top-level/python-packages.nix
···
tivars = callPackage ../development/python-modules/tivars { };
-
tkinter = callPackage ../development/python-modules/tkinter {
-
py = python.override (lib.optionalAttrs (!python.isPyPy) { x11Support = true; });
-
};
tkinter-gl = callPackage ../development/python-modules/tkinter-gl { };
···
tivars = callPackage ../development/python-modules/tivars { };
+
tkinter =
+
if isPyPy then
+
null
+
else
+
callPackage ../development/python-modules/tkinter {
+
tcl = pkgs.tcl-9_0;
+
tk = pkgs.tk-9_0;
+
};
tkinter-gl = callPackage ../development/python-modules/tkinter-gl { };