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