diff --git a/pkgs/development/python-modules/tkinter/default.nix b/pkgs/development/python-modules/tkinter/default.nix index afc6d765a4986..233b2b2b0e4a9 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, @@ -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" ]; 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 0000000000000..cf2ca0f7acdfa --- /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) diff --git a/pkgs/development/python-modules/tkinter/pyproject.toml b/pkgs/development/python-modules/tkinter/pyproject.toml index 770331a7ef4f5..a53ccd8c72a28 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 9e7bfc8df7f13..e7e417363f0c8 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 { };