Unverified Commit 3b754e10 authored by Martin Weinelt's avatar Martin Weinelt Committed by GitHub
Browse files

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

parents eb95e93c 69b8cd94
Loading
Loading
Loading
Loading
+40 −17
Original line number Diff line number Diff line
{
  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,25 +69,43 @@ 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 = ''
  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 -m unittest test.test_tkinter

        ${python.interpreter} -m unittest ${lib.concatStringsSep " " testsGui}
    ''
    + ''
      runHook postCheck
    '';

  passthru.tests.unittests = tkinter.overridePythonAttrs { doCheck = true; };

  pythonImportsCheck = [ "tkinter" ];

  meta = {
+24 −0
Original line number Diff line number Diff line
--- 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)
+1 −2
Original line number Diff line number Diff line
@@ -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
Original line number Diff line number Diff line
@@ -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 { };