Subject: [PATCH v3 02/22] gnu: pypy: Move to separate module.

From: Marius Bakke <[email-masked]>
Date: Sun, 23 Oct 2022 00:20:40 +0200

From: Lars-Dominik Braun <[email-masked]>

This removes the need to import (gnu packages python-xyz) in (gnu packages
python), avoiding issues with circular imports.

* gnu/packages/python.scm (pypy): Move…
* gnu/packages/pypy.scm (pypy): …here
* gnu/local.mk: Register new file.

Co-authored-by: Marius Bakke <[email-masked]>
---
 gnu/local.mk            |   1 +
 gnu/packages/pypy.scm   | 273 ++++++++++++++++++++++++++++++++++++++++
 gnu/packages/python.scm | 170 -------------------------
 3 files changed, 274 insertions(+), 170 deletions(-)
 create mode 100644 gnu/packages/pypy.scm

diff --git a/gnu/local.mk b/gnu/local.mk
index 8247180bef..bf598cec8b 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -506,6 +506,7 @@ GNU_SYSTEM_MODULES =				\
   %D%/packages/pure.scm				\
   %D%/packages/purescript.scm			\
   %D%/packages/pv.scm				\
+  %D%/packages/pypy.scm				\
   %D%/packages/python.scm			\
   %D%/packages/python-build.scm			\
   %D%/packages/python-check.scm			\
