python313Packages.tkinter: fix build for python 3.10 and 3.11, enable tests (#442184)

This commit is contained in:
Martin Weinelt
2025-09-24 03:04:17 +02:00
committed by GitHub
4 changed files with 70 additions and 21 deletions
@@ -1,5 +1,6 @@
{
lib,
stdenv,
buildPythonPackage,
replaceVars,
setuptools,
@@ -8,7 +9,6 @@
tcl,
tclPackages,
tk,
tkinter,
xvfb-run,
}:
@@ -27,23 +27,28 @@ buildPythonPackage {
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
} $NIX_BUILD_TOP/tkinter/pyproject.toml
''
+ lib.optionalString (pythonOlder "3.13") ''
substituteInPlace "tkinter/tix.py" --replace-fail \
substituteInPlace "$NIX_BUILD_TOP/tkinter/tkinter/tix.py" --replace-fail \
"os.environ.get('TIX_LIBRARY')" \
"os.environ.get('TIX_LIBRARY') or '${tclPackages.tix}/lib'"
'';
# Adapted from https://github.com/python/cpython/pull/124542
patches = lib.optional (pythonOlder "3.12") ./fix-ttk-notebook-test.patch;
preConfigure = ''
pushd $NIX_BUILD_TOP/tkinter
'';
build-system = [ setuptools ];
buildInputs = [
@@ -64,24 +69,42 @@ buildPythonPackage {
];
};
doCheck = false;
nativeCheckInputs = [ xvfb-run ];
nativeCheckInputs = lib.optional stdenv.hostPlatform.isLinux 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; };
checkPhase =
let
testsNoGui = [
"test.test_tcl"
"test.test_ttk_textonly"
];
testsGui =
if pythonOlder "3.12" then
[
"test.test_tk"
"test.test_ttk_guionly"
]
else
[
"test.test_tkinter"
"test.test_ttk"
];
in
''
runHook preCheck
${python.interpreter} -m unittest ${lib.concatStringsSep " " testsNoGui}
''
+ lib.optionalString stdenv.hostPlatform.isLinux ''
xvfb-run -w 10 -s "-screen 0 1920x1080x24" \
${python.interpreter} -m unittest ${lib.concatStringsSep " " testsGui}
''
+ ''
runHook postCheck
'';
pythonImportsCheck = [ "tkinter" ];
@@ -0,0 +1,24 @@
--- a/Lib/tkinter/test/test_ttk/test_widgets.py
+++ b/Lib/tkinter/test/test_ttk/test_widgets.py
@@ -911,12 +911,20 @@ class ScrollbarTest(AbstractWidgetTest, unittest.TestCase):
return ttk.Scrollbar(self.root, **kwargs)
-@add_standard_options(IntegerSizeTests, StandardTtkOptionsTests)
+@add_standard_options(StandardTtkOptionsTests)
class NotebookTest(AbstractWidgetTest, unittest.TestCase):
OPTIONS = (
'class', 'cursor', 'height', 'padding', 'style', 'takefocus', 'width',
)
+ def test_configure_height(self):
+ widget = self.create()
+ self.checkPixelsParam(widget, 'height', '10c', 402, -402, 0, conv=False)
+
+ def test_configure_width(self):
+ widget = self.create()
+ self.checkPixelsParam(widget, 'width', '10c', 402, -402, 0, conv=False)
+
def setUp(self):
super().setUp()
self.nb = self.create(padding=0)
@@ -11,6 +11,5 @@ 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@/"] }
{ name = "_tkinter", sources = ["_tkinter.c"], libraries = ["tcl", "tk"], include-dirs = ["@python_internal_dir@/"] }
]
+5 -2
View File
@@ -18408,8 +18408,11 @@ self: super: with self; {
null
else
callPackage ../development/python-modules/tkinter {
tcl = pkgs.tcl-9_0;
tk = pkgs.tk-9_0;
# Tcl/Tk 9.0 support in Tkinter is not quite ready yet:
# - https://github.com/python/cpython/issues/124111
# - https://github.com/python/cpython/issues/104568
tcl = pkgs.tcl-8_6;
tk = pkgs.tk-8_6;
};
tkinter-gl = callPackage ../development/python-modules/tkinter-gl { };