From 6747987a9f6c9312a3297e17fc31707443c11857 Mon Sep 17 00:00:00 2001 From: Tom Hunze Date: Thu, 11 Sep 2025 21:00:31 +0200 Subject: [PATCH 1/5] python313Packages.tkinter: revert to building with tcl 8.6 Tcl 9.0 support in Tkinter is not quite there yet [1]. There is ongoing work on improving support, though. This fixes the build of `python310Packages.tkinter` and `python311Packages.tkinter`. [1] https://github.com/python/cpython/issues/124111 --- pkgs/development/python-modules/tkinter/pyproject.toml | 3 +-- pkgs/top-level/python-packages.nix | 7 +++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/pkgs/development/python-modules/tkinter/pyproject.toml b/pkgs/development/python-modules/tkinter/pyproject.toml index 770331a7ef4f..a53ccd8c72a2 100644 --- a/pkgs/development/python-modules/tkinter/pyproject.toml +++ b/pkgs/development/python-modules/tkinter/pyproject.toml @@ -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@/"] } ] - diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index 9e7bfc8df7f1..e7e417363f0c 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -18388,8 +18388,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 { }; From 0ff96eca9b5e0a70e4c7b2ea3d8788605ddd3285 Mon Sep 17 00:00:00 2001 From: Tom Hunze Date: Thu, 11 Sep 2025 21:04:05 +0200 Subject: [PATCH 2/5] python313Packages.tkinter: enable tests by default --- pkgs/development/python-modules/tkinter/default.nix | 5 ----- 1 file changed, 5 deletions(-) diff --git a/pkgs/development/python-modules/tkinter/default.nix b/pkgs/development/python-modules/tkinter/default.nix index afc6d765a498..548c36625c4d 100644 --- a/pkgs/development/python-modules/tkinter/default.nix +++ b/pkgs/development/python-modules/tkinter/default.nix @@ -8,7 +8,6 @@ tcl, tclPackages, tk, - tkinter, xvfb-run, }: @@ -64,8 +63,6 @@ buildPythonPackage { ]; }; - doCheck = false; - nativeCheckInputs = [ xvfb-run ]; preCheck = '' @@ -81,8 +78,6 @@ buildPythonPackage { runHook postCheck ''; - passthru.tests.unittests = tkinter.overridePythonAttrs { doCheck = true; }; - pythonImportsCheck = [ "tkinter" ]; meta = { From d4b01227d4fdeacb65a00d18f42186191e90e02f Mon Sep 17 00:00:00 2001 From: Tom Hunze Date: Thu, 11 Sep 2025 21:10:04 +0200 Subject: [PATCH 3/5] python313Packages.tkinter: enable tests for tcl and ttk --- pkgs/development/python-modules/tkinter/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/development/python-modules/tkinter/default.nix b/pkgs/development/python-modules/tkinter/default.nix index 548c36625c4d..560ebf766649 100644 --- a/pkgs/development/python-modules/tkinter/default.nix +++ b/pkgs/development/python-modules/tkinter/default.nix @@ -73,7 +73,7 @@ buildPythonPackage { checkPhase = '' runHook preCheck xvfb-run -w 10 -s "-screen 0 1920x1080x24" \ - python -m unittest test.test_tkinter + python -m unittest test.test_tcl test.test_tkinter test.test_ttk test.test_ttk_textonly runHook postCheck ''; From 829b86801b3e432e466559a4cd0a8c652d461be5 Mon Sep 17 00:00:00 2001 From: Tom Hunze Date: Thu, 11 Sep 2025 22:12:15 +0200 Subject: [PATCH 4/5] python313Packages.tkinter: fix test selection for darwin, older python https://github.com/python/cpython/pull/94070 --- .../python-modules/tkinter/default.nix | 39 +++++++++++++++---- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/pkgs/development/python-modules/tkinter/default.nix b/pkgs/development/python-modules/tkinter/default.nix index 560ebf766649..8d5807493977 100644 --- a/pkgs/development/python-modules/tkinter/default.nix +++ b/pkgs/development/python-modules/tkinter/default.nix @@ -1,5 +1,6 @@ { lib, + stdenv, buildPythonPackage, replaceVars, setuptools, @@ -63,20 +64,42 @@ buildPythonPackage { ]; }; - 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_tcl test.test_tkinter test.test_ttk test.test_ttk_textonly - - runHook postCheck - ''; + checkPhase = + let + testsNoGui = [ + "test.test_tcl" + "test.test_ttk_textonly" + ]; + testsGui = + if pythonOlder "3.12" then + [ + "test.test_tk" + # "test.test_ttk_guionly" # https://github.com/python/cpython/issues/124378 + ] + 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" ]; From 69b8cd945c645230ddf909784973d6c2136fac40 Mon Sep 17 00:00:00 2001 From: Tom Hunze Date: Fri, 12 Sep 2025 14:15:21 +0200 Subject: [PATCH 5/5] python313Packages.tkinter: patch failing ttk test for python <3.12 https://github.com/python/cpython/issues/124378 https://github.com/python/cpython/pull/124542 --- .../python-modules/tkinter/default.nix | 15 ++++++++---- .../tkinter/fix-ttk-notebook-test.patch | 24 +++++++++++++++++++ 2 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 pkgs/development/python-modules/tkinter/fix-ttk-notebook-test.patch diff --git a/pkgs/development/python-modules/tkinter/default.nix b/pkgs/development/python-modules/tkinter/default.nix index 8d5807493977..233b2b2b0e4a 100644 --- a/pkgs/development/python-modules/tkinter/default.nix +++ b/pkgs/development/python-modules/tkinter/default.nix @@ -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 = [ @@ -81,7 +86,7 @@ buildPythonPackage { if pythonOlder "3.12" then [ "test.test_tk" - # "test.test_ttk_guionly" # https://github.com/python/cpython/issues/124378 + "test.test_ttk_guionly" ] else [ diff --git a/pkgs/development/python-modules/tkinter/fix-ttk-notebook-test.patch b/pkgs/development/python-modules/tkinter/fix-ttk-notebook-test.patch new file mode 100644 index 000000000000..cf2ca0f7acdf --- /dev/null +++ b/pkgs/development/python-modules/tkinter/fix-ttk-notebook-test.patch @@ -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)