diff --git a/gnu/packages/pypy.scm b/gnu/packages/pypy.scm
new file mode 100644
index 0000000000..002cfd59cd
--- /dev/null
+++ b/gnu/packages/pypy.scm
@@ -0,0 +1,273 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2013 Nikita Karetnikov <[email-masked]>
+;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2021 Ludovic Courtès <[email-masked]>
+;;; Copyright © 2013, 2014, 2015, 2016 Andreas Enge <[email-masked]>
+;;; Copyright © 2014, 2015 Mark H Weaver <[email-masked]>
+;;; Copyright © 2014, 2017, 2019 Eric Bavier <[email-masked]>
+;;; Copyright © 2014, 2015 Federico Beffa <[email-masked]>
+;;; Copyright © 2015 Omar Radwan <[email-masked]>
+;;; Copyright © 2015 Pierre-Antoine Rault <[email-masked]>
+;;; Copyright © 2015, 2016, 2017, 2018, 2019 Ricardo Wurmus <[email-masked]>
+;;; Copyright © 2015, 2016 Christine Lemmer-Webber <[email-masked]>
+;;; Copyright © 2015 Eric Dvorsak <[email-masked]>
+;;; Copyright © 2015, 2016 David Thompson <[email-masked]>
+;;; Copyright © 2015, 2016, 2017, 2021 Leo Famulari <[email-masked]>
+;;; Copyright © 2015, 2017 Ben Woodcroft <[email-masked]>
+;;; Copyright © 2015, 2016 Erik Edrosa <[email-masked]>
+;;; Copyright © 2015, 2016, 2017, 2018, 2019, 2020 Efraim Flashner <[email-masked]>
+;;; Copyright © 2015, 2017 Kyle Meyer <[email-masked]>
+;;; Copyright © 2015, 2016 Chris Marusich <[email-masked]>
+;;; Copyright © 2016 Danny Milosavljevic <[email-masked]>
+;;; Copyright © 2016 Lukas Gradl <[email-masked]>
+;;; Copyright © 2016, 2018 Hartmut Goebel <[email-masked]>
+;;; Copyright © 2016 Daniel Pimentel <[email-masked]>
+;;; Copyright © 2016 Sou Bunnbu <[email-masked]>
+;;; Copyright © 2016, 2017 Troy Sankey <[email-masked]>
+;;; Copyright © 2016, 2017 Nikita <[email-masked]>
+;;; Copyright © 2016 Dylan Jeffers <sapientech@[email-masked]>
+;;; Copyright © 2016 David Craven <[email-masked]>
+;;; Copyright © 2016, 2017, 2018, 2019, 2020, 2021 Marius Bakke <[email-masked]>
+;;; Copyright © 2016, 2017 Stefan Reichör <[email-masked]>
+;;; Copyright © 2016 Dylan Jeffers <sapientech@[email-masked]>
+;;; Copyright © 2016, 2017 Alex Vong <[email-masked]>
+;;; Copyright © 2016, 2017, 2018 Arun Isaac <[email-masked]>
+;;; Copyright © 2016–2018, 2021 Tobias Geerinckx-Rice <[email-masked]>
+;;; Copyright © 2016, 2017, 2018, 2021 Julien Lepiller <[email-masked]>
+;;; Copyright © 2016, 2017 Thomas Danckaert <[email-masked]>
+;;; Copyright © 2017 Carlo Zancanaro <[email-masked]>
+;;; Copyright © 2017 Frederick M. Muriithi <[email-masked]>
+;;; Copyright © 2017, 2018 Adriano Peluso <[email-masked]>
+;;; Copyright © 2017 Ben Sturmfels <[email-masked]>
+;;; Copyright © 2017, 2018, 2019 Mathieu Othacehe <[email-masked]>
+;;; Copyright © 2017 José Miguel Sánchez García <[email-masked]>
+;;; Copyright © 2017 Roel Janssen <[email-masked]>
+;;; Copyright © 2017, 2018 Kei Kebreau <[email-masked]>
+;;; Copyright © 2017 Rutger Helling <[email-masked]>
+;;; Copyright © 2017 Muriithi Frederick Muriuki <[email-masked]>
+;;; Copyright © 2017 Brendan Tildesley <[email-masked]>
+;;; Copyright © 2018 Ethan R. Jones <[email-masked]
+;;; Copyright © 2018 Fis Trivial <[email-masked]>
+;;; Copyright © 2018 Vijayalakshmi Vedantham <[email-masked]>
+;;; Copyright © 2018 Mathieu Lirzin <[email-masked]>
+;;; Copyright © 2018 Adam Massmann <[email-masked]>
+;;; Copyright © 2016, 2018 Tomáš Čech <[email-masked]>
+;;; Copyright © 2018 Nicolas Goaziou <[email-masked]>
+;;; Copyright © 2018 Oleg Pykhalov <[email-masked]>
+;;; Copyright © 2018 Clément Lassieur <[email-masked]>
+;;; Copyright © 2018, 2019, 2020, 2021 Maxim Cournoyer <[email-masked]>
+;;; Copyright © 2018 Luther Thompson <[email-masked]>
+;;; Copyright © 2018 Vagrant Cascadian <[email-masked]>
+;;; Copyright © 2019 Tanguy Le Carrour <[email-masked]>
+;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen <[email-masked]>
+;;; Copyright © 2020, 2021 Greg Hogan <[email-masked]>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (gnu packages pypy)
+  #:use-module ((guix licenses) #:prefix license:)
+  #:use-module (gnu packages)
+  #:use-module (gnu packages base)
+  #:use-module (gnu packages bash)
+  #:use-module (gnu packages certs)
+  #:use-module (gnu packages check)
+  #:use-module (gnu packages compression)
+  #:use-module (gnu packages dbm)
+  #:use-module (gnu packages hurd)
+  #:use-module (gnu packages libffi)
+  #:use-module (gnu packages ncurses)
+  #:use-module (gnu packages pkg-config)
+  #:use-module (gnu packages python)
+  #:use-module (gnu packages python-xyz)
+  #:use-module (gnu packages readline)
+  #:use-module (gnu packages shells)
+  #:use-module (gnu packages sqlite)
+  #:use-module (gnu packages tcl)
+  #:use-module (gnu packages tls)
+  #:use-module (gnu packages xml)
+  #:use-module (guix gexp)
+  #:use-module (guix packages)
+  #:use-module (guix download)
+  #:use-module (guix utils)
+  #:use-module (guix build-system gnu)
+  #:use-module (guix build-system trivial)
+  #:use-module (srfi srfi-1)
+  #:use-module (srfi srfi-26))
+
+(define-public pypy
+  (package
+    (name "pypy")
+    (version "7.3.5")
+    (source (origin
+              (method url-fetch)
+              (uri (string-append "https://downloads.python.org/pypy/"
+                                  "pypy3.7-v" version "-src.tar.bz2"))
+              (sha256
+               (base32
+                "18lrdmpcczlbk3cfarkgwqdmilrybz56i1dafk8dkjlyk90gw86r"))))
+    (build-system gnu-build-system)
+    (arguments
+     (list
+      #:tests? #f                      ;FIXME: 43 out of 364 tests are failing
+      #:modules '((ice-9 ftw) (ice-9 match)
+                  (guix build utils) (guix build gnu-build-system))
+      #:disallowed-references (list nss-certs)
+      #:phases
+      #~(modify-phases %standard-phases
+          (delete 'configure)
+          (add-after 'unpack 'patch-source
+            (lambda* (#:key inputs #:allow-other-keys)
+              (substitute* '("rpython/rlib/clibffi.py")
+                ;; find_library does not work for libc
+                (("ctypes\\.util\\.find_library\\('c'\\)") "'libc.so'"))
+              (substitute* '("lib_pypy/cffi/_pycparser/ply/cpp.py")
+                ;; Make reproducible (XXX: unused?)
+                (("time\\.localtime\\(\\)") "time.gmtime(0)"))
+              (substitute* '("pypy/module/sys/version.py")
+                ;; Make reproducible
+                (("t\\.gmtime\\(\\)") "t.gmtime(0)"))
+              (substitute* '("lib_pypy/_tkinter/tklib_build.py")
+                ;; Link to versioned libtcl and libtk
+                (("linklibs = \\['tcl', 'tk'\\]")
+                 "linklibs = ['tcl8.6', 'tk8.6']")
+                (("incdirs = \\[\\]")
+                 (string-append
+                  "incdirs = ['"
+                  #$(this-package-input "tcl") "/include', '"
+                  #$(this-package-input "tk")  "/include']")))
+              (substitute* '("lib_pypy/_curses_build.py")
+                ;; Find curses
+                (("/usr/local")
+                 #$(this-package-input "ncurses")))
+              (substitute* '("lib_pypy/_dbm.py")
+                ;; Use gdbm compat library, so we don’t need to pull
+                ;; in bdb.
+                (("ctypes.util.find_library\\('db'\\)")
+                 (format #f "~s" (search-input-file
+                                  inputs "lib/libgdbm_compat.so"))))
+              (substitute* '("lib_pypy/_sqlite3_build.py")
+                ;; Always use search paths
+                (("sys\\.platform\\.startswith\\('freebsd'\\)") "True")
+                ;; Find sqlite3
+                (("/usr/local") (assoc-ref inputs "sqlite"))
+                (("libname = 'sqlite3'")
+                 (format #f "libname = ~s"
+                         (search-input-file inputs "lib/libsqlite3.so.0"))))
+              (substitute* '("lib-python/3/subprocess.py")
+                ;; Fix shell path
+                (("/bin/sh")
+                 (search-input-file inputs "/bin/sh")))
+              (substitute* '("lib-python/3/distutils/unixccompiler.py")
+                ;; gcc-toolchain does not provide symlink cc -> gcc
+                (("\"cc\"") "\"gcc\""))))
+          (add-after 'unpack 'set-source-file-times-to-1980
+            ;; copied from python package, required by zip testcase
+            (lambda _
+              (let ((circa-1980 (* 10 366 24 60 60)))
+                (ftw "." (lambda (file stat flag)
+                           (utime file circa-1980 circa-1980)
+                           #t)))))
+          (replace 'build
+            (lambda _
+              (with-directory-excursion "pypy/goal"
+                ;; Build with jit optimization.
+                (invoke "python2"
+                        "../../rpython/bin/rpython"
+                        (string-append "--make-jobs="
+                                       (number->string (parallel-job-count)))
+                        "-Ojit"
+                        "targetpypystandalone"
+                        "--allworkingmodules"))
+              ;; Build c modules and package everything, so tests work.
+              (with-directory-excursion "pypy/tool/release"
+                (invoke "python2" "package.py"
+                        "--archive-name" "pypy-dist"
+                        "--builddir" (getcwd)))))
+          (replace 'check
+            (lambda* (#:key tests? #:allow-other-keys)
+              (if tests?
+                  (begin
+                    (setenv "HOME" "/tmp") ; test_with_pip tries to
+                                        ; access ~/.cache/pip
+                    ;; Run library tests only (no interpreter unit tests).
+                    ;; This is what Gentoo does.
+                    (invoke "python" "pypy/test_all.py"
+                            "--pypy=pypy/tool/release/pypy-dist/bin/pypy3"
+                            "lib-python"))
+                  (format #t "test suite not run~%"))))
+          (replace 'install
+            (lambda* (#:key inputs outputs #:allow-other-keys)
+              (let* ((bin-pypy3 (string-append #$output "/bin/pypy3"))
+                     (shebang-match-python "#!.+/bin/python")
+                     (shebang-pypy3 (string-append "#!" bin-pypy3))
+                     (dist-dir "pypy/tool/release/pypy-dist"))
+                (with-directory-excursion dist-dir
+                  ;; Delete test data.
+                  (for-each
+                   (lambda (x)
+                     (delete-file-recursively (string-append
+                                               "lib-python/3/" x)))
+                   '("tkinter/test"
+                     "test"
+                     "sqlite3/test"
+                     "lib2to3/tests"
+                     "idlelib/idle_test"
+                     "distutils/tests"
+                     "ctypes/test"
+                     "unittest/test"))
+                  ;; Patch shebang referencing python.
+                  (substitute* '("lib-python/3/cgi.py"
+                                 "lib-python/3/encodings/rot_13.py")
+                    ((shebang-match-python) shebang-pypy3))
+                  (with-fluids ((%default-port-encoding "ISO-8859-1"))
+                    (substitute* '("lib_pypy/_md5.py"
+                                   "lib_pypy/_sha1.py")
+                      ((shebang-match-python) shebang-pypy3))))
+                (copy-recursively dist-dir #$output)))))))
+    (native-inputs
+     (list gzip
+           nss-certs                    ; For ssl tests
+           pkg-config
+           python-2
+           python2-pycparser
+           tar))                        ; Required for package.py
+    (inputs
+     (list bzip2
+           expat
+           gdbm
+           glibc
+           libffi
+           ncurses
+           openssl
+           sqlite
+           tcl
+           tk
+           xz
+           zlib))
+    (home-page "https://www.pypy.org/")
+    (synopsis "Python implementation with just-in-time compilation")
+    (description "PyPy is a faster, alternative implementation of the Python
+programming language employing a just-in-time compiler.  It supports most
+Python code natively, including C extensions.")
+    (license (list license:expat     ; pypy itself; _pytest/
+                   license:psfl      ; python standard library in lib-python/
+                   license:asl2.0    ; dotviewer/font/ and some of lib-python/
+                   license:gpl3+ ; ./rpython/rlib/rvmprof/src/shared/libbacktrace/dwarf2.*
+                   license:bsd-3 ; lib_pypy/cffi/_pycparser/ply/
+                   (license:non-copyleft
+                    "http://www.unicode.org/copyright.html")))))
+
+(define-public pypy3
+  (deprecated-package "pypy3" pypy))
diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm
index e31158dfc0..00c3eb7774 100644
--- a/gnu/packages/python.scm
+++ b/gnu/packages/python.scm
@@ -81,17 +81,13 @@ (define-module (gnu packages python)
   #:use-module (gnu packages)
   #:use-module (gnu packages base)
   #:use-module (gnu packages bash)
-  #:use-module (gnu packages certs)
   #:use-module (gnu packages check)
   #:use-module (gnu packages compression)
   #:use-module (gnu packages dbm)
   #:use-module (gnu packages hurd)
   #:use-module (gnu packages libffi)
-  #:use-module (gnu packages ncurses)
   #:use-module (gnu packages pkg-config)
-  #:use-module (gnu packages python-xyz)
   #:use-module (gnu packages readline)
-  #:use-module (gnu packages shells)
   #:use-module (gnu packages sqlite)
   #:use-module (gnu packages tcl)
   #:use-module (gnu packages tls)
@@ -736,169 +732,3 @@ (define-public micropython
 compatible with normal Python as possible to allow you to transfer code with
 ease from the desktop to a microcontroller or embedded system.")
     (license license:expat)))
-
-(define-public pypy
-  (package
-    (name "pypy")
-    (version "7.3.5")
-    (source (origin
-              (method url-fetch)
-              (uri (string-append "https://downloads.python.org/pypy/"
-                                  "pypy3.7-v" version "-src.tar.bz2"))
-              (sha256
-               (base32
-                "18lrdmpcczlbk3cfarkgwqdmilrybz56i1dafk8dkjlyk90gw86r"))))
-    (build-system gnu-build-system)
-    (arguments
-     (list
-      #:tests? #f                      ;FIXME: 43 out of 364 tests are failing
-      #:modules '((ice-9 ftw) (ice-9 match)
-                  (guix build utils) (guix build gnu-build-system))
-      #:disallowed-references (list nss-certs)
-      #:phases
-      #~(modify-phases %standard-phases
-          (delete 'configure)
-          (add-after 'unpack 'patch-source
-            (lambda* (#:key inputs #:allow-other-keys)
-              (substitute* '("rpython/rlib/clibffi.py")
-                ;; find_library does not work for libc
-                (("ctypes\\.util\\.find_library\\('c'\\)") "'libc.so'"))
-              (substitute* '("lib_pypy/cffi/_pycparser/ply/cpp.py")
-                ;; Make reproducible (XXX: unused?)
-                (("time\\.localtime\\(\\)") "time.gmtime(0)"))
-              (substitute* '("pypy/module/sys/version.py")
-                ;; Make reproducible
-                (("t\\.gmtime\\(\\)") "t.gmtime(0)"))
-              (substitute* '("lib_pypy/_tkinter/tklib_build.py")
-                ;; Link to versioned libtcl and libtk
-                (("linklibs = \\['tcl', 'tk'\\]")
-                 "linklibs = ['tcl8.6', 'tk8.6']")
-                (("incdirs = \\[\\]")
-                 (string-append
-                  "incdirs = ['"
-                  #$(this-package-input "tcl") "/include', '"
-                  #$(this-package-input "tk")  "/include']")))
-              (substitute* '("lib_pypy/_curses_build.py")
-                ;; Find curses
-                (("/usr/local")
-                 #$(this-package-input "ncurses")))
-              (substitute* '("lib_pypy/_dbm.py")
-                ;; Use gdbm compat library, so we don’t need to pull
-                ;; in bdb.
-                (("ctypes.util.find_library\\('db'\\)")
-                 (format #f "~s" (search-input-file
-                                  inputs "lib/libgdbm_compat.so"))))
-              (substitute* '("lib_pypy/_sqlite3_build.py")
-                ;; Always use search paths
-                (("sys\\.platform\\.startswith\\('freebsd'\\)") "True")
-                ;; Find sqlite3
-                (("/usr/local") (assoc-ref inputs "sqlite"))
-                (("libname = 'sqlite3'")
-                 (format #f "libname = ~s"
-                         (search-input-file inputs "lib/libsqlite3.so.0"))))
-              (substitute* '("lib-python/3/subprocess.py")
-                ;; Fix shell path
-                (("/bin/sh")
-                 (search-input-file inputs "/bin/sh")))
-              (substitute* '("lib-python/3/distutils/unixccompiler.py")
-                ;; gcc-toolchain does not provide symlink cc -> gcc
-                (("\"cc\"") "\"gcc\""))))
-          (add-after 'unpack 'set-source-file-times-to-1980
-            ;; copied from python package, required by zip testcase
-            (lambda _
-              (let ((circa-1980 (* 10 366 24 60 60)))
-                (ftw "." (lambda (file stat flag)
-                           (utime file circa-1980 circa-1980)
-                           #t)))))
-          (replace 'build
-            (lambda _
-              (with-directory-excursion "pypy/goal"
-                ;; Build with jit optimization.
-                (invoke "python2"
-                        "../../rpython/bin/rpython"
-                        (string-append "--make-jobs="
-                                       (number->string (parallel-job-count)))
-                        "-Ojit"
-                        "targetpypystandalone"
-                        "--allworkingmodules"))
-              ;; Build c modules and package everything, so tests work.
-              (with-directory-excursion "pypy/tool/release"
-                (invoke "python2" "package.py"
-                        "--archive-name" "pypy-dist"
-                        "--builddir" (getcwd)))))
-          (replace 'check
-            (lambda* (#:key tests? #:allow-other-keys)
-              (if tests?
-                  (begin
-                    (setenv "HOME" "/tmp") ; test_with_pip tries to
-                                        ; access ~/.cache/pip
-                    ;; Run library tests only (no interpreter unit tests).
-                    ;; This is what Gentoo does.
-                    (invoke "python" "pypy/test_all.py"
-                            "--pypy=pypy/tool/release/pypy-dist/bin/pypy3"
-                            "lib-python"))
-                  (format #t "test suite not run~%"))))
-          (replace 'install
-            (lambda* (#:key inputs outputs #:allow-other-keys)
-              (let* ((bin-pypy3 (string-append #$output "/bin/pypy3"))
-                     (shebang-match-python "#!.+/bin/python")
-                     (shebang-pypy3 (string-append "#!" bin-pypy3))
-                     (dist-dir "pypy/tool/release/pypy-dist"))
-                (with-directory-excursion dist-dir
-                  ;; Delete test data.
-                  (for-each
-                   (lambda (x)
-                     (delete-file-recursively (string-append
-                                               "lib-python/3/" x)))
-                   '("tkinter/test"
-                     "test"
-                     "sqlite3/test"
-                     "lib2to3/tests"
-                     "idlelib/idle_test"
-                     "distutils/tests"
-                     "ctypes/test"
-                     "unittest/test"))
-                  ;; Patch shebang referencing python.
-                  (substitute* '("lib-python/3/cgi.py"
-                                 "lib-python/3/encodings/rot_13.py")
-                    ((shebang-match-python) shebang-pypy3))
-                  (with-fluids ((%default-port-encoding "ISO-8859-1"))
-                    (substitute* '("lib_pypy/_md5.py"
-                                   "lib_pypy/_sha1.py")
-                      ((shebang-match-python) shebang-pypy3))))
-                (copy-recursively dist-dir #$output)))))))
-    (native-inputs
-     (list gzip
-           nss-certs                    ; For ssl tests
-           pkg-config
-           python-2
-           python2-pycparser
-           tar))                        ; Required for package.py
-    (inputs
-     (list bzip2
-           expat
-           gdbm
-           glibc
-           libffi
-           ncurses
-           openssl
-           sqlite
-           tcl
-           tk
-           xz
-           zlib))
-    (home-page "https://www.pypy.org/")
-    (synopsis "Python implementation with just-in-time compilation")
-    (description "PyPy is a faster, alternative implementation of the Python
-programming language employing a just-in-time compiler.  It supports most
-Python code natively, including C extensions.")
-    (license (list license:expat     ; pypy itself; _pytest/
-                   license:psfl      ; python standard library in lib-python/
-                   license:asl2.0    ; dotviewer/font/ and some of lib-python/
-                   license:gpl3+ ; ./rpython/rlib/rvmprof/src/shared/libbacktrace/dwarf2.*
-                   license:bsd-3 ; lib_pypy/cffi/_pycparser/ply/
-                   (license:non-copyleft
-                    "http://www.unicode.org/copyright.html")))))
-
-(define-public pypy3
-  (deprecated-package "pypy3" pypy))
-- 
2.38.0