~ruther/guix-local

ref: 1232e5352621befc6eefeda0ffec55c5bdf5df64 guix-local/gnu/packages/pypy.scm -rw-r--r-- 15.3 KiB
1232e535 — Hilton Chain gnu: rust-crates: Add ‘package:’ prefix for replaced crates. 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2021 Lars-Dominik Braun <lars@6xq.net>
;;; Copyright © 2021 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2021, 2022, 2025 Maxim Cournoyer <maxim@guixotic.coop>
;;; Copyright © 2021 Leo Famulari <leo@famulari.name>
;;; Copyright © 2025 Laura Kirsch <laurakirsch240406@gmail.com>
;;;
;;; 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 base)
  #:use-module (gnu packages nss)
  #:use-module (gnu packages compression)
  #:use-module (gnu packages dbm)
  #: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 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))

;;; This Python 2 alternative implementation is useful for allowing faster
;;; iterations on the development of Pypy 3.
(define-public pypy2
  (package
    (name "pypy2")
    (version "7.3.20")
    (source (origin
              (method url-fetch)
              (uri (string-append "https://downloads.python.org/pypy/"
                                  "pypy2.7-v" version "-src.tar.bz2"))
              (sha256
               (base32
                "0qiyd9bajxyzh4j5swk14iwyh4b7pn38sg3j721zfysz8jc895dz"))))
    (build-system gnu-build-system)
    (arguments
     (list
      #:modules '((ice-9 ftw) (ice-9 match)
                  (guix build utils) (guix build gnu-build-system))
      ;; The stdlib tests do not all pass, this is known and tracked upstream
      ;; on their buildbot instance, for example at:
      ;; <https://buildbot.pypy.org/summary?branch=py3.11>.  That's also true
      ;; for Pypy 3.  The tests are also disabled to avoid having to package
      ;; extra Python 2 dependencies like python2-hypothesis.
      #:tests? #f
      ;; XXX: ELF file 'pypy.debug' makes 'validate-needed-in-runpath' throw:
      ;; <https://issues.guix.gnu.org/57653>.
      #:validate-runpath? #f
      #: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/2.7/subprocess.py")
                ;; Fix shell path
                (("/bin/sh")
                 (search-input-file inputs "/bin/sh")))
              (substitute* '("lib-python/2.7/distutils/unixccompiler.py")
                ;; gcc-toolchain does not provide symlink cc -> gcc
                (("\"cc\"") (format #f "~s" #$(cc-for-target))))
              (substitute* "lib-python/2.7/distutils/sysconfig_pypy.py"
                (("\"cc ")
                 (string-append "\"" #$(cc-for-target) " ")))))
          (add-after 'unpack 'use-libffi.so
            (lambda _
              (substitute* "rpython/rlib/clibffi.py"
                (("\"libffi\\.a\"")
                 "\"libffi.so\""))))
          (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 _
              (setenv "CC" #$(cc-for-target))
              (with-directory-excursion "pypy/goal"
                ;; Build with jit optimization.
                (invoke "python2"
                        "../../rpython/bin/rpython"
                        (string-append "--cc=" #$(cc-for-target))
                        (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 'install
            (lambda* (#:key inputs outputs #:allow-other-keys)
              (let* ((bin-pypy2 (string-append #$output "/bin/pypy2"))
                     (shebang-match-python "#!.+/bin/python")
                     (shebang-pypy2 (string-append "#!" bin-pypy2))
                     (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/2.7/" x)))
                   '("lib-tk/test"
                     "test"
                     "lib2to3/tests"
                     "idlelib/idle_test"
                     "distutils/tests"
                     "ctypes/test"
                     "unittest/test"))
                  ;; Patch shebang referencing python.
                  (substitute* '("lib-python/2.7/cgi.py"
                                 "lib-python/2.7/encodings/rot_13.py")
                    ((shebang-match-python) shebang-pypy2)))
                (copy-recursively dist-dir #$output)))))))
    (native-inputs
     (list nss-certs                    ; For ssl tests
           pkg-config
           python-2
           python2-cffi))
    (inputs
     (list bzip2
           expat
           gdbm
           libffi
           ncurses
           openssl
           sqlite
           tcl
           tk
           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 pypy
  (package
    (inherit pypy2)
    (name "pypy")
    (version "7.3.20")
    (source (origin
              (method url-fetch)
              (uri (string-append "https://downloads.python.org/pypy/"
                                  "pypy3.11-v" version "-src.tar.bz2"))
              (sha256
               (base32
                "1yq6n888fxfdqid29q3w8bn7ii800bjkf44w82kjwgh0c2kxv1kp"))))
    (arguments
     (substitute-keyword-arguments (package-arguments pypy2)
       ((#:phases phases)
        #~(modify-phases #$phases
            (replace 'patch-source
              ;; Overridden from pypy2 because some file names have changed.
              (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\"") (format #f "~s" #$(cc-for-target))))))
            (replace 'build
              (lambda _
                (with-directory-excursion "pypy/goal"
                  ;; Build with jit optimization.
                  (invoke "pypy2"
                          "../../rpython/bin/rpython"
                          (string-append "--cc=" #$(cc-for-target))
                          (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 "pypy2" "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/pypy3.11/" x)))
                     '("tkinter/test"
                       "test"
                       "lib2to3/tests"
                       "idlelib/idle_test"
                       "distutils/tests"
                       "ctypes/test"
                       "unittest/test"))
                    ;; Patch shebang referencing python.
                    (substitute* '("lib/pypy3.11/cgi.py"
                                   "lib/pypy3.11/encodings/rot_13.py")
                      ((shebang-match-python) shebang-pypy3))
                    (with-fluids ((%default-port-encoding "ISO-8859-1"))
                      (substitute* '("lib/pypy3.11/_md5.py"
                                     "lib/pypy3.11/_sha1.py")
                        ((shebang-match-python) shebang-pypy3))))
                  (copy-recursively dist-dir #$output))))))))
    (native-inputs
     (modify-inputs (package-native-inputs pypy2)
       (replace "python2" pypy2)))
    (inputs
     (modify-inputs (package-inputs pypy2)
       (append xz)))))

(define-deprecated-package pypy3
  pypy)