| 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 | (define-module (gnu packages python)
|
| 80 | #:use-module ((guix licenses) #:prefix license:)
|
| 81 | #:use-module (gnu packages)
|
| 82 | #:use-module (gnu packages base)
|
| 83 | #:use-module (gnu packages bash)
|
| 84 | #:use-module (gnu packages certs)
|
| 85 | #:use-module (gnu packages check)
|
| 86 | #:use-module (gnu packages compression)
|
| 87 | #:use-module (gnu packages dbm)
|
| 88 | #:use-module (gnu packages hurd)
|
| 89 | #:use-module (gnu packages libffi)
|
| 90 | #:use-module (gnu packages ncurses)
|
| 91 | #:use-module (gnu packages pkg-config)
|
| 92 | #:use-module (gnu packages python-xyz)
|
| 93 | #:use-module (gnu packages readline)
|
| 94 | #:use-module (gnu packages shells)
|
| 95 | #:use-module (gnu packages sqlite)
|
| 96 | #:use-module (gnu packages tcl)
|
| 97 | #:use-module (gnu packages tls)
|
| 98 | #:use-module (gnu packages xml)
|
| 99 | #:use-module (guix packages)
|
| 100 | #:use-module (guix download)
|
| 101 | #:use-module (guix utils)
|
| 102 | #:use-module (guix build-system gnu)
|
| 103 | #:use-module (guix build-system trivial)
|
| 104 | #:use-module (srfi srfi-1)
|
| 105 | #:use-module (srfi srfi-26))
|
| 106 |
|
| 107 | (define-public python-2.7
|
| 108 | (package
|
| 109 | (name "python2")
|
| 110 | (version "2.7.17")
|
| 111 | (source
|
| 112 | (origin
|
| 113 | (method url-fetch)
|
| 114 | (uri (string-append "https://www.python.org/ftp/python/"
|
| 115 | version "/Python-" version ".tar.xz"))
|
| 116 | (sha256
|
| 117 | (base32
|
| 118 | "0hds28cg226m8j8sr394nm9yc4gxhvlv109w0avsf2mxrlrz0hsd"))
|
| 119 | (patches (search-patches "python-2.7-search-paths.patch"
|
| 120 | "python-2-deterministic-build-info.patch"
|
| 121 | "python-2.7-site-prefixes.patch"
|
| 122 | "python-2.7-source-date-epoch.patch"
|
| 123 | "python-2.7-adjust-tests.patch"
|
| 124 | "python-cross-compile.patch"
|
| 125 | "python-2.7-CVE-2021-3177.patch"))
|
| 126 | (modules '((guix build utils)))
|
| 127 | (snippet
|
| 128 | '(begin
|
| 129 | |
| 130 | (for-each delete-file-recursively
|
| 131 | '("Modules/_ctypes/libffi" "Modules/expat" "Modules/zlib"))
|
| 132 |
|
| 133 | (substitute* "Modules/Setup.dist"
|
| 134 | |
| 135 | (("^#pyexpat.*") "pyexpat pyexpat.c -lexpat\n"))
|
| 136 |
|
| 137 | |
| 138 | |
| 139 | |
| 140 | (for-each delete-file
|
| 141 | '("Lib/test/test_compileall.py"
|
| 142 | "Lib/test/test_ctypes.py" |
| 143 | "Lib/test/test_distutils.py"
|
| 144 | "Lib/test/test_import.py"
|
| 145 | "Lib/test/test_shutil.py"
|
| 146 | "Lib/test/test_socket.py"
|
| 147 | "Lib/test/test_subprocess.py"))
|
| 148 | #t))))
|
| 149 | (outputs '("out"
|
| 150 | "tk")) |
| 151 | (build-system gnu-build-system)
|
| 152 | (arguments
|
| 153 | `(#:test-target "test"
|
| 154 | #:configure-flags
|
| 155 | (list "--enable-shared" |
| 156 | "--with-system-expat" |
| 157 | "--with-system-ffi" |
| 158 | "--with-ensurepip=install" |
| 159 | "--enable-unicode=ucs4"
|
| 160 |
|
| 161 | |
| 162 | |
| 163 | "INSTALL=install -c"
|
| 164 | "MKDIR_P=mkdir -p"
|
| 165 |
|
| 166 | |
| 167 | |
| 168 | ,@(if (%current-target-system)
|
| 169 | '("ac_cv_buggy_getaddrinfo=no"
|
| 170 | "ac_cv_file__dev_ptmx=no"
|
| 171 | "ac_cv_file__dev_ptc=no")
|
| 172 | '())
|
| 173 | (string-append "LDFLAGS=-Wl,-rpath="
|
| 174 | (assoc-ref %outputs "out") "/lib"))
|
| 175 | |
| 176 | #:make-flags
|
| 177 | (list (string-append
|
| 178 | (format #f "TESTOPTS=-j~d" (parallel-job-count))
|
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | " --exclude test_urllib2_localnet test_httplib"))
|
| 185 |
|
| 186 | #:modules ((ice-9 ftw) (ice-9 match)
|
| 187 | (guix build utils) (guix build gnu-build-system))
|
| 188 | #:phases
|
| 189 | (modify-phases %standard-phases
|
| 190 | (add-before
|
| 191 | 'configure 'patch-lib-shells
|
| 192 | (lambda _
|
| 193 | |
| 194 | |
| 195 | |
| 196 | ,@(if (%current-target-system)
|
| 197 | '((setenv "_PYTHON_HOST_PLATFORM" ""))
|
| 198 | '())
|
| 199 | |
| 200 | |
| 201 | (substitute* (filter file-exists?
|
| 202 | '("Lib/subprocess.py"
|
| 203 | "Lib/popen2.py"
|
| 204 | "Lib/distutils/tests/test_spawn.py"
|
| 205 | "Lib/test/support/__init__.py"
|
| 206 | "Lib/test/test_subprocess.py"))
|
| 207 | (("/bin/sh") (which "sh")))
|
| 208 | #t))
|
| 209 | ,@(if (hurd-system?)
|
| 210 | `((add-before 'build 'patch-regen-for-hurd
|
| 211 | (lambda* (#:key inputs #:allow-other-keys)
|
| 212 | (let ((libc (assoc-ref inputs "libc")))
|
| 213 | (substitute* "Lib/plat-generic/regen"
|
| 214 | (("/usr/include/") (string-append libc "/include/")))
|
| 215 | #t))))
|
| 216 | '())
|
| 217 | (add-before 'configure 'do-not-record-configure-flags
|
| 218 | (lambda* (#:key configure-flags #:allow-other-keys)
|
| 219 | |
| 220 | |
| 221 | |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | (substitute* "configure"
|
| 227 | (("^CONFIG_ARGS=.*$")
|
| 228 | (format #f "CONFIG_ARGS='~a'\n"
|
| 229 | (if (member "--with-system-ffi" configure-flags)
|
| 230 | "--with-system-ffi"
|
| 231 | ""))))
|
| 232 | #t))
|
| 233 | (add-before
|
| 234 | 'check 'pre-check
|
| 235 | (lambda _
|
| 236 | |
| 237 | (setenv "HOME" (getcwd))
|
| 238 | #t))
|
| 239 | (add-after
|
| 240 | 'unpack 'set-source-file-times-to-1980
|
| 241 | |
| 242 | |
| 243 | |
| 244 | |
| 245 | (lambda _
|
| 246 | (let ((circa-1980 (* 10 366 24 60 60)))
|
| 247 | (ftw "." (lambda (file stat flag)
|
| 248 | (utime file circa-1980 circa-1980)
|
| 249 | #t))
|
| 250 | #t)))
|
| 251 | (add-after 'install 'remove-tests
|
| 252 | |
| 253 | |
| 254 | (lambda* (#:key outputs #:allow-other-keys)
|
| 255 | (let ((out (assoc-ref outputs "out")))
|
| 256 | (match (scandir (string-append out "/lib")
|
| 257 | (lambda (name)
|
| 258 | (string-prefix? "python" name)))
|
| 259 | ((pythonX.Y)
|
| 260 | (let ((testdir (string-append out "/lib/" pythonX.Y
|
| 261 | "/test")))
|
| 262 | (with-directory-excursion testdir
|
| 263 | (for-each delete-file-recursively
|
| 264 | (scandir testdir
|
| 265 | (match-lambda
|
| 266 | ((or "." "..") #f)
|
| 267 | ("support" #f)
|
| 268 | (file
|
| 269 | (not
|
| 270 | (string-prefix? "test_support."
|
| 271 | file))))))
|
| 272 | (call-with-output-file "__init__.py" (const #t))
|
| 273 | #t)))))))
|
| 274 | (add-after 'remove-tests 'rebuild-bytecode
|
| 275 | (lambda* (#:key outputs #:allow-other-keys)
|
| 276 | (let ((out (assoc-ref outputs "out")))
|
| 277 | |
| 278 | |
| 279 | (setenv "PYTHONHASHSEED" "0")
|
| 280 | (for-each
|
| 281 | (lambda (opt)
|
| 282 | (format #t "Compiling with optimization level: ~a\n"
|
| 283 | (if (null? opt) "none" (car opt)))
|
| 284 | (for-each (lambda (file)
|
| 285 | (apply invoke
|
| 286 | `(,,(if (%current-target-system)
|
| 287 | "python2"
|
| 288 | '(string-append out "/bin/python"))
|
| 289 | ,@opt
|
| 290 | "-m" "compileall"
|
| 291 | "-f" |
| 292 | |
| 293 | "-x" "lib2to3/.*"
|
| 294 | ,file)))
|
| 295 | (find-files out "\\.py$")))
|
| 296 | (list '() '("-O") '("-OO")))
|
| 297 | #t)))
|
| 298 | (add-after 'install 'move-tk-inter
|
| 299 | (lambda* (#:key outputs #:allow-other-keys)
|
| 300 | |
| 301 | |
| 302 | (let ((out (assoc-ref outputs "out"))
|
| 303 | (tk (assoc-ref outputs "tk")))
|
| 304 | (when tk
|
| 305 | (match (find-files out "tkinter.*\\.so")
|
| 306 | ((tkinter.so)
|
| 307 | |
| 308 | |
| 309 | (let* ((len (string-length out))
|
| 310 | (target (string-append
|
| 311 | tk "/"
|
| 312 | (string-drop
|
| 313 | (dirname (dirname tkinter.so))
|
| 314 | len)
|
| 315 | "/site-packages")))
|
| 316 | (install-file tkinter.so target)
|
| 317 | (delete-file tkinter.so)))))
|
| 318 | #t))))))
|
| 319 | (inputs
|
| 320 | `(("bzip2" ,bzip2)
|
| 321 | ("expat" ,expat)
|
| 322 | ("gdbm" ,gdbm)
|
| 323 | ("libffi" ,libffi) |
| 324 | ("sqlite" ,sqlite) |
| 325 | ("openssl" ,openssl)
|
| 326 | ("readline" ,readline)
|
| 327 | ("zlib" ,zlib)
|
| 328 | ("tcl" ,tcl)
|
| 329 | ("tk" ,tk))) |
| 330 | (native-inputs
|
| 331 | `(("pkg-config" ,pkg-config)
|
| 332 | |
| 333 | ,@(if (%current-target-system)
|
| 334 | `(("python2" ,this-package)
|
| 335 | ("which" ,which))
|
| 336 | '())))
|
| 337 | (native-search-paths
|
| 338 | (list (search-path-specification
|
| 339 | (variable "PYTHONPATH")
|
| 340 | (files '("lib/python2.7/site-packages")))))
|
| 341 | (home-page "https://www.python.org")
|
| 342 | (synopsis "High-level, dynamically-typed programming language")
|
| 343 | (description
|
| 344 | "Python is a remarkably powerful dynamic programming language that
|
| 345 | is used in a wide variety of application domains. Some of its key
|
| 346 | distinguishing features include: clear, readable syntax; strong
|
| 347 | introspection capabilities; intuitive object orientation; natural
|
| 348 | expression of procedural code; full modularity, supporting hierarchical
|
| 349 | packages; exception-based error handling; and very high level dynamic
|
| 350 | data types.")
|
| 351 | (properties '((cpe-name . "python")))
|
| 352 | (license license:psfl)))
|
| 353 |
|
| 354 | |
| 355 | (define-public python-2 python-2.7)
|
| 356 |
|
| 357 | (define-public python2-called-python
|
| 358 | |
| 359 | |
| 360 | |
| 361 | (package/inherit python-2
|
| 362 | (name "python")
|
| 363 | (properties `((superseded . ,python-2)))))
|
| 364 |
|
| 365 | (define-public python-3.8
|
| 366 | (package (inherit python-2)
|
| 367 | (name "python")
|
| 368 | (version "3.8.2")
|
| 369 | (source (origin
|
| 370 | (method url-fetch)
|
| 371 | (uri (string-append "https://www.python.org/ftp/python/"
|
| 372 | version "/Python-" version ".tar.xz"))
|
| 373 | (patches (search-patches
|
| 374 | "python-CVE-2020-26116.patch"
|
| 375 | "python-3.8-CVE-2021-3177.patch"
|
| 376 | "python-3-fix-tests.patch"
|
| 377 | "python-3.8-fix-tests.patch"
|
| 378 | "python-3-deterministic-build-info.patch"
|
| 379 | "python-3-search-paths.patch"))
|
| 380 | (sha256
|
| 381 | (base32
|
| 382 | "1ps5v323cp5czfshqjmbsqw7nvrdpcbk06f62jbzaqik4gfffii6"))
|
| 383 | (modules '((guix build utils)))
|
| 384 | (snippet
|
| 385 | '(begin
|
| 386 | |
| 387 | (delete-file-recursively "Modules/expat")
|
| 388 | (substitute* "Modules/Setup"
|
| 389 | |
| 390 | (("^#pyexpat.*") "pyexpat pyexpat.c -lexpat\n"))
|
| 391 | #t))))
|
| 392 | (arguments
|
| 393 | (substitute-keyword-arguments (package-arguments python-2)
|
| 394 | ((#:make-flags _)
|
| 395 | `(list (string-append
|
| 396 | (format #f "TESTOPTS=-j~d" (parallel-job-count))
|
| 397 | |
| 398 | " --exclude test_mmap"
|
| 399 | |
| 400 | |
| 401 | " test_socket"
|
| 402 | ,@(if (hurd-target?)
|
| 403 | '(" test_posix" |
| 404 | " test_time"
|
| 405 | " test_pty"
|
| 406 | " test_shutil"
|
| 407 | " test_tempfile" |
| 408 | |
| 409 | " test_asyncio" |
| 410 | " test_os" |
| 411 | |
| 412 | " test_openpty" |
| 413 | " test_selectors" |
| 414 | |
| 415 | " test_compileall" |
| 416 | " test_poll" |
| 417 | " test_subprocess" |
| 418 | " test_asyncore" |
| 419 | " test_threadsignals"
|
| 420 | " test_eintr" |
| 421 | " test_io" |
| 422 | " test_logging"
|
| 423 | " test_signal"
|
| 424 | " test_threading" |
| 425 | " test_flags" |
| 426 | " test_bidirectional_pty"
|
| 427 | " test_create_unix_connection"
|
| 428 | " test_unix_sock_client_ops"
|
| 429 | " test_open_unix_connection"
|
| 430 | " test_open_unix_connection_error"
|
| 431 | " test_read_pty_output"
|
| 432 | " test_write_pty")
|
| 433 | '()))))
|
| 434 | ((#:phases phases)
|
| 435 | `(modify-phases ,phases
|
| 436 | ,@(if (hurd-system?)
|
| 437 | `((delete 'patch-regen-for-hurd)) |
| 438 | '())
|
| 439 | ,@(if (hurd-target?)
|
| 440 | |
| 441 | |
| 442 | |
| 443 | '((add-before 'configure 'support-hurd-cross-compile
|
| 444 | (lambda _
|
| 445 | (substitute* "configure"
|
| 446 | (("\\*-\\*-vxworks.*" all)
|
| 447 | (string-append "*-*-gnu)\nac_sys_system=GNU\n;;\n" all)))
|
| 448 | #t)))
|
| 449 | '())
|
| 450 | (add-before 'check 'set-TZDIR
|
| 451 | (lambda* (#:key inputs native-inputs #:allow-other-keys)
|
| 452 | |
| 453 | (setenv "TZDIR"
|
| 454 | (string-append (assoc-ref
|
| 455 | (or native-inputs inputs) "tzdata")
|
| 456 | "/share/zoneinfo"))
|
| 457 | #t))
|
| 458 | |
| 459 | |
| 460 | (add-before 'check 'unset-SOURCE_DATE_EPOCH
|
| 461 | (lambda _ (unsetenv "SOURCE_DATE_EPOCH") #t))
|
| 462 | (add-after 'check 'reset-SOURCE_DATE_EPOCH
|
| 463 | (lambda _ (setenv "SOURCE_DATE_EPOCH" "1") #t))
|
| 464 | (replace 'rebuild-bytecode
|
| 465 | (lambda* (#:key outputs #:allow-other-keys)
|
| 466 | (let ((out (assoc-ref outputs "out")))
|
| 467 | |
| 468 | |
| 469 | (setenv "PYTHONHASHSEED" "0")
|
| 470 | (for-each
|
| 471 | (lambda (opt)
|
| 472 | (format #t "Compiling with optimization level: ~a\n"
|
| 473 | (if (null? opt) "none" (car opt)))
|
| 474 | (for-each (lambda (file)
|
| 475 | (apply invoke
|
| 476 | `(,,(if (%current-target-system)
|
| 477 | "python3"
|
| 478 | '(string-append out
|
| 479 | "/bin/python3"))
|
| 480 | ,@opt
|
| 481 | "-m" "compileall"
|
| 482 | "-f" |
| 483 | |
| 484 | "-x" "lib2to3/.*"
|
| 485 | ,file)))
|
| 486 | (find-files out "\\.py$")))
|
| 487 | (list '() '("-O") '("-OO")))
|
| 488 | #t)))
|
| 489 | |
| 490 | |
| 491 | ,@(let ((system (or (%current-target-system)
|
| 492 | (%current-system))))
|
| 493 | (if (any (cute string-prefix? <> system)
|
| 494 | '("arm" "aarch64"))
|
| 495 | '((add-after 'unpack 'apply-alignment-patch
|
| 496 | (lambda* (#:key native-inputs inputs #:allow-other-keys)
|
| 497 | (invoke "patch" "-p1" "--force" "--input"
|
| 498 | (assoc-ref (or native-inputs inputs)
|
| 499 | "arm-alignment.patch")))))
|
| 500 | '()))))))
|
| 501 | (native-inputs
|
| 502 | `(("tzdata" ,tzdata-for-tests)
|
| 503 |
|
| 504 | |
| 505 | |
| 506 | |
| 507 | |
| 508 | ,@(let ((system (or (%current-target-system)
|
| 509 | (%current-system))))
|
| 510 | (if (any (cute string-prefix? <> system)
|
| 511 | '("arm" "aarch64"))
|
| 512 | `(("arm-alignment.patch" ,(search-patch "python-3-arm-alignment.patch")))
|
| 513 | '()))
|
| 514 |
|
| 515 | ,@(if (%current-target-system)
|
| 516 | `(("python3" ,this-package))
|
| 517 | '())
|
| 518 | ,@(package-native-inputs python-2)))
|
| 519 | (native-search-paths
|
| 520 | (list (search-path-specification
|
| 521 | (variable "PYTHONPATH")
|
| 522 | (files (list (string-append "lib/python"
|
| 523 | (version-major+minor version)
|
| 524 | "/site-packages"))))))))
|
| 525 |
|
| 526 | (define-public python-3.9
|
| 527 | (package (inherit python-3.8)
|
| 528 | (name "python-next")
|
| 529 | (version "3.9.2")
|
| 530 | (source (origin
|
| 531 | (method url-fetch)
|
| 532 | (uri (string-append "https://www.python.org/ftp/python/"
|
| 533 | version "/Python-" version ".tar.xz"))
|
| 534 | (patches (search-patches
|
| 535 | "python-3.9-fix-tests.patch"
|
| 536 | "python-3-deterministic-build-info.patch"
|
| 537 | "python-3-search-paths.patch"))
|
| 538 | (sha256
|
| 539 | (base32
|
| 540 | "0z94vv5qhlwvcgc4sy9sdiqs0220s84wx3b62vslh5419z2k881w"))
|
| 541 | (modules '((guix build utils)))
|
| 542 | (snippet
|
| 543 | '(begin
|
| 544 | |
| 545 | (delete-file-recursively "Modules/expat")
|
| 546 | (substitute* "Modules/Setup"
|
| 547 | |
| 548 | (("^#pyexpat.*") "pyexpat pyexpat.c -lexpat\n"))
|
| 549 | #t))))))
|
| 550 |
|
| 551 | |
| 552 | (define-public python-3 python-3.8)
|
| 553 |
|
| 554 | |
| 555 | (define-public python python-3)
|
| 556 |
|
| 557 | |
| 558 | |
| 559 |
|
| 560 | (define-public python2-minimal
|
| 561 | (package/inherit python-2
|
| 562 | (name "python2-minimal")
|
| 563 | (outputs '("out"))
|
| 564 |
|
| 565 | |
| 566 | |
| 567 | |
| 568 | |
| 569 | (inputs `(("expat" ,expat)
|
| 570 | ("libffi" ,libffi)
|
| 571 | ("zlib" ,zlib)))))
|
| 572 |
|
| 573 | (define-public python-minimal
|
| 574 | (package/inherit python
|
| 575 | (name "python-minimal")
|
| 576 | (outputs '("out"))
|
| 577 |
|
| 578 | |
| 579 | |
| 580 | |
| 581 | |
| 582 | (inputs `(("expat" ,expat)
|
| 583 | ("libffi" ,libffi)
|
| 584 | ("openssl" ,openssl)
|
| 585 | ("zlib" ,zlib)))))
|
| 586 |
|
| 587 | (define-public python-debug
|
| 588 | (package/inherit python
|
| 589 | (name "python-debug")
|
| 590 | (outputs '("out" "debug"))
|
| 591 | (build-system gnu-build-system)
|
| 592 | (arguments
|
| 593 | (substitute-keyword-arguments (package-arguments python)
|
| 594 | ((#:configure-flags flags '())
|
| 595 | `(cons "--with-pydebug" ,flags))))
|
| 596 | (synopsis
|
| 597 | "High-level, dynamically-typed programming language (for debugging)")
|
| 598 | (description
|
| 599 | "This variant of Python provides an interpreter built with
|
| 600 | @code{--with-pydebug} to help develop and debug extensions. See
|
| 601 | @url{https://pythonextensionpatterns.readthedocs.io/en/latest/debugging/debug.html},
|
| 602 | for more information.")))
|
| 603 |
|
| 604 | (define* (wrap-python3 python
|
| 605 | #:optional
|
| 606 | (name (string-append (package-name python) "-wrapper")))
|
| 607 | (package/inherit python
|
| 608 | (name name)
|
| 609 | (source #f)
|
| 610 | (build-system trivial-build-system)
|
| 611 | (outputs '("out"))
|
| 612 | (inputs `(("bash" ,bash)))
|
| 613 | (propagated-inputs `(("python" ,python)))
|
| 614 | (arguments
|
| 615 | `(#:modules ((guix build utils))
|
| 616 | #:builder
|
| 617 | (begin
|
| 618 | (use-modules (guix build utils))
|
| 619 | (let ((bin (string-append (assoc-ref %outputs "out") "/bin"))
|
| 620 | (python (string-append (assoc-ref %build-inputs "python") "/bin/")))
|
| 621 | (mkdir-p bin)
|
| 622 | (for-each
|
| 623 | (lambda (old new)
|
| 624 | (symlink (string-append python old)
|
| 625 | (string-append bin "/" new)))
|
| 626 | `("python3" ,"pydoc3" ,"idle3" ,"pip3")
|
| 627 | `("python" ,"pydoc" ,"idle" ,"pip"))
|
| 628 | |
| 629 | |
| 630 | (let ((bash (string-append (assoc-ref %build-inputs "bash")
|
| 631 | "/bin/bash"))
|
| 632 | (old (string-append python "python3-config"))
|
| 633 | (new (string-append bin "/python-config")))
|
| 634 | (with-output-to-file new
|
| 635 | (lambda ()
|
| 636 | (format #t "#!~a~%" bash)
|
| 637 | (format #t "exec \"~a\" \"$@\"~%" old)
|
| 638 | (chmod new #o755)
|
| 639 | #t)))))))
|
| 640 | (synopsis "Wrapper for the Python 3 commands")
|
| 641 | (description
|
| 642 | "This package provides wrappers for the commands of Python@tie{}3.x such
|
| 643 | that they can be invoked under their usual name---e.g., @command{python}
|
| 644 | instead of @command{python3} or @command{pip} instead of @command{pip3}.
|
| 645 | To function properly, this package should not be installed together with the
|
| 646 | @command{python} package.")))
|
| 647 |
|
| 648 | (define-public python-wrapper (wrap-python3 python))
|
| 649 | (define-public python-minimal-wrapper (wrap-python3 python-minimal))
|
| 650 |
|
| 651 | (define-public micropython
|
| 652 | (package
|
| 653 | (name "micropython")
|
| 654 | (version "1.14")
|
| 655 | (source
|
| 656 | (origin
|
| 657 | (method url-fetch)
|
| 658 | (uri (string-append "https://github.com/micropython/micropython/"
|
| 659 | "releases/download/v" version
|
| 660 | "/micropython-" version ".tar.xz"))
|
| 661 | (sha256
|
| 662 | (base32 "0k6ri3rxxnnmvcbi7z7x59r21f4vj9dcf9j64jhj1cgazmb62c4p"))
|
| 663 | (modules '((guix build utils)))
|
| 664 | (snippet
|
| 665 | '(begin
|
| 666 | (delete-file-recursively "ports/cc3200/FreeRTOS")
|
| 667 | (with-directory-excursion "lib"
|
| 668 | |
| 669 | (for-each delete-file-recursively
|
| 670 | '("libffi" "lwip" "stm32lib" "nrfx")))
|
| 671 | #t))))
|
| 672 | (build-system gnu-build-system)
|
| 673 | (arguments
|
| 674 | `(#:phases
|
| 675 | (modify-phases %standard-phases
|
| 676 | (add-before 'build 'build-mpy-cross
|
| 677 | (lambda* (#:key make-flags #:allow-other-keys)
|
| 678 | (with-directory-excursion "mpy-cross"
|
| 679 | (apply invoke "make" make-flags))))
|
| 680 | (add-after 'build-mpy-cross 'prepare-build
|
| 681 | (lambda _
|
| 682 | (chdir "ports/unix")
|
| 683 | |
| 684 | (substitute* "Makefile"
|
| 685 | (("-Os") "-Os -ffp-contract=off"))
|
| 686 | #t))
|
| 687 | (replace 'install-license-files
|
| 688 | |
| 689 | (lambda* (#:key outputs #:allow-other-keys)
|
| 690 | (let* ((out (assoc-ref outputs "out"))
|
| 691 | (dest (string-append out "/share/doc/" ,name "-" ,version "/")))
|
| 692 | (install-file "../../LICENSE" dest))
|
| 693 | #t))
|
| 694 | (delete 'configure)) |
| 695 | #:make-flags (list (string-append "PREFIX=" (assoc-ref %outputs "out"))
|
| 696 | "V=1")
|
| 697 | #:test-target "test"))
|
| 698 | (native-inputs
|
| 699 | `(("pkg-config" ,pkg-config)
|
| 700 | ("python" ,python-wrapper)))
|
| 701 | (inputs
|
| 702 | `(("libffi" ,libffi)))
|
| 703 | (home-page "https://micropython.org/")
|
| 704 | (synopsis "Python implementation for microcontrollers and constrained systems")
|
| 705 | (description "MicroPython is a lean and efficient implementation of the
|
| 706 | Python 3 programming language that includes a small subset of the Python
|
| 707 | standard library and is optimised to run on microcontrollers and in constrained
|
| 708 | environments. MicroPython is packed full of advanced features such as an
|
| 709 | interactive prompt, arbitrary precision integers, closures, list comprehension,
|
| 710 | generators, exception handling and more. Still it is compact enough to fit and
|
| 711 | run within just 256k of code space and 16k of RAM. MicroPython aims to be as
|
| 712 | compatible with normal Python as possible to allow you to transfer code with
|
| 713 | ease from the desktop to a microcontroller or embedded system.")
|
| 714 | (license license:expat)))
|
| 715 |
|
| 716 | (define-public pypy3
|
| 717 | (package
|
| 718 | (name "pypy3")
|
| 719 | (version "7.3.1")
|
| 720 | (source (origin
|
| 721 | (method url-fetch)
|
| 722 | (uri (string-append "https://bitbucket.org/pypy/pypy/downloads/" |
| 723 | "pypy3.6-v" version "-src.tar.bz2"))
|
| 724 | (sha256
|
| 725 | (base32
|
| 726 | "10zsk8jby8j6visk5mzikpb1cidvz27qq4pfpa26jv53klic6b0c"))
|
| 727 | (patches (search-patches "pypy3-7.3.1-fix-tests.patch"))))
|
| 728 | (build-system gnu-build-system)
|
| 729 | (native-inputs
|
| 730 | `(("python-2" ,python-2)
|
| 731 | ("pkg-config" ,pkg-config)
|
| 732 | ("tar" ,tar) |
| 733 | ("python2-pycparser" ,python2-pycparser)
|
| 734 | ("python2-hypothesis" ,python2-hypothesis)
|
| 735 | ("nss-certs" ,nss-certs) |
| 736 | ("gzip" ,gzip)))
|
| 737 | (inputs
|
| 738 | `(("libffi" ,libffi)
|
| 739 | ("zlib" ,zlib)
|
| 740 | ("ncurses" ,ncurses)
|
| 741 | ("openssl" ,openssl)
|
| 742 | ("expat" ,expat)
|
| 743 | ("bzip2" ,bzip2)
|
| 744 | ("sqlite" ,sqlite)
|
| 745 | ("gdbm" ,gdbm)
|
| 746 | ("tcl" ,tcl)
|
| 747 | ("tk" ,tk)
|
| 748 | ("glibc" ,glibc)
|
| 749 | ("bash-minimal" ,bash-minimal) |
| 750 | ("xz" ,xz))) |
| 751 | (arguments
|
| 752 | `(#:tests? #f |
| 753 | #:modules ((ice-9 ftw) (ice-9 match)
|
| 754 | (guix build utils) (guix build gnu-build-system))
|
| 755 | #:phases (modify-phases %standard-phases
|
| 756 | (delete 'configure)
|
| 757 | (add-after 'unpack 'patch-source
|
| 758 | (lambda* (#:key inputs outputs #:allow-other-keys)
|
| 759 | (substitute* '("rpython/rlib/clibffi.py")
|
| 760 | |
| 761 | (("ctypes\\.util\\.find_library\\('c'\\)") "'libc.so'"))
|
| 762 | (substitute* '("lib_pypy/cffi/_pycparser/ply/cpp.py")
|
| 763 | |
| 764 | (("time\\.localtime\\(\\)") "time.gmtime(0)"))
|
| 765 | (substitute* '("pypy/module/sys/version.py")
|
| 766 | |
| 767 | (("t\\.gmtime\\(\\)") "t.gmtime(0)"))
|
| 768 | (substitute* '("lib_pypy/_tkinter/tklib_build.py")
|
| 769 | |
| 770 | (("linklibs = \\['tcl', 'tk'\\]")
|
| 771 | "linklibs = ['tcl8.6', 'tk8.6']")
|
| 772 | (("incdirs = \\[\\]")
|
| 773 | (string-append "incdirs = ['"
|
| 774 | (assoc-ref inputs "tcl")
|
| 775 | "/include', '"
|
| 776 | (assoc-ref inputs "tk")
|
| 777 | "/include']")))
|
| 778 | (substitute* '("lib_pypy/_curses_build.py")
|
| 779 | |
| 780 | (("/usr/local") (assoc-ref inputs "ncurses")))
|
| 781 | (substitute* '("lib_pypy/_sqlite3_build.py")
|
| 782 | |
| 783 | (("sys\\.platform\\.startswith\\('freebsd'\\)") "True")
|
| 784 | |
| 785 | (("/usr/local") (assoc-ref inputs "sqlite"))
|
| 786 | (("libname = 'sqlite3'")
|
| 787 | (string-append "libname = '"
|
| 788 | (assoc-ref inputs "sqlite")
|
| 789 | "/lib/libsqlite3.so.0'")))
|
| 790 | (substitute* '("lib-python/3/subprocess.py")
|
| 791 | |
| 792 | (("/bin/sh")
|
| 793 | (string-append (assoc-ref inputs "bash-minimal") "/bin/sh")))
|
| 794 | (substitute* '("lib-python/3/distutils/unixccompiler.py")
|
| 795 | |
| 796 | (("\"cc\"") "\"gcc\""))
|
| 797 | #t))
|
| 798 | (add-after
|
| 799 | 'unpack 'set-source-file-times-to-1980
|
| 800 | |
| 801 | (lambda _
|
| 802 | (let ((circa-1980 (* 10 366 24 60 60)))
|
| 803 | (ftw "." (lambda (file stat flag)
|
| 804 | (utime file circa-1980 circa-1980)
|
| 805 | #t))
|
| 806 | #t)))
|
| 807 | (replace 'build
|
| 808 | (lambda* (#:key inputs #:allow-other-keys)
|
| 809 | (with-directory-excursion "pypy/goal"
|
| 810 | |
| 811 | (invoke "python2"
|
| 812 | "../../rpython/bin/rpython"
|
| 813 | (string-append "--make-jobs="
|
| 814 | (number->string (parallel-job-count)))
|
| 815 | "-Ojit"
|
| 816 | "targetpypystandalone"))
|
| 817 | |
| 818 | (with-directory-excursion "pypy/tool/release"
|
| 819 | (unsetenv "PYTHONPATH") |
| 820 | |
| 821 | |
| 822 | (invoke "python2" "package.py"
|
| 823 | "--archive-name" "pypy-dist"
|
| 824 | "--builddir" (getcwd)))))
|
| 825 | (replace 'check
|
| 826 | (lambda* (#:key tests? #:allow-other-keys)
|
| 827 | (if tests?
|
| 828 | (begin
|
| 829 | (setenv "HOME" "/tmp") |
| 830 | |
| 831 | |
| 832 | |
| 833 | (invoke
|
| 834 | "python2"
|
| 835 | "pypy/test_all.py"
|
| 836 | "--pypy=pypy/tool/release/pypy-dist/bin/pypy3"
|
| 837 | "lib-python"))
|
| 838 | (format #t "test suite not run~%"))
|
| 839 | #t))
|
| 840 | (replace 'install
|
| 841 | (lambda* (#:key inputs outputs #:allow-other-keys)
|
| 842 | (with-directory-excursion "pypy/tool/release"
|
| 843 | |
| 844 | (for-each
|
| 845 | (lambda (x)
|
| 846 | (delete-file-recursively (string-append
|
| 847 | "pypy-dist/lib-python/3/" x)))
|
| 848 | '("tkinter/test"
|
| 849 | "test"
|
| 850 | "sqlite3/test"
|
| 851 | "lib2to3/tests"
|
| 852 | "idlelib/idle_test"
|
| 853 | "distutils/tests"
|
| 854 | "ctypes/test"
|
| 855 | "unittest/test"))
|
| 856 | |
| 857 | (substitute* '("pypy-dist/lib-python/3/cgi.py"
|
| 858 | "pypy-dist/lib-python/3/encodings/rot_13.py")
|
| 859 | (("#!.+/bin/python")
|
| 860 | (string-append "#!" (assoc-ref outputs "out") "/bin/pypy3")))
|
| 861 | (with-fluids ((%default-port-encoding "ISO-8859-1"))
|
| 862 | (substitute* '("pypy-dist/lib_pypy/_md5.py"
|
| 863 | "pypy-dist/lib_pypy/_sha1.py")
|
| 864 | (("#!.+/bin/python")
|
| 865 | (string-append "#!" (assoc-ref outputs "out") "/bin/pypy3"))))
|
| 866 | (copy-recursively "pypy-dist" (assoc-ref outputs "out")))
|
| 867 | #t)))))
|
| 868 | (home-page "https://www.pypy.org/")
|
| 869 | (synopsis "Python implementation with just-in-time compilation")
|
| 870 | (description "PyPy is a faster, alternative implementation of the Python
|
| 871 | programming language employing a just-in-time compiler. It supports most
|
| 872 | Python code natively, including C extensions.")
|
| 873 | (license (list license:expat |
| 874 | license:psfl |
| 875 | license:asl2.0 |
| 876 | license:gpl3+ |
| 877 | license:bsd-3 |
| 878 | (license:non-copyleft
|
| 879 | "http://www.unicode.org/copyright.html")))))
|
| 880 |
|