nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 replaceVars,
6 setuptools,
7 python,
8 pythonOlder,
9 tcl,
10 tclPackages,
11 tk,
12 xvfb-run,
13}:
14
15buildPythonPackage {
16 pname = "tkinter";
17 version = python.version;
18 pyproject = true;
19
20 src = python.src;
21
22 prePatch = ''
23 mkdir $NIX_BUILD_TOP/tkinter
24
25 # copy the module bits and pieces from the python source
26 cp -v Modules/{_tkinter.c,tkinter.h} ../tkinter/
27 cp -rv Modules/clinic ../tkinter/
28 cp -rv Lib/tkinter ../tkinter/
29
30 # install our custom pyproject.toml
31 cp ${
32 replaceVars ./pyproject.toml {
33 python_version = python.version;
34 python_internal_dir = "${python}/include/${python.libPrefix}/internal";
35 }
36 } $NIX_BUILD_TOP/tkinter/pyproject.toml
37
38 ''
39 + lib.optionalString (pythonOlder "3.13") ''
40 substituteInPlace "$NIX_BUILD_TOP/tkinter/tkinter/tix.py" --replace-fail \
41 "os.environ.get('TIX_LIBRARY')" \
42 "os.environ.get('TIX_LIBRARY') or '${tclPackages.tix}/lib'"
43 '';
44
45 # Adapted from https://github.com/python/cpython/pull/124542
46 patches = lib.optional (pythonOlder "3.12") ./fix-ttk-notebook-test.patch;
47
48 preConfigure = ''
49 pushd $NIX_BUILD_TOP/tkinter
50 '';
51
52 build-system = [ setuptools ];
53
54 buildInputs = [
55 tcl
56 tk
57 ];
58
59 env = {
60 TCLTK_LIBS = toString [
61 "-L${lib.getLib tcl}/lib"
62 "-L${lib.getLib tk}/lib"
63 "-l${tcl.libPrefix}"
64 "-l${tk.libPrefix}"
65 ];
66 TCLTK_CFLAGS = toString [
67 "-I${lib.getDev tcl}/include"
68 "-I${lib.getDev tk}/include"
69 ];
70 };
71
72 nativeCheckInputs = lib.optional stdenv.hostPlatform.isLinux xvfb-run;
73
74 preCheck = ''
75 cd $NIX_BUILD_TOP/Python-*/Lib
76 export HOME=$TMPDIR
77 '';
78
79 checkPhase =
80 let
81 testsNoGui = [
82 "test.test_tcl"
83 "test.test_ttk_textonly"
84 ];
85 testsGui =
86 if pythonOlder "3.12" then
87 [
88 "test.test_tk"
89 "test.test_ttk_guionly"
90 ]
91 else
92 [
93 "test.test_tkinter"
94 "test.test_ttk"
95 ];
96 in
97 ''
98 runHook preCheck
99 ${python.interpreter} -m unittest ${lib.concatStringsSep " " testsNoGui}
100 ''
101 + lib.optionalString stdenv.hostPlatform.isLinux ''
102 xvfb-run -w 10 -s "-screen 0 1920x1080x24" \
103 ${python.interpreter} -m unittest ${lib.concatStringsSep " " testsGui}
104 ''
105 + ''
106 runHook postCheck
107 '';
108
109 pythonImportsCheck = [ "tkinter" ];
110
111 meta = {
112 # Based on first sentence from https://docs.python.org/3/library/tkinter.html
113 description = "Standard Python interface to the Tcl/Tk GUI toolkit";
114 longDescription = ''
115 The tkinter package (“Tk interface”) is the standard Python interface to
116 the Tcl/Tk GUI toolkit. Both Tk and tkinter are available on most Unix
117 platforms, including macOS, as well as on Windows systems.
118
119 Running python -m tkinter from the command line should open a window
120 demonstrating a simple Tk interface, letting you know that tkinter is
121 properly installed on your system, and also showing what version of
122 Tcl/Tk is installed, so you can read the Tcl/Tk documentation specific to
123 that version.
124
125 Tkinter supports a range of Tcl/Tk versions, built either with or without
126 thread support. The official Python binary release bundles Tcl/Tk 8.6
127 threaded. See the source code for the _tkinter module for more
128 information about supported versions.
129
130 Tkinter is not a thin wrapper, but adds a fair amount of its own logic to
131 make the experience more pythonic. This documentation will concentrate on
132 these additions and changes, and refer to the official Tcl/Tk
133 documentation for details that are unchanged.
134 '';
135 homepage = "https://docs.python.org/3/library/tkinter.html";
136 inherit (python.meta)
137 license
138 maintainers
139 ;
140 };
141}