summaryrefslogtreecommitdiff
path: root/gnu/packages/python.scm
diff options
context:
space:
mode:
authorTanguy Le Carrour <tanguy@bioneland.org>2024-03-07 19:58:18 +0100
committerLars-Dominik Braun <lars@6xq.net>2024-03-09 16:59:20 +0100
commitd1b660a00c1e9a7128ccbd13d01314faedae8ebf (patch)
treedd201f9263490795d0ad72f9112e88f5c570da59 /gnu/packages/python.scm
parent1bc05c6f6d56ad9e0e31d7f1cc75545a65e3d0f3 (diff)
gnu: Add python-3.12 and python-next.
* gnu/packages/python.scm (python-3.12, python-next): New variables. * gnu/packages/patches/python-3.12-fix-tests.patch: New file. Change-Id: Ie393b732a8863569578e72e62603b75a1655a34e Signed-off-by: Tanguy Le Carrour <tanguy@bioneland.org> Signed-off-by: Lars-Dominik Braun <lars@6xq.net>
Diffstat (limited to 'gnu/packages/python.scm')
-rw-r--r--gnu/packages/python.scm387
1 files changed, 386 insertions, 1 deletions
diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm
index 51d5f598d73..0ae3709b998 100644
--- a/gnu/packages/python.scm
+++ b/gnu/packages/python.scm
@@ -55,7 +55,7 @@
55;;; Copyright © 2018, 2019, 2020, 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com> 55;;; Copyright © 2018, 2019, 2020, 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com>
56;;; Copyright © 2018 Luther Thompson <lutheroto@gmail.com> 56;;; Copyright © 2018 Luther Thompson <lutheroto@gmail.com>
57;;; Copyright © 2018 Vagrant Cascadian <vagrant@debian.org> 57;;; Copyright © 2018 Vagrant Cascadian <vagrant@debian.org>
58;;; Copyright © 2019 Tanguy Le Carrour <tanguy@bioneland.org> 58;;; Copyright © 2019, 2024 Tanguy Le Carrour <tanguy@bioneland.org>
59;;; Copyright © 2020, 2023 Janneke Nieuwenhuizen <janneke@gnu.org> 59;;; Copyright © 2020, 2023 Janneke Nieuwenhuizen <janneke@gnu.org>
60;;; Copyright © 2020, 2021 Greg Hogan <code@greghogan.com> 60;;; Copyright © 2020, 2021 Greg Hogan <code@greghogan.com>
61;;; Copyright © 2022 Philip McGrath <philip@philipmcgrath.com> 61;;; Copyright © 2022 Philip McGrath <philip@philipmcgrath.com>
@@ -596,6 +596,391 @@ data types.")
596 (variable "PYTHONTZPATH") 596 (variable "PYTHONTZPATH")
597 (files (list "share/zoneinfo"))))))) 597 (files (list "share/zoneinfo")))))))
598 598
599(define-public python-3.12
600 (package
601 (name "python-next")
602 (version "3.12.2")
603 (source
604 (origin
605 (method url-fetch)
606 (uri (string-append "https://www.python.org/ftp/python/" version
607 "/Python-" version ".tar.xz"))
608 (sha256
609 (base32 "0w6qyfhc912xxav9x9pifwca40b4l49vy52wai9j0gc1mhni2a5y"))
610 (patches (search-patches "python-3-deterministic-build-info.patch"
611 "python-3.12-fix-tests.patch"
612 "python-3-hurd-configure.patch"))
613 (modules '((guix build utils)))
614 (snippet '(begin
615 ;; Delete the bundled copy of libexpat.
616 (delete-file-recursively "Modules/expat")
617 (substitute* "Modules/Setup"
618 ;; Link Expat instead of embedding the bundled one.
619 (("^#pyexpat.*")
620 "pyexpat pyexpat.c -lexpat\n"))
621 ;; Delete windows binaries
622 (for-each delete-file
623 (find-files "Lib/distutils/command" "\\.exe$"))))))
624 (outputs '("out" "tk" ;tkinter; adds 50 MiB to the closure
625 "idle")) ;programming environment; weighs 5MB
626 (build-system gnu-build-system)
627 (arguments
628 `(#:test-target "test"
629 #:configure-flags (list "--enable-shared" ;allow embedding
630 "--with-system-expat" ;for XML support
631 "--with-system-ffi" ;build ctypes
632 "--with-ensurepip=install" ;install pip and setuptools
633 "--with-computed-gotos" ;main interpreter loop optimization
634 "--enable-unicode=ucs4"
635 "--without-static-libpython"
636
637 ;; FIXME: These flags makes Python significantly faster,
638 ;; but leads to non-reproducible binaries.
639 ;; "--with-lto" ;increase size by 20MB, but 15% speedup
640 ;; "--enable-optimizations"
641
642 ;; Prevent the installed _sysconfigdata.py from retaining
643 ;; a reference to coreutils.
644 "INSTALL=install -c"
645 "MKDIR_P=mkdir -p"
646
647 ;; Disable runtime check failing if cross-compiling, see:
648 ;; https://lists.yoctoproject.org/pipermail/poky/2013-June/008997.html
649 ,@(if (%current-target-system)
650 '("ac_cv_buggy_getaddrinfo=no"
651 "ac_cv_file__dev_ptmx=no"
652 "ac_cv_file__dev_ptc=no")
653 '())
654 ;; -fno-semantic-interposition reinstates some
655 ;; optimizations by gcc leading to around 15% speedup.
656 ;; This is the default starting from python 3.10.
657 "CFLAGS=-fno-semantic-interposition"
658 (string-append "LDFLAGS=-Wl,-rpath="
659 (assoc-ref %outputs "out")
660 "/lib"
661 " -fno-semantic-interposition"))
662 ;; With no -j argument tests use all available cpus, so provide one.
663 #:make-flags (list (string-append (format #f "TESTOPTS=-j~d"
664 (parallel-job-count))
665 ;; those tests fail on low-memory systems
666 " --exclude test_mmap test_socket test_threading test_asyncio"
667 ,@(if (system-hurd?)
668 '(" test_posix" ;multiple errors
669 " test_time"
670 " test_pty"
671 " test_shutil"
672 " test_tempfile" ;chflags: invalid argument:
673 ;; tbv14c9t/dir0/dir0/dir0/test0.txt
674 " test_os" ;stty: 'standard input':
675 ;; Inappropriate ioctl for device
676 " test_openpty" ;No such file or directory
677 " test_selectors" ;assertEqual(NUM_FDS // 2, len(fds))
678 ;; 32752 != 4
679 " test_compileall" ;multiple errors
680 " test_poll" ;list index out of range
681 " test_subprocess" ;runs over 10min
682 " test_asyncore" ;multiple errors
683 " test_threadsignals"
684 " test_eintr" ;Process return code is -14
685 " test_io" ;multiple errors
686 " test_logging"
687 " test_signal"
688 " test_flags" ;ERROR
689 " test_bidirectional_pty"
690 " test_create_unix_connection"
691 " test_unix_sock_client_ops"
692 " test_open_unix_connection"
693 " test_open_unix_connection_error"
694 " test_read_pty_output"
695 " test_write_pty"
696 " test_concurrent_futures" ;freeze
697 " test_venv" ;freeze
698 " test_multiprocessing_forkserver" ;runs over 10min
699 " test_multiprocessing_spawn" ;runs over 10min
700 " test_builtin"
701 " test_capi"
702 " test_dbm_ndbm"
703 " test_exceptions"
704 " test_faulthandler"
705 " test_getopt"
706 " test_importlib"
707 " test_json"
708 " test_multiprocessing_fork"
709 " test_multiprocessing_main_handling"
710 " test_pdb "
711 " test_regrtest"
712 " test_sqlite")
713 '())))
714
715 #:modules ((ice-9 ftw)
716 (ice-9 match)
717 (guix build utils)
718 (guix build gnu-build-system))
719
720 #:phases (modify-phases %standard-phases
721 ,@(if (system-hurd?)
722 `((add-after 'unpack
723 'disable-multi-processing
724 (lambda _
725 (substitute* "Makefile.pre.in"
726 (("-j0")
727 "-j1")))))
728 '())
729 (add-before 'configure 'patch-lib-shells
730 (lambda _
731 ;; This variable is used in setup.py to enable cross compilation
732 ;; specific switches. As it is not set properly by configure
733 ;; script, set it manually.
734 ,@(if (%current-target-system)
735 '((setenv "_PYTHON_HOST_PLATFORM" ""))
736 '())
737 ;; Filter for existing files, since some may not exist in all
738 ;; versions of python that are built with this recipe.
739 (substitute* (filter file-exists?
740 '("Lib/subprocess.py"
741 "Lib/popen2.py"
742 "Lib/distutils/tests/test_spawn.py"
743 "Lib/test/support/__init__.py"
744 "Lib/test/test_subprocess.py"))
745 (("/bin/sh")
746 (which "sh")))))
747 (add-before 'configure 'do-not-record-configure-flags
748 (lambda* (#:key configure-flags #:allow-other-keys)
749 ;; Remove configure flags from the installed '_sysconfigdata.py'
750 ;; and 'Makefile' so we don't end up keeping references to the
751 ;; build tools.
752 ;;
753 ;; Preserve at least '--with-system-ffi' since otherwise the
754 ;; thing tries to build libffi, fails, and we end up with a
755 ;; Python that lacks ctypes.
756 (substitute* "configure"
757 (("^CONFIG_ARGS=.*$")
758 (format #f "CONFIG_ARGS='~a'\n"
759 (if (member "--with-system-ffi"
760 configure-flags)
761 "--with-system-ffi" ""))))))
762 (add-before 'check 'pre-check
763 (lambda _
764 ;; 'Lib/test/test_site.py' needs a valid $HOME
765 (setenv "HOME"
766 (getcwd))))
767 (add-after 'unpack 'set-source-file-times-to-1980
768 ;; XXX One of the tests uses a ZIP library to pack up some of the
769 ;; source tree, and fails with "ZIP does not support timestamps
770 ;; before 1980". Work around this by setting the file times in the
771 ;; source tree to sometime in early 1980.
772 (lambda _
773 (let ((circa-1980 (* 10 366 24 60 60)))
774 (ftw "."
775 (lambda (file stat flag)
776 (utime file circa-1980 circa-1980) #t)))))
777 (add-after 'unpack 'remove-windows-binaries
778 (lambda _
779 ;; Delete .exe from embedded .whl (zip) files
780 (for-each (lambda (whl)
781 (let ((dir "whl-content")
782 (circa-1980 (* 10 366 24 60 60)))
783 (mkdir-p dir)
784 (with-directory-excursion dir
785 (let ((whl (string-append "../" whl)))
786 (invoke "unzip" whl)
787 (for-each delete-file
788 (find-files "." "\\.exe$"))
789 (delete-file whl)
790 ;; Reset timestamps to prevent them from ending
791 ;; up in the Zip archive.
792 (ftw "."
793 (lambda (file stat flag)
794 (utime file circa-1980
795 circa-1980) #t))
796 (apply invoke "zip" "-X" whl
797 (find-files "."
798 #:directories? #t))))
799 (delete-file-recursively dir)))
800 (find-files "Lib/ensurepip" "\\.whl$"))))
801 (add-after 'install 'remove-tests
802 ;; Remove 25 MiB of unneeded unit tests. Keep test_support.*
803 ;; because these files are used by some libraries out there.
804 (lambda* (#:key outputs #:allow-other-keys)
805 (let ((out (assoc-ref outputs "out")))
806 (match (scandir (string-append out "/lib")
807 (lambda (name)
808 (string-prefix? "python" name)))
809 ((pythonX.Y)
810 (let ((testdir (string-append out "/lib/" pythonX.Y
811 "/test")))
812 (with-directory-excursion testdir
813 (for-each delete-file-recursively
814 (scandir testdir
815 (match-lambda
816 ((or "." "..")
817 #f)
818 ("support" #f)
819 (file (not (string-prefix?
820 "test_support."
821 file))))))
822 (call-with-output-file "__init__.py"
823 (const #t))))
824 (let ((libdir (string-append out "/lib/" pythonX.Y)))
825 (for-each (lambda (directory)
826 (let ((dir (string-append libdir "/"
827 directory)))
828 (when (file-exists? dir)
829 (delete-file-recursively dir))))
830 '("email/test" "ctypes/test"
831 "unittest/test"
832 "tkinter/test"
833 "sqlite3/test"
834 "bsddb/test"
835 "lib-tk/test"
836 "json/tests"
837 "distutils/tests"))))))))
838 (add-after 'remove-tests 'move-tk-inter
839 (lambda* (#:key outputs inputs #:allow-other-keys)
840 ;; When Tkinter support is built move it to a separate output so
841 ;; that the main output doesn't contain a reference to Tcl/Tk.
842 (let ((out (assoc-ref outputs "out"))
843 (tk (assoc-ref outputs "tk")))
844 (when tk
845 (match (find-files out "tkinter.*\\.so")
846 ((tkinter.so)
847 ;; The .so is in OUT/lib/pythonX.Y/lib-dynload, but we
848 ;; want it under TK/lib/pythonX.Y/site-packages.
849 (let* ((len (string-length out))
850 (target (string-append tk "/"
851 (string-drop (dirname
852 (dirname
853 tkinter.so))
854 len)
855 "/site-packages")))
856 (install-file tkinter.so target)
857 (delete-file tkinter.so))))
858 ;; Remove explicit store path references.
859 (let ((tcl (assoc-ref inputs "tcl"))
860 (tk (assoc-ref inputs "tk")))
861 (substitute* (find-files (string-append out "/lib")
862 "^(_sysconfigdata_.*\\.py|Makefile)$")
863 (((string-append "-L" tk "/lib"))
864 "")
865 (((string-append "-L" tcl "/lib"))
866 "")))))))
867 (add-after 'move-tk-inter 'move-idle
868 (lambda* (#:key outputs #:allow-other-keys)
869 ;; when idle is built, move it to a separate output to save some
870 ;; space (5MB)
871 (let ((out (assoc-ref outputs "out"))
872 (idle (assoc-ref outputs "idle")))
873 (when idle
874 (for-each (lambda (file)
875 (let ((target (string-append idle
876 "/bin/"
877 (basename
878 file))))
879 (install-file file
880 (dirname target))
881 (delete-file file)))
882 (find-files (string-append out "/bin")
883 "^idle"))
884 (match (find-files out "^idlelib$"
885 #:directories? #t)
886 ((idlelib)
887 (let* ((len (string-length out))
888 (target (string-append idle "/"
889 (string-drop
890 idlelib len)
891 "/site-packages")))
892 (mkdir-p (dirname target))
893 (rename-file idlelib target))))))))
894 (add-after 'move-idle 'rebuild-bytecode
895 (lambda* (#:key outputs #:allow-other-keys)
896 (let ((out (assoc-ref outputs "out")))
897 ;; Disable hash randomization to ensure the generated .pycs
898 ;; are reproducible.
899 (setenv "PYTHONHASHSEED" "0")
900
901 (for-each (lambda (output)
902 ;; XXX: Delete existing pycs generated by the build
903 ;; system beforehand because the -f argument does
904 ;; not necessarily overwrite all files, leading to
905 ;; indeterministic results.
906 (for-each (lambda (pyc)
907 (delete-file pyc))
908 (find-files output "\\.pyc$"))
909
910 (apply invoke
911 `(,,(if (%current-target-system)
912 "python3"
913 '(string-append out
914 "/bin/python3")) "-m"
915 "compileall"
916 "-o"
917 "0"
918 "-o"
919 "1"
920 "-o"
921 "2"
922 "-f" ;force rebuild
923 "--invalidation-mode=unchecked-hash"
924 ;; Don't build lib2to3, because it's
925 ;; Python 2 code.
926 "-x"
927 "lib2to3/.*"
928 ,output)))
929 (map cdr outputs)))))
930 (add-before 'check 'set-TZDIR
931 (lambda* (#:key inputs native-inputs #:allow-other-keys)
932 ;; test_email requires the Olson time zone database.
933 (setenv "TZDIR"
934 (string-append (assoc-ref (or native-inputs
935 inputs) "tzdata")
936 "/share/zoneinfo"))))
937 (add-after 'install 'install-sitecustomize.py
938 ,(customize-site version)))))
939 (inputs (list bzip2
940 expat
941 gdbm
942 libffi ;for ctypes
943 sqlite ;for sqlite extension
944 openssl
945 readline
946 zlib
947 tcl
948 tk)) ;for tkinter
949 (native-inputs `(("tzdata" ,tzdata-for-tests)
950 ("unzip" ,unzip)
951 ("zip" ,(@ (gnu packages compression) zip))
952 ("pkg-config" ,pkg-config)
953 ("sitecustomize.py" ,(local-file (search-auxiliary-file
954 "python/sitecustomize.py")))
955 ;; When cross-compiling, a native version of Python itself is needed.
956 ,@(if (%current-target-system)
957 `(("python" ,this-package)
958 ("which" ,which))
959 '())))
960 (native-search-paths
961 (list (guix-pythonpath-search-path version)
962 ;; Used to locate tzdata by the zoneinfo module introduced in
963 ;; Python 3.9.
964 (search-path-specification
965 (variable "PYTHONTZPATH")
966 (files (list "share/zoneinfo")))))
967 (home-page "https://www.python.org")
968 (synopsis "High-level, dynamically-typed programming language")
969 (description
970 "Python is a remarkably powerful dynamic programming language that
971is used in a wide variety of application domains. Some of its key
972distinguishing features include: clear, readable syntax; strong
973introspection capabilities; intuitive object orientation; natural
974expression of procedural code; full modularity, supporting hierarchical
975packages; exception-based error handling; and very high level dynamic
976data types.")
977 (properties '((cpe-name . "python")))
978 (license license:psfl)))
979
980
981;; Next 3.x version.
982(define-public python-next python-3.12)
983
599;; Current 3.x version. 984;; Current 3.x version.
600(define-public python-3 python-3.10) 985(define-public python-3 python-3.10)
601 986