Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 40 additions & 17 deletions pkgs/development/python-modules/tkinter/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
lib,
stdenv,
buildPythonPackage,
replaceVars,
setuptools,
Expand All @@ -8,7 +9,6 @@
tcl,
tclPackages,
tk,
tkinter,
xvfb-run,
}:

Expand All @@ -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 = [
Expand All @@ -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" ];

Expand Down
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 1 addition & 2 deletions pkgs/development/python-modules/tkinter/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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@/"] }
]

7 changes: 5 additions & 2 deletions pkgs/top-level/python-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 { };
Expand Down
Loading