aboutsummaryrefslogtreecommitdiff
path: root/tests/status.scm
blob: b0af6198723c19a00b78465d3f21b876602b3d09 (about) (plain)
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
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2018, 2019, 2022 Ludovic Courtès <ludo@gnu.org>
;;;
;;; 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 (test-status)
  #:use-module (guix status)
  #:use-module (srfi srfi-1)
  #:use-module (srfi srfi-64)
  #:use-module (srfi srfi-71)
  #:use-module (rnrs bytevectors)
  #:use-module (rnrs io ports)
  #:use-module (ice-9 match))

(test-begin "status")

(test-equal "compute-status, no-op"
  (build-status)
  (let ((port get-status (build-event-output-port compute-status)))
    (display "foo\nbar\n\baz\n" port)
    (get-status)))

(test-equal "compute-status, builds + substitutes"
  (list (build-status
         (building (list (build "foo.drv" "x86_64-linux")))
         (downloading (list (download "bar" "http://example.org/bar"
                                      #:size 500
                                      #:start 'now))))
        (build-status
         (building (list (build "foo.drv" "x86_64-linux")))
         (downloading (list (download "bar" "http://example.org/bar"
                                      #:size 500
                                      #:transferred 42
                                      #:start 'now))))
        (build-status
         (builds-completed (list (build "foo.drv" "x86_64-linux")))
         (downloads-completed (list (download "bar" "http://example.org/bar"
                                              #:size 500
                                              #:transferred 500
                                              #:start 'now
                                              #:end 'now)))))
  (let ((port get-status
              (build-event-output-port (lambda (event status)
                                         (compute-status event status
                                                         #:current-time
                                                         (const 'now))))))
    (display "@ build-started foo.drv - x86_64-linux \n" port)
    (display "@ substituter-started bar\n" port)
    (display "@ download-started bar http://example.org/bar 500\n" port)
    (display "various\nthings\nget\nwritten\n" port)
    (let ((first (get-status)))
      (display "@ download-progress bar http://example.org/bar 500 42\n"
               port)
      (let ((second (get-status)))
        (display "@ download-progress bar http://example.org/bar 500 84\n"
                 port)
        (display "@ build-succeeded foo.drv\n" port)
        (display "@ download-succeeded bar http://example.org/bar 500\n" port)
        (display "Almost done!\n" port)
        (display "@ substituter-succeeded bar\n" port)
        (list first second (get-status))))))

(test-equal "compute-status, missing events"
  (list (build-status
         (building (list (build "foo.drv" "x86_64-linux"
                                #:log-file "foo.log")))
         (downloading (list (download "baz" "http://example.org/baz"
                                      #:size 500
                                      #:transferred 42
                                      #:start 'now)
                            (download "bar" "http://example.org/bar"
                                      #:size 999
                                      #:transferred 0
                                      #:start 'now))))
        (build-status
         (builds-completed (list (build "foo.drv" "x86_64-linux"
                                        #:log-file "foo.log")))
         (downloads-completed (list (download "baz" "http://example.org/baz"
                                              #:size 500
                                              #:transferred 500
                                              #:start 'now
                                              #:end 'now)
                                    (download "bar" "http://example.org/bar"
                                              #:size 999
                                              #:transferred 999
                                              #:start 'now
                                              #:end 'now)))))
  ;; Below we omit 'substituter-started' events and the like.
  (let ((port get-status
              (build-event-output-port (lambda (event status)
                                         (compute-status event status
                                                         #:current-time
                                                         (const 'now))))))
    (display "@ build-started foo.drv - x86_64-linux foo.log\n" port)
    (display "@ download-started bar http://example.org/bar 999\n" port)
    (display "various\nthings\nget\nwritten\n" port)
    (display "@ download-progress baz http://example.org/baz 500 42\n"
             port)
    (let ((first (get-status)))
      (display "@ build-succeeded foo.drv\n" port)
      (display "@ download-succeeded bar http://example.org/bar 999\n" port)
      (display "Almost done!\n" port)
      (display "@ substituter-succeeded baz\n" port)
      (list first (get-status)))))

(test-equal "build-output-port, UTF-8"
  '((build-log #f "lambda is λ!\n"))
  (let ((port get-status (build-event-output-port cons '()))
        (bv              (string->utf8 "lambda is λ!\n")))
    (put-bytevector port bv)
    (force-output port)
    (get-status)))

(test-equal "build-output-port, daemon messages with LF"
  '((build-log #f "updating substitutes... 0%\r")
    (build-log #f "updating substitutes... 50%\r")
    (build-log #f "updating substitutes... 100%\r"))
  (let ((port get-status (build-event-output-port cons '())))
    (for-each (lambda (suffix)
                (let ((bv (string->utf8
                           (string-append "updating substitutes... "
                                          suffix "\r"))))
                  (put-bytevector port bv)
                  (force-output port)))
              '("0%" "50%" "100%"))
    (reverse (get-status))))

(test-equal "current-build-output-port, UTF-8 + garbage"
  ;; What about a mixture of UTF-8 + garbage?
  (let ((replacement "�"))
    `((build-log #f ,(string-append "garbage: " replacement "lambda: λ\n"))))
  (let ((port get-status (build-event-output-port cons '())))
    (display "garbage: " port)
    (put-bytevector port #vu8(128))
    (put-bytevector port (string->utf8 "lambda: λ\n"))
    (force-output port)
    (get-status)))

(test-equal "compute-status, multiplexed build output"
  (list (build-status
         (building (list (build "foo.drv" "x86_64-linux" #:id 121)))
         (downloading (list (download "bar" "http://example.org/bar"
                                      #:size 999
                                      #:start 'now))))
        (build-status
         (building (list (build "foo.drv" "x86_64-linux" #:id 121)))
         (downloading (list (download "bar" "http://example.org/bar"
                                      #:size 999
                                      #:transferred 42
                                      #:start 'now))))
        (build-status
         ;; "bar" is now only listed as a download.
         (builds-completed (list (build "foo.drv" "x86_64-linux" #:id 121)))
         (downloads-completed (list (download "bar" "http://example.org/bar"
                                              #:size 999
                                              #:transferred 999
                                              #:start 'now
                                              #:end 'now)))))
  (let ((port get-status
              (build-event-output-port (lambda (event status)
                                         (compute-status event status
                                                         #:current-time
                                                         (const 'now)
                                                         #:derivation-path->output-path
                                                         (match-lambda
                                                           ("bar.drv" "bar")))))))
    (display "@ build-started foo.drv - x86_64-linux  121\n" port)
    (display "@ build-started bar.drv - armhf-linux bar.log 144\n" port)
    (display "@ build-log 121 6\nHello!" port)
    (display "@ build-log 144 50
@ download-started bar http://example.org/bar 999\n" port)
    (let ((first (get-status)))
      (display "@ build-log 121 30\n@ build-started FAKE!.drv 555\n")
      (display "@ build-log 144 54
@ download-progress bar http://example.org/bar 999 42\n"
               port)
      (let ((second (get-status)))
        (display "@ download-succeeded bar http://example.org/bar 999\n" port)
        (display "@ build-succeeded foo.drv\n" port)
        (display "@ build-succeeded bar.drv\n" port)
        (list first second (get-status))))))

(test-equal "compute-status, build completion"
  (list (build-status
         (building (list (build "foo.drv" "x86_64-linux" #:id 121))))
        (build-status
         (building (list (build "foo.drv" "x86_64-linux" #:id 121
                                #:completion 0.))))
        (build-status
         (building (list (build "foo.drv" "x86_64-linux" #:id 121
                                #:completion 50.))))
        (build-status
         (builds-completed (list (build "foo.drv" "x86_64-linux" #:id 121
                                        #:completion 100.)))))
  (let ((port get-status
              (build-event-output-port (lambda (event status)
                                         (compute-status event status
                                                         #:current-time
                                                         (const 'now))))))
    (display "@ build-started foo.drv - x86_64-linux  121\n" port)
    (display "@ build-log 121 6\nHello!" port)
    (let ((first (get-status)))
      (display "@ build-log 121 20\n[ 0/100] building X\n" port)
      (display "@ build-log 121 6\nHello!" port)
      (let ((second (get-status)))
        (display "@ build-log 121 20\n[50/100] building Y\n" port)
        (display "@ build-log 121 6\nHello!" port)
        (let ((third (get-status)))
          (display "@ build-log 121 21\n[100/100] building Z\n" port)
          (display "@ build-log 121 6\nHello!" port)
          (display "@ build-succeeded foo.drv\n" port)
          (list first second third (get-status)))))))

(test-equal "compute-status, build phase"
  (list (build-status
         (building (list (build "foo.drv" "x86_64-linux" #:id 121
                                #:phase 'configure))))
        (build-status
         (building (list (build "foo.drv" "x86_64-linux" #:id 121
                                #:phase 'configure
                                #:completion 50.))))
        (build-status
         (building (list (build "foo.drv" "x86_64-linux" #:id 121
                                #:phase 'install))))
        (build-status
         (builds-completed (list (build "foo.drv" "x86_64-linux" #:id 121
                                        #:phase 'install)))))
  (let ((port get-status
              (build-event-output-port (lambda (event status)
                                         (compute-status event status
                                                         #:current-time
                                                         (const 'now))))))
    (display "@ build-started foo.drv - x86_64-linux  121\n" port)
    (display "@ build-log 121 27\nstarting phase `configure'\n" port)
    (display "@ build-log 121 6\nabcde!" port)
    (let ((first (get-status)))
      (display "@ build-log 121 20\n[50/100] building Y\n" port)
      (display "@ build-log 121 6\nfghik!" port)
      (let ((second (get-status)))
        (display "@ build-log 121 21\n[100/100] building Z\n" port)
        (display "@ build-log 121 25\nstarting phase `install'\n" port)
        (display "@ build-log 121 6\nlmnop!" port)
        (let ((third (get-status)))
          (display "@ build-succeeded foo.drv\n" port)
          (list first second third (get-status)))))))

(test-end "status")
> ;;; Copyright © 2016, 2017, 2018 Tobias Geerinckx-Rice <me@tobias.gr> ;;; Copyright © 2016, 2017 Thomas Danckaert <post@thomasdanckaert.be> ;;; Copyright © 2017 Carlo Zancanaro <carlo@zancanaro.id.au> ;;; Copyright © 2017 Frederick M. Muriithi <fredmanglis@gmail.com> ;;; Copyright © 2017, 2018 Adriano Peluso <catonano@gmail.com> ;;; Copyright © 2017 Ben Sturmfels <ben@sturm.com.au> ;;; Copyright © 2017, 2018 Mathieu Othacehe <m.othacehe@gmail.com> ;;; Copyright © 2017 José Miguel Sánchez García <jmi2k@openmailbox.org> ;;; Copyright © 2017 Roel Janssen <roel@gnu.org> ;;; Copyright © 2017, 2018 Kei Kebreau <kkebreau@posteo.net> ;;; Copyright © 2017 Rutger Helling <rhelling@mykolab.com> ;;; Copyright © 2017 Muriithi Frederick Muriuki <fredmanglis@gmail.com> ;;; Copyright © 2017 Brendan Tildesley <mail@brendan.scot> ;;; Copyright © 2018 Ethan R. Jones <ethanrjones97@gmail.com ;;; Copyright © 2018 Fis Trivial <ybbs.daans@hotmail.com> ;;; Copyright © 2018 Vijayalakshmi Vedantham <vijimay12@gmail.com> ;;; Copyright © 2018 Mathieu Lirzin <mthl@gnu.org> ;;; Copyright © 2018 Adam Massmann <massmannak@gmail.com> ;;; Copyright © 2016, 2018 Tomáš Čech <sleep_walker@gnu.org> ;;; Copyright © 2018 Nicolas Goaziou <mail@nicolasgoaziou.fr> ;;; Copyright © 2018 Oleg Pykhalov <go.wigust@gmail.com> ;;; Copyright © 2018 Clément Lassieur <clement@lassieur.org> ;;; Copyright © 2018, 2019 Maxim Cournoyer <maxim.cournoyer@gmail.com> ;;; Copyright © 2018 Luther Thompson <lutheroto@gmail.com> ;;; Copyright © 2018 Vagrant Cascadian <vagrant@debian.org> ;;; ;;; 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 python) #:use-module ((guix licenses) #:prefix license:) #:use-module (gnu packages) #:use-module (gnu packages base) #:use-module (gnu packages bash) #:use-module (gnu packages compression) #:use-module (gnu packages dbm) #:use-module (gnu packages libffi) #:use-module (gnu packages pkg-config) #:use-module (gnu packages readline) #:use-module (gnu packages sqlite) #:use-module (gnu packages tcl) #:use-module (gnu packages tls) #:use-module (gnu packages xml) #:use-module (guix packages) #:use-module (guix download) #:use-module (guix utils) #:use-module (guix build-system gnu) #:use-module (guix build-system trivial)) (define-public python-2.7 (package (name "python2") (version "2.7.16") (source (origin (method url-fetch) (uri (string-append "https://www.python.org/ftp/python/" version "/Python-" version ".tar.xz")) (sha256 (base32 "1mqfcqp5y8r0bfyr7ppl74n0lig45p9mc4b8adlcpvj74rhfy8pj")) (patches (search-patches "python-2.7-search-paths.patch" "python-2-deterministic-build-info.patch" "python-2.7-site-prefixes.patch" "python-2.7-source-date-epoch.patch" "python-2.7-adjust-tests.patch")) (modules '((guix build utils))) (snippet '(begin ;; Ensure the bundled copies of these libraries are not used. (for-each delete-file-recursively '("Modules/_ctypes/libffi" "Modules/expat" "Modules/zlib")) (substitute* "Modules/Setup.dist" ;; Link Expat instead of embedding the bundled one. (("^#pyexpat.*") "pyexpat pyexpat.c -lexpat\n")) ;; Suboptimal to delete failing tests here, but if we delete them in ;; the arguments then we need to make sure to strip out that phase ;; when it gets inherited by python and python-minimal. (for-each delete-file '("Lib/test/test_compileall.py" "Lib/test/test_ctypes.py" ; fails on mips64el "Lib/test/test_distutils.py" "Lib/test/test_import.py" "Lib/test/test_shutil.py" "Lib/test/test_socket.py" "Lib/test/test_subprocess.py")) #t)))) (outputs '("out" "tk")) ;tkinter; adds 50 MiB to the closure (build-system gnu-build-system) (arguments `(#:test-target "test" #:configure-flags (list "--enable-shared" ;allow embedding "--with-system-expat" ;for XML support "--with-system-ffi" ;build ctypes "--with-ensurepip=install" ;install pip and setuptools "--enable-unicode=ucs4" ;; Prevent the installed _sysconfigdata.py from retaining a reference ;; to coreutils. "INSTALL=install -c" "MKDIR_P=mkdir -p" (string-append "LDFLAGS=-Wl,-rpath=" (assoc-ref %outputs "out") "/lib")) ;; With no -j argument tests use all available cpus, so provide one. #:make-flags (list (string-append (format #f "TESTOPTS=-j~d" (parallel-job-count)) ;; Exclude the following tests as they fail ;; non-deterministically with "error: [Errno 104] Connection ;; reset by peer." Python 3 seems unaffected. A potential fix, ;; yet to be backported to Python 2, is available at: ;; https://github.com/python/cpython/commit/529525fb5a8fd9b96ab4021311a598c77588b918. " --exclude test_urllib2_localnet test_httplib")) #:modules ((ice-9 ftw) (ice-9 match) (guix build utils) (guix build gnu-build-system)) #:phases (modify-phases %standard-phases (add-before 'configure 'patch-lib-shells (lambda _ ;; Filter for existing files, since some may not exist in all ;; versions of python that are built with this recipe. (substitute* (filter file-exists? '("Lib/subprocess.py" "Lib/popen2.py" "Lib/distutils/tests/test_spawn.py" "Lib/test/support/__init__.py" "Lib/test/test_subprocess.py")) (("/bin/sh") (which "sh"))) #t)) (add-before 'configure 'do-not-record-configure-flags (lambda* (#:key configure-flags #:allow-other-keys) ;; Remove configure flags from the installed '_sysconfigdata.py' ;; and 'Makefile' so we don't end up keeping references to the ;; build tools. ;; ;; Preserve at least '--with-system-ffi' since otherwise the ;; thing tries to build libffi, fails, and we end up with a ;; Python that lacks ctypes. (substitute* "configure" (("^CONFIG_ARGS=.*$") (format #f "CONFIG_ARGS='~a'\n" (if (member "--with-system-ffi" configure-flags) "--with-system-ffi" "")))) #t)) (add-before 'check 'pre-check (lambda _ ;; 'Lib/test/test_site.py' needs a valid $HOME (setenv "HOME" (getcwd)) #t)) (add-after 'unpack 'set-source-file-times-to-1980 ;; XXX One of the tests uses a ZIP library to pack up some of the ;; source tree, and fails with "ZIP does not support timestamps ;; before 1980". Work around this by setting the file times in the ;; source tree to sometime in early 1980. (lambda _ (let ((circa-1980 (* 10 366 24 60 60))) (ftw "." (lambda (file stat flag) (utime file circa-1980 circa-1980) #t)) #t))) (add-after 'install 'remove-tests ;; Remove 25 MiB of unneeded unit tests. Keep test_support.* ;; because these files are used by some libraries out there. (lambda* (#:key outputs #:allow-other-keys) (let ((out (assoc-ref outputs "out"))) (match (scandir (string-append out "/lib") (lambda (name) (string-prefix? "python" name))) ((pythonX.Y) (let ((testdir (string-append out "/lib/" pythonX.Y "/test"))) (with-directory-excursion testdir (for-each delete-file-recursively (scandir testdir (match-lambda ((or "." "..") #f) ("support" #f) (file (not (string-prefix? "test_support." file)))))) (call-with-output-file "__init__.py" (const #t)) #t))))))) (add-after 'remove-tests 'rebuild-bytecode (lambda* (#:key outputs #:allow-other-keys) (let ((out (assoc-ref outputs "out"))) ;; Disable hash randomization to ensure the generated .pycs ;; are reproducible. (setenv "PYTHONHASHSEED" "0") (for-each (lambda (opt) (format #t "Compiling with optimization level: ~a\n" (if (null? opt) "none" (car opt))) (for-each (lambda (file) (apply invoke `(,(string-append out "/bin/python") ,@opt "-m" "compileall" "-f" ; force rebuild ;; Don't build lib2to3, because it contains Python 3 code. "-x" "lib2to3/.*" ,file))) (find-files out "\\.py$"))) (list '() '("-O") '("-OO"))) #t))) (add-after 'install 'move-tk-inter (lambda* (#:key outputs #:allow-other-keys) ;; When Tkinter support is built move it to a separate output so ;; that the main output doesn't contain a reference to Tcl/Tk. (let ((out (assoc-ref outputs "out")) (tk (assoc-ref outputs "tk"))) (when tk (match (find-files out "tkinter.*\\.so") ((tkinter.so) ;; The .so is in OUT/lib/pythonX.Y/lib-dynload, but we ;; want it under TK/lib/pythonX.Y/site-packages. (let* ((len (string-length out)) (target (string-append tk "/" (string-drop (dirname (dirname tkinter.so)) len) "/site-packages"))) (install-file tkinter.so target) (delete-file tkinter.so))))) #t)))))) (inputs `(("bzip2" ,bzip2) ("expat" ,expat) ("gdbm" ,gdbm) ("libffi" ,libffi) ; for ctypes ("sqlite" ,sqlite) ; for sqlite extension ("openssl" ,openssl) ("readline" ,readline) ("zlib" ,zlib) ("tcl" ,tcl) ("tk" ,tk))) ; for tkinter (native-inputs `(("pkg-config" ,pkg-config))) (native-search-paths (list (search-path-specification (variable "PYTHONPATH") (files '("lib/python2.7/site-packages"))))) (home-page "https://www.python.org") (synopsis "High-level, dynamically-typed programming language") (description "Python is a remarkably powerful dynamic programming language that is used in a wide variety of application domains. Some of its key distinguishing features include: clear, readable syntax; strong introspection capabilities; intuitive object orientation; natural expression of procedural code; full modularity, supporting hierarchical packages; exception-based error handling; and very high level dynamic data types.") (properties '((cpe-name . "python"))) (license license:psfl))) ;; Current 2.x version. (define-public python-2 python-2.7) (define-public python2-called-python ;; Both 2.x and 3.x used to be called "python". In commit ;; a7714d42de2c3082f3609d1e63c83d703fb39cf9 (March 2018), we renamed the ;; Python 2.x package to "python2". (package (inherit python-2) (name "python") (properties `((superseded . ,python-2))))) (define-public python-3.7 (package (inherit python-2) (name "python") (version "3.7.4") (source (origin (method url-fetch) (uri (string-append "https://www.python.org/ftp/python/" version "/Python-" version ".tar.xz")) (patches (search-patches "python-3-fix-tests.patch" "python-3-deterministic-build-info.patch" "python-3-search-paths.patch")) (sha256 (base32 "0gxiv5617zd7dnqm5k9r4q2188lk327nf9jznwq9j6b8p0s92ygv")) (modules '((guix build utils))) (snippet '(begin ;; Delete the bundled copy of libexpat. (delete-file-recursively "Modules/expat") (substitute* "Modules/Setup.dist" ;; Link Expat instead of embedding the bundled one. (("^#pyexpat.*") "pyexpat pyexpat.c -lexpat\n")) #t)))) (arguments (substitute-keyword-arguments (package-arguments python-2) ((#:make-flags _) `(list (string-append (format #f "TESTOPTS=-j~d" (parallel-job-count)) ;; test_mmap fails on low-memory systems. " --exclude test_mmap" ;; test_socket may hang and eventually run out of memory ;; on some systems: <https://bugs.python.org/issue34587>. " test_socket" ;; XXX: test_ctypes fails on some platforms due to a problem in ;; libffi 3.2.1: <https://bugs.python.org/issue23249>. ,@(if (string-prefix? "aarch64" (%current-system)) '(" test_ctypes") '())))) ((#:phases phases) `(modify-phases ,phases (add-before 'check 'set-TZDIR (lambda* (#:key inputs #:allow-other-keys) ;; test_email requires the Olson time zone database. (setenv "TZDIR" (string-append (assoc-ref inputs "tzdata") "/share/zoneinfo")) #t)) ;; Unset SOURCE_DATE_EPOCH while running the test-suite and set it ;; again afterwards. See <https://bugs.python.org/issue34022>. (add-before 'check 'unset-SOURCE_DATE_EPOCH (lambda _ (unsetenv "SOURCE_DATE_EPOCH") #t)) (add-after 'check 'reset-SOURCE_DATE_EPOCH (lambda _ (setenv "SOURCE_DATE_EPOCH" "1") #t)) (replace 'rebuild-bytecode (lambda* (#:key outputs #:allow-other-keys) (let ((out (assoc-ref outputs "out"))) ;; Disable hash randomization to ensure the generated .pycs ;; are reproducible. (setenv "PYTHONHASHSEED" "0") (for-each (lambda (opt) (format #t "Compiling with optimization level: ~a\n" (if (null? opt) "none" (car opt))) (for-each (lambda (file) (apply invoke `(,(string-append out "/bin/python3") ,@opt "-m" "compileall" "-f" ; force rebuild ;; Don't build lib2to3, because it's Python 2 code. "-x" "lib2to3/.*" ,file))) (find-files out "\\.py$"))) (list '() '("-O") '("-OO"))) #t))))))) (native-inputs `(("tzdata" ,tzdata-for-tests) ,@(package-native-inputs python-2))) (native-search-paths (list (search-path-specification (variable "PYTHONPATH") (files (list (string-append "lib/python" (version-major+minor version) "/site-packages")))))))) ;; Current 3.x version. (define-public python-3 python-3.7) ;; Current major version. (define-public python python-3) ;; Minimal variants of Python, mostly used to break the cycle between Tk and ;; Python (Tk -> libxcb -> Python.) (define-public python2-minimal (package/inherit python-2 (name "python2-minimal") (outputs '("out")) ;; Keep zlib, which is used by 'pip' (via the 'zipimport' module), which ;; is invoked upon 'make install'. 'pip' also expects 'ctypes' and thus ;; libffi. Expat is needed for XML support which is expected by a lot ;; of libraries out there. (inputs `(("expat" ,expat) ("libffi" ,libffi) ("zlib" ,zlib))))) (define-public python-minimal (package/inherit python (name "python-minimal") (outputs '("out")) ;; Build fails due to missing ctypes without libffi. ;; OpenSSL is a mandatory dependency of Python 3.x, for urllib; ;; zlib is required by 'zipimport', used by pip. Expat is needed ;; for XML support, which is generally expected to be available. (inputs `(("expat" ,expat) ("libffi" ,libffi) ("openssl" ,openssl) ("zlib" ,zlib))))) (define-public python-debug (package/inherit python (name "python-debug") (outputs '("out" "debug")) (build-system gnu-build-system) (arguments (substitute-keyword-arguments (package-arguments python) ((#:configure-flags flags '()) `(cons "--with-pydebug" ,flags)))) (synopsis "High-level, dynamically-typed programming language (for debugging)") (description "This variant of Python provides an interpreter built with @code{--with-pydebug} to help develop and debug extensions. See @url{https://pythonextensionpatterns.readthedocs.io/en/latest/debugging/debug.html}, for more information."))) (define* (wrap-python3 python #:optional (name (string-append (package-name python) "-wrapper"))) (package/inherit python (name name) (source #f) (build-system trivial-build-system) (outputs '("out")) (inputs `(("bash" ,bash))) (propagated-inputs `(("python" ,python))) (arguments `(#:modules ((guix build utils)) #:builder (begin (use-modules (guix build utils)) (let ((bin (string-append (assoc-ref %outputs "out") "/bin")) (python (string-append (assoc-ref %build-inputs "python") "/bin/"))) (mkdir-p bin) (for-each (lambda (old new) (symlink (string-append python old) (string-append bin "/" new))) `("python3" ,"pydoc3" ,"idle3" ,"pip3") `("python" ,"pydoc" ,"idle" ,"pip")) ;; python-config outputs search paths based upon its location, ;; use a bash wrapper to avoid changing its outputs. (let ((bash (string-append (assoc-ref %build-inputs "bash") "/bin/bash")) (old (string-append python "python3-config")) (new (string-append bin "/python-config"))) (with-output-to-file new (lambda () (format #t "#!~a~%" bash) (format #t "exec \"~a\" \"$@\"~%" old) (chmod new #o755) #t))))))) (synopsis "Wrapper for the Python 3 commands") (description "This package provides wrappers for the commands of Python@tie{}3.x such that they can be invoked under their usual name---e.g., @command{python} instead of @command{python3}."))) (define-public python-wrapper (wrap-python3 python)) (define-public python-minimal-wrapper (wrap-python3 python-minimal)) (define-public micropython (package (name "micropython") (version "1.11") (source (origin (method url-fetch) (uri (string-append "https://github.com/micropython/micropython/" "releases/download/v" version "/micropython-" version ".tar.gz")) (sha256 (base32 "0px3xhw16rl0l7qifq7jw1gq92wzlnhd17dmszv9m2c3wbzs9p9f")) (modules '((guix build utils))) (snippet '(begin (delete-file-recursively "ports/cc3200/FreeRTOS") (with-directory-excursion "lib" ;; TODO: Unbundle axtls and berkley-db-1.xx (for-each delete-file-recursively '("libffi" "lwip" "stm32lib" "nrfx"))) #t)))) (build-system gnu-build-system) (arguments `(#:phases (modify-phases %standard-phases (add-before 'build 'prepare-build (lambda _ (chdir "ports/unix") ;; see: https://github.com/micropython/micropython/pull/4246 (substitute* "Makefile" (("-Os") "-Os -ffp-contract=off")) #t)) (replace 'install-license-files ;; We don't build in the root directory so the file isn't found. (lambda* (#:key outputs #:allow-other-keys) (let* ((out (assoc-ref outputs "out")) (dest (string-append out "/share/doc/" ,name "-" ,version "/"))) (install-file "../../LICENSE" dest)) #t)) (delete 'configure)) ; no configure #:make-flags (list (string-append "PREFIX=" (assoc-ref %outputs "out")) "V=1") #:test-target "test")) (native-inputs `(("pkg-config" ,pkg-config) ("python" ,python-wrapper))) (inputs `(("libffi" ,libffi))) (home-page "https://micropython.org/") (synopsis "Python implementation for microcontrollers and constrained systems") (description "MicroPython is a lean and efficient implementation of the Python 3 programming language that includes a small subset of the Python standard library and is optimised to run on microcontrollers and in constrained environments. MicroPython is packed full of advanced features such as an interactive prompt, arbitrary precision integers, closures, list comprehension, generators, exception handling and more. Still it is compact enough to fit and run within just 256k of code space and 16k of RAM. MicroPython aims to be as 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)))