diff options
| author | Ricardo Wurmus <rekado@elephly.net> | 2025-01-23 10:39:59 +0100 |
|---|---|---|
| committer | Andreas Enge <andreas@enge.fr> | 2025-04-16 11:46:07 +0200 |
| commit | fb4f9823fb42e05c3c399cf61631e0b0af4643c6 (patch) | |
| tree | 66917f0649b1cd2de3a4fa8300434d39e480c5d2 /gnu/packages/python.scm | |
| parent | 79904458f9b33298c9c591e6aa6e6bafe18f6f24 (diff) | |
gnu: Add python-3.11.
* gnu/packages/patches/python-3.11-fix-tests.patch: New file.
* gnu/local.mk (dist_patch_DATA): Add patch.
* gnu/packages/python.scm (python-3.11): New variable.
Co-authored-by: Tanguy Le Carrour <tanguy@bioneland.org>.
Change-Id: I4a05f75d7b8867166ab91e983abff1a99cd7c80e
Diffstat (limited to 'gnu/packages/python.scm')
| -rw-r--r-- | gnu/packages/python.scm | 378 |
1 files changed, 378 insertions, 0 deletions
diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm index c5f98c3a46f..27b416219de 100644 --- a/gnu/packages/python.scm +++ b/gnu/packages/python.scm | |||
| @@ -660,6 +660,384 @@ def contents() -> str: | |||
| 660 | (variable "PYTHONTZPATH") | 660 | (variable "PYTHONTZPATH") |
| 661 | (files (list "share/zoneinfo"))))))) | 661 | (files (list "share/zoneinfo"))))))) |
| 662 | 662 | ||
| 663 | (define-public python-3.11 | ||
| 664 | (package | ||
| 665 | (inherit python-3.10) | ||
| 666 | (name "python") | ||
| 667 | (version "3.11.11") | ||
| 668 | (source (origin | ||
| 669 | (method url-fetch) | ||
| 670 | (uri (string-append "https://www.python.org/ftp/python/" | ||
| 671 | version "/Python-" version ".tar.xz")) | ||
| 672 | (patches (search-patches | ||
| 673 | "python-3-deterministic-build-info.patch" | ||
| 674 | "python-3.11-fix-tests.patch" | ||
| 675 | "python-3-hurd-configure.patch" | ||
| 676 | "python-3-search-paths.patch")) | ||
| 677 | (sha256 | ||
| 678 | (base32 | ||
| 679 | "1qrvsxg5g0b0pgz2iigxic2j3g6b2c59iva46vins8ydl33j169a")) | ||
| 680 | (modules '((guix build utils))) | ||
| 681 | (snippet | ||
| 682 | '(begin | ||
| 683 | ;; Delete the bundled copy of libexpat. | ||
| 684 | (delete-file-recursively "Modules/expat") | ||
| 685 | (substitute* "Modules/Setup" | ||
| 686 | ;; Link Expat instead of embedding the bundled one. | ||
| 687 | (("^#pyexpat.*") "pyexpat pyexpat.c -lexpat\n")) | ||
| 688 | ;; Delete windows binaries | ||
| 689 | (for-each delete-file | ||
| 690 | (find-files "Lib/distutils/command" "\\.exe$")))))) | ||
| 691 | (arguments | ||
| 692 | (list | ||
| 693 | #:test-target "test" | ||
| 694 | #:configure-flags | ||
| 695 | #~(list "--enable-shared" ;allow embedding | ||
| 696 | "--with-system-expat" ;for XML support | ||
| 697 | "--with-system-ffi" ;build ctypes | ||
| 698 | "--with-ensurepip=install" ;install pip and setuptools | ||
| 699 | "--with-computed-gotos" ;main interpreter loop optimization | ||
| 700 | "--enable-unicode=ucs4" | ||
| 701 | "--without-static-libpython" | ||
| 702 | "--enable-loadable-sqlite-extensions" | ||
| 703 | |||
| 704 | ;; FIXME: These flags makes Python significantly faster, | ||
| 705 | ;; but leads to non-reproducible binaries. | ||
| 706 | ;; "--with-lto" ;increase size by 20MB, but 15% speedup | ||
| 707 | ;; "--enable-optimizations" | ||
| 708 | |||
| 709 | ;; Prevent the installed _sysconfigdata.py from retaining | ||
| 710 | ;; a reference to coreutils. | ||
| 711 | "INSTALL=install -c" | ||
| 712 | "MKDIR_P=mkdir -p" | ||
| 713 | |||
| 714 | ;; Disable runtime check failing if cross-compiling, see: | ||
| 715 | ;; https://lists.yoctoproject.org/pipermail/poky/2013-June/008997.html | ||
| 716 | #$@(if (%current-target-system) | ||
| 717 | '("ac_cv_buggy_getaddrinfo=no" | ||
| 718 | "ac_cv_file__dev_ptmx=no" | ||
| 719 | "ac_cv_file__dev_ptc=no") | ||
| 720 | '()) | ||
| 721 | ;; -fno-semantic-interposition reinstates some | ||
| 722 | ;; optimizations by gcc leading to around 15% speedup. | ||
| 723 | ;; This is the default starting from python 3.10. | ||
| 724 | "CFLAGS=-fno-semantic-interposition" | ||
| 725 | (string-append "LDFLAGS=-Wl,-rpath=" #$output "/lib" | ||
| 726 | " -fno-semantic-interposition")) | ||
| 727 | ;; With no -j argument tests use all available cpus, so provide one. | ||
| 728 | #:make-flags | ||
| 729 | `(list (string-append (format #f "TESTOPTS=-j~d" | ||
| 730 | (parallel-job-count)) | ||
| 731 | ;; those tests fail on low-memory systems | ||
| 732 | " --exclude" | ||
| 733 | " test_mmap" | ||
| 734 | " test_socket" | ||
| 735 | " test_threading" | ||
| 736 | " test_asyncio" | ||
| 737 | " test_shutdown" | ||
| 738 | ,@(if (system-hurd?) | ||
| 739 | '(" test_posix" ;multiple errors | ||
| 740 | " test_time" | ||
| 741 | " test_pty" | ||
| 742 | " test_shutil" | ||
| 743 | " test_tempfile" ;chflags: invalid argument: | ||
| 744 | ;; tbv14c9t/dir0/dir0/dir0/test0.txt | ||
| 745 | " test_os" ;stty: 'standard input': | ||
| 746 | ;; Inappropriate ioctl for device | ||
| 747 | " test_openpty" ;No such file or directory | ||
| 748 | " test_selectors" ;assertEqual(NUM_FDS // 2, len(fds)) | ||
| 749 | ;; 32752 != 4 | ||
| 750 | " test_compileall" ;multiple errors | ||
| 751 | " test_poll" ;list index out of range | ||
| 752 | " test_subprocess" ;runs over 10min | ||
| 753 | " test_asyncore" ;multiple errors | ||
| 754 | " test_threadsignals" | ||
| 755 | " test_eintr" ;Process return code is -14 | ||
| 756 | " test_io" ;multiple errors | ||
| 757 | " test_logging" | ||
| 758 | " test_signal" | ||
| 759 | " test_flags" ;ERROR | ||
| 760 | " test_bidirectional_pty" | ||
| 761 | " test_create_unix_connection" | ||
| 762 | " test_unix_sock_client_ops" | ||
| 763 | " test_open_unix_connection" | ||
| 764 | " test_open_unix_connection_error" | ||
| 765 | " test_read_pty_output" | ||
| 766 | " test_write_pty" | ||
| 767 | " test_concurrent_futures" ;freeze | ||
| 768 | " test_venv" ;freeze | ||
| 769 | " test_multiprocessing_forkserver" ;runs over 10min | ||
| 770 | " test_multiprocessing_spawn" ;runs over 10min | ||
| 771 | " test_builtin" | ||
| 772 | " test_capi" | ||
| 773 | " test_dbm_ndbm" | ||
| 774 | " test_exceptions" | ||
| 775 | " test_faulthandler" | ||
| 776 | " test_getopt" | ||
| 777 | " test_importlib" | ||
| 778 | " test_json" | ||
| 779 | " test_multiprocessing_fork" | ||
| 780 | " test_multiprocessing_main_handling" | ||
| 781 | " test_pdb " | ||
| 782 | " test_regrtest" | ||
| 783 | " test_sqlite") | ||
| 784 | '()))) | ||
| 785 | |||
| 786 | #:modules | ||
| 787 | '((ice-9 ftw) | ||
| 788 | (ice-9 match) | ||
| 789 | (guix build utils) | ||
| 790 | (guix build gnu-build-system)) | ||
| 791 | |||
| 792 | #:phases | ||
| 793 | `(modify-phases %standard-phases | ||
| 794 | ,@(if (system-hurd?) | ||
| 795 | `((add-after 'unpack | ||
| 796 | 'disable-multi-processing | ||
| 797 | (lambda _ | ||
| 798 | (substitute* "Makefile.pre.in" | ||
| 799 | (("-j0") | ||
| 800 | "-j1"))))) | ||
| 801 | '()) | ||
| 802 | (add-before 'configure 'patch-lib-shells | ||
| 803 | (lambda _ | ||
| 804 | ;; This variable is used in setup.py to enable cross compilation | ||
| 805 | ;; specific switches. As it is not set properly by configure | ||
| 806 | ;; script, set it manually. | ||
| 807 | ,@(if (%current-target-system) | ||
| 808 | '((setenv "_PYTHON_HOST_PLATFORM" "")) | ||
| 809 | '()) | ||
| 810 | ;; Filter for existing files, since some may not exist in all | ||
| 811 | ;; versions of python that are built with this recipe. | ||
| 812 | (substitute* (filter file-exists? | ||
| 813 | '("Lib/subprocess.py" | ||
| 814 | "Lib/popen2.py" | ||
| 815 | "Lib/distutils/tests/test_spawn.py" | ||
| 816 | "Lib/test/support/__init__.py" | ||
| 817 | "Lib/test/test_subprocess.py")) | ||
| 818 | (("/bin/sh") | ||
| 819 | (which "sh"))))) | ||
| 820 | (add-before 'configure 'do-not-record-configure-flags | ||
| 821 | (lambda* (#:key configure-flags #:allow-other-keys) | ||
| 822 | ;; Remove configure flags from the installed '_sysconfigdata.py' | ||
| 823 | ;; and 'Makefile' so we don't end up keeping references to the | ||
| 824 | ;; build tools. | ||
| 825 | ;; | ||
| 826 | ;; Preserve at least '--with-system-ffi' since otherwise the | ||
| 827 | ;; thing tries to build libffi, fails, and we end up with a | ||
| 828 | ;; Python that lacks ctypes. | ||
| 829 | (substitute* "configure" | ||
| 830 | (("^CONFIG_ARGS=.*$") | ||
| 831 | (format #f "CONFIG_ARGS='~a'\n" | ||
| 832 | (if (member "--with-system-ffi" | ||
| 833 | configure-flags) | ||
| 834 | "--with-system-ffi" "")))))) | ||
| 835 | (add-before 'check 'pre-check | ||
| 836 | (lambda _ | ||
| 837 | ;; 'Lib/test/test_site.py' needs a valid $HOME | ||
| 838 | (setenv "HOME" | ||
| 839 | (getcwd)))) | ||
| 840 | (add-after 'unpack 'set-source-file-times-to-1980 | ||
| 841 | ;; XXX One of the tests uses a ZIP library to pack up some of the | ||
| 842 | ;; source tree, and fails with "ZIP does not support timestamps | ||
| 843 | ;; before 1980". Work around this by setting the file times in the | ||
| 844 | ;; source tree to sometime in early 1980. | ||
| 845 | (lambda _ | ||
| 846 | (let ((circa-1980 (* 10 366 24 60 60))) | ||
| 847 | (ftw "." | ||
| 848 | (lambda (file stat flag) | ||
| 849 | (utime file circa-1980 circa-1980) #t))))) | ||
| 850 | (add-after 'unpack 'remove-windows-binaries | ||
| 851 | (lambda _ | ||
| 852 | ;; Delete .exe from embedded .whl (zip) files | ||
| 853 | (for-each (lambda (whl) | ||
| 854 | (let ((dir "whl-content") | ||
| 855 | (circa-1980 (* 10 366 24 60 60))) | ||
| 856 | (mkdir-p dir) | ||
| 857 | (with-directory-excursion dir | ||
| 858 | (let ((whl (string-append "../" whl))) | ||
| 859 | (invoke "unzip" whl) | ||
| 860 | (for-each delete-file | ||
| 861 | (find-files "." "\\.exe$")) | ||
| 862 | (delete-file whl) | ||
| 863 | ;; Reset timestamps to prevent them from ending | ||
| 864 | ;; up in the Zip archive. | ||
| 865 | (ftw "." | ||
| 866 | (lambda (file stat flag) | ||
| 867 | (utime file circa-1980 | ||
| 868 | circa-1980) #t)) | ||
| 869 | (apply invoke "zip" "-X" whl | ||
| 870 | (find-files "." | ||
| 871 | #:directories? #t)))) | ||
| 872 | (delete-file-recursively dir))) | ||
| 873 | (find-files "Lib/ensurepip" "\\.whl$")))) | ||
| 874 | (add-after 'install 'remove-tests | ||
| 875 | ;; Remove 25 MiB of unneeded unit tests. Keep test_support.* | ||
| 876 | ;; because these files are used by some libraries out there. | ||
| 877 | (lambda* (#:key outputs #:allow-other-keys) | ||
| 878 | (let ((out (assoc-ref outputs "out"))) | ||
| 879 | (match (scandir (string-append out "/lib") | ||
| 880 | (lambda (name) | ||
| 881 | (string-prefix? "python" name))) | ||
| 882 | ((pythonX.Y) | ||
| 883 | (let ((testdir (string-append out "/lib/" pythonX.Y | ||
| 884 | "/test"))) | ||
| 885 | (with-directory-excursion testdir | ||
| 886 | (for-each delete-file-recursively | ||
| 887 | (scandir testdir | ||
| 888 | (match-lambda | ||
| 889 | ((or "." "..") | ||
| 890 | #f) | ||
| 891 | ("support" #f) | ||
| 892 | (file (not (string-prefix? | ||
| 893 | "test_support." | ||
| 894 | file)))))) | ||
| 895 | (call-with-output-file "__init__.py" | ||
| 896 | (const #t)))) | ||
| 897 | (let ((libdir (string-append out "/lib/" pythonX.Y))) | ||
| 898 | (for-each (lambda (directory) | ||
| 899 | (let ((dir (string-append libdir "/" | ||
| 900 | directory))) | ||
| 901 | (when (file-exists? dir) | ||
| 902 | (delete-file-recursively dir)))) | ||
| 903 | '("email/test" "ctypes/test" | ||
| 904 | "unittest/test" | ||
| 905 | "tkinter/test" | ||
| 906 | "sqlite3/test" | ||
| 907 | "bsddb/test" | ||
| 908 | "lib-tk/test" | ||
| 909 | "json/tests" | ||
| 910 | "distutils/tests")))))))) | ||
| 911 | (add-after 'remove-tests 'move-tk-inter | ||
| 912 | (lambda* (#:key outputs inputs #:allow-other-keys) | ||
| 913 | ;; When Tkinter support is built move it to a separate output so | ||
| 914 | ;; that the main output doesn't contain a reference to Tcl/Tk. | ||
| 915 | (let ((out (assoc-ref outputs "out")) | ||
| 916 | (tk (assoc-ref outputs "tk"))) | ||
| 917 | (when tk | ||
| 918 | (match (find-files out "tkinter.*\\.so") | ||
| 919 | ((tkinter.so) | ||
| 920 | ;; The .so is in OUT/lib/pythonX.Y/lib-dynload, but we | ||
| 921 | ;; want it under TK/lib/pythonX.Y/site-packages. | ||
| 922 | (let* ((len (string-length out)) | ||
| 923 | (target (string-append tk "/" | ||
| 924 | (string-drop (dirname | ||
| 925 | (dirname | ||
| 926 | tkinter.so)) | ||
| 927 | len) | ||
| 928 | "/site-packages"))) | ||
| 929 | (install-file tkinter.so target) | ||
| 930 | (delete-file tkinter.so)))) | ||
| 931 | ;; Remove explicit store path references. | ||
| 932 | (let ((tcl (assoc-ref inputs "tcl")) | ||
| 933 | (tk (assoc-ref inputs "tk"))) | ||
| 934 | (substitute* (find-files (string-append out "/lib") | ||
| 935 | "^(_sysconfigdata_.*\\.py|Makefile)$") | ||
| 936 | (((string-append "-L" tk "/lib")) | ||
| 937 | "") | ||
| 938 | (((string-append "-L" tcl "/lib")) | ||
| 939 | ""))))))) | ||
| 940 | (add-after 'move-tk-inter 'move-idle | ||
| 941 | (lambda* (#:key outputs #:allow-other-keys) | ||
| 942 | ;; when idle is built, move it to a separate output to save some | ||
| 943 | ;; space (5MB) | ||
| 944 | (let ((out (assoc-ref outputs "out")) | ||
| 945 | (idle (assoc-ref outputs "idle"))) | ||
| 946 | (when idle | ||
| 947 | (for-each (lambda (file) | ||
| 948 | (let ((target (string-append idle | ||
| 949 | "/bin/" | ||
| 950 | (basename | ||
| 951 | file)))) | ||
| 952 | (install-file file | ||
| 953 | (dirname target)) | ||
| 954 | (delete-file file))) | ||
| 955 | (find-files (string-append out "/bin") | ||
| 956 | "^idle")) | ||
| 957 | (match (find-files out "^idlelib$" | ||
| 958 | #:directories? #t) | ||
| 959 | ((idlelib) | ||
| 960 | (let* ((len (string-length out)) | ||
| 961 | (target (string-append idle "/" | ||
| 962 | (string-drop | ||
| 963 | idlelib len) | ||
| 964 | "/site-packages"))) | ||
| 965 | (mkdir-p (dirname target)) | ||
| 966 | (rename-file idlelib target)))))))) | ||
| 967 | (add-after 'move-idle 'rebuild-bytecode | ||
| 968 | (lambda* (#:key outputs #:allow-other-keys) | ||
| 969 | (let ((out (assoc-ref outputs "out"))) | ||
| 970 | ;; Disable hash randomization to ensure the generated .pycs | ||
| 971 | ;; are reproducible. | ||
| 972 | (setenv "PYTHONHASHSEED" "0") | ||
| 973 | |||
| 974 | (for-each (lambda (output) | ||
| 975 | ;; XXX: Delete existing pycs generated by the build | ||
| 976 | ;; system beforehand because the -f argument does | ||
| 977 | ;; not necessarily overwrite all files, leading to | ||
| 978 | ;; indeterministic results. | ||
| 979 | (for-each (lambda (pyc) | ||
| 980 | (delete-file pyc)) | ||
| 981 | (find-files output "\\.pyc$")) | ||
| 982 | |||
| 983 | (apply invoke | ||
| 984 | `(,,(if (%current-target-system) | ||
| 985 | "python3" | ||
| 986 | '(string-append out | ||
| 987 | "/bin/python3")) "-m" | ||
| 988 | "compileall" | ||
| 989 | "-o" | ||
| 990 | "0" | ||
| 991 | "-o" | ||
| 992 | "1" | ||
| 993 | "-o" | ||
| 994 | "2" | ||
| 995 | "-f" ;force rebuild | ||
| 996 | "--invalidation-mode=unchecked-hash" | ||
| 997 | ;; Don't build lib2to3, because it's | ||
| 998 | ;; Python 2 code. | ||
| 999 | "-x" | ||
| 1000 | "lib2to3/.*" | ||
| 1001 | ,output))) | ||
| 1002 | (map cdr outputs))))) | ||
| 1003 | (add-before 'check 'set-TZDIR | ||
| 1004 | (lambda* (#:key inputs native-inputs #:allow-other-keys) | ||
| 1005 | ;; test_email requires the Olson time zone database. | ||
| 1006 | (setenv "TZDIR" | ||
| 1007 | (string-append (assoc-ref (or native-inputs | ||
| 1008 | inputs) "tzdata") | ||
| 1009 | "/share/zoneinfo")))) | ||
| 1010 | (add-after 'install 'install-sitecustomize.py | ||
| 1011 | ,(customize-site version))))) | ||
| 1012 | (inputs (list bzip2 | ||
| 1013 | expat | ||
| 1014 | gdbm | ||
| 1015 | libffi ;for ctypes | ||
| 1016 | sqlite ;for sqlite extension | ||
| 1017 | openssl | ||
| 1018 | readline | ||
| 1019 | zlib | ||
| 1020 | tcl | ||
| 1021 | tk)) ;for tkinter | ||
| 1022 | (native-inputs `(("tzdata" ,tzdata-for-tests) | ||
| 1023 | ("unzip" ,unzip) | ||
| 1024 | ("zip" ,(@ (gnu packages compression) zip)) | ||
| 1025 | ("pkg-config" ,pkg-config) | ||
| 1026 | ("sitecustomize.py" ,(local-file (search-auxiliary-file | ||
| 1027 | "python/sitecustomize.py"))) | ||
| 1028 | ;; When cross-compiling, a native version of Python itself is needed. | ||
| 1029 | ,@(if (%current-target-system) | ||
| 1030 | `(("python" ,this-package) | ||
| 1031 | ("which" ,which)) | ||
| 1032 | '()))) | ||
| 1033 | (native-search-paths | ||
| 1034 | (list (guix-pythonpath-search-path version) | ||
| 1035 | ;; Used to locate tzdata by the zoneinfo module introduced in | ||
| 1036 | ;; Python 3.9. | ||
| 1037 | (search-path-specification | ||
| 1038 | (variable "PYTHONTZPATH") | ||
| 1039 | (files (list "share/zoneinfo"))))))) | ||
| 1040 | |||
| 663 | (define-public python-3.12 | 1041 | (define-public python-3.12 |
| 664 | (package | 1042 | (package |
| 665 | (name "python-next") | 1043 | (name "python-next") |
