| 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 | (define-module (gnu packages python)
|
| 78 | #:use-module ((guix licenses) #:prefix license:)
|
| 79 | #:use-module (gnu packages)
|
| 80 | #:use-module (gnu packages base)
|
| 81 | #:use-module (gnu packages bash)
|
| 82 | #:use-module (gnu packages compression)
|
| 83 | #:use-module (gnu packages dbm)
|
| 84 | #:use-module (gnu packages libffi)
|
| 85 | #:use-module (gnu packages pkg-config)
|
| 86 | #:use-module (gnu packages readline)
|
| 87 | #:use-module (gnu packages sqlite)
|
| 88 | #:use-module (gnu packages tcl)
|
| 89 | #:use-module (gnu packages tls)
|
| 90 | #:use-module (gnu packages xml)
|
| 91 | #:use-module (guix packages)
|
| 92 | #:use-module (guix download)
|
| 93 | #:use-module (guix utils)
|
| 94 | #:use-module (guix build-system gnu)
|
| 95 | #:use-module (guix build-system trivial))
|
| 96 |
|
| 97 | (define-public python-2.7
|
| 98 | (package
|
| 99 | (name "python2")
|
| 100 | (version "2.7.16")
|
| 101 | (source
|
| 102 | (origin
|
| 103 | (method url-fetch)
|
| 104 | (uri (string-append "https://www.python.org/ftp/python/"
|
| 105 | version "/Python-" version ".tar.xz"))
|
| 106 | (sha256
|
| 107 | (base32
|
| 108 | "1mqfcqp5y8r0bfyr7ppl74n0lig45p9mc4b8adlcpvj74rhfy8pj"))
|
| 109 | (patches (search-patches "python-2.7-search-paths.patch"
|
| 110 | "python-2-deterministic-build-info.patch"
|
| 111 | "python-2.7-site-prefixes.patch"
|
| 112 | "python-2.7-source-date-epoch.patch"
|
| 113 | "python-2.7-adjust-tests.patch"))
|
| 114 | (modules '((guix build utils)))
|
| 115 | (snippet
|
| 116 | '(begin
|
| 117 | |
| 118 | (for-each delete-file-recursively
|
| 119 | '("Modules/_ctypes/libffi" "Modules/expat" "Modules/zlib"))
|
| 120 |
|
| 121 | (substitute* "Modules/Setup.dist"
|
| 122 | |
| 123 | (("^#pyexpat.*") "pyexpat pyexpat.c -lexpat\n"))
|
| 124 |
|
| 125 | |
| 126 | |
| 127 | |
| 128 | (for-each delete-file
|
| 129 | '("Lib/test/test_compileall.py"
|
| 130 | "Lib/test/test_ctypes.py" |
| 131 | "Lib/test/test_distutils.py"
|
| 132 | "Lib/test/test_import.py"
|
| 133 | "Lib/test/test_shutil.py"
|
| 134 | "Lib/test/test_socket.py"
|
| 135 | "Lib/test/test_subprocess.py"))
|
| 136 | #t))))
|
| 137 | (outputs '("out"
|
| 138 | "tk")) |
| 139 | (build-system gnu-build-system)
|
| 140 | (arguments
|
| 141 | `(#:test-target "test"
|
| 142 | #:configure-flags
|
| 143 | (list "--enable-shared" |
| 144 | "--with-system-expat" |
| 145 | "--with-system-ffi" |
| 146 | "--with-ensurepip=install" |
| 147 | "--enable-unicode=ucs4"
|
| 148 |
|
| 149 | |
| 150 | |
| 151 | "INSTALL=install -c"
|
| 152 | "MKDIR_P=mkdir -p"
|
| 153 |
|
| 154 | (string-append "LDFLAGS=-Wl,-rpath="
|
| 155 | (assoc-ref %outputs "out") "/lib"))
|
| 156 | |
| 157 | #:make-flags
|
| 158 | (list (string-append
|
| 159 | (format #f "TESTOPTS=-j~d" (parallel-job-count))
|
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | " --exclude test_urllib2_localnet test_httplib"))
|
| 166 |
|
| 167 | #:modules ((ice-9 ftw) (ice-9 match)
|
| 168 | (guix build utils) (guix build gnu-build-system))
|
| 169 | #:phases
|
| 170 | (modify-phases %standard-phases
|
| 171 | (add-before
|
| 172 | 'configure 'patch-lib-shells
|
| 173 | (lambda _
|
| 174 | |
| 175 | |
| 176 | (substitute* (filter file-exists?
|
| 177 | '("Lib/subprocess.py"
|
| 178 | "Lib/popen2.py"
|
| 179 | "Lib/distutils/tests/test_spawn.py"
|
| 180 | "Lib/test/support/__init__.py"
|
| 181 | "Lib/test/test_subprocess.py"))
|
| 182 | (("/bin/sh") (which "sh")))
|
| 183 | #t))
|
| 184 | (add-before 'configure 'do-not-record-configure-flags
|
| 185 | (lambda* (#:key configure-flags #:allow-other-keys)
|
| 186 | |
| 187 | |
| 188 | |
| 189 | |
| 190 | |
| 191 | |
| 192 | |
| 193 | (substitute* "configure"
|
| 194 | (("^CONFIG_ARGS=.*$")
|
| 195 | (format #f "CONFIG_ARGS='~a'\n"
|
| 196 | (if (member "--with-system-ffi" configure-flags)
|
| 197 | "--with-system-ffi"
|
| 198 | ""))))
|
| 199 | #t))
|
| 200 | (add-before
|
| 201 | 'check 'pre-check
|
| 202 | (lambda _
|
| 203 | |
| 204 | (setenv "HOME" (getcwd))
|
| 205 | #t))
|
| 206 | (add-after
|
| 207 | 'unpack 'set-source-file-times-to-1980
|
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | (lambda _
|
| 213 | (let ((circa-1980 (* 10 366 24 60 60)))
|
| 214 | (ftw "." (lambda (file stat flag)
|
| 215 | (utime file circa-1980 circa-1980)
|
| 216 | #t))
|
| 217 | #t)))
|
| 218 | (add-after 'install 'remove-tests
|
| 219 | |
| 220 | |
| 221 | (lambda* (#:key outputs #:allow-other-keys)
|
| 222 | (let ((out (assoc-ref outputs "out")))
|
| 223 | (match (scandir (string-append out "/lib")
|
| 224 | (lambda (name)
|
| 225 | (string-prefix? "python" name)))
|
| 226 | ((pythonX.Y)
|
| 227 | (let ((testdir (string-append out "/lib/" pythonX.Y
|
| 228 | "/test")))
|
| 229 | (with-directory-excursion testdir
|
| 230 | (for-each delete-file-recursively
|
| 231 | (scandir testdir
|
| 232 | (match-lambda
|
| 233 | ((or "." "..") #f)
|
| 234 | ("support" #f)
|
| 235 | (file
|
| 236 | (not
|
| 237 | (string-prefix? "test_support."
|
| 238 | file))))))
|
| 239 | (call-with-output-file "__init__.py" (const #t))
|
| 240 | #t)))))))
|
| 241 | (add-after 'remove-tests 'rebuild-bytecode
|
| 242 | (lambda* (#:key outputs #:allow-other-keys)
|
| 243 | (let ((out (assoc-ref outputs "out")))
|
| 244 | |
| 245 | |
| 246 | (setenv "PYTHONHASHSEED" "0")
|
| 247 | (for-each
|
| 248 | (lambda (opt)
|
| 249 | (format #t "Compiling with optimization level: ~a\n"
|
| 250 | (if (null? opt) "none" (car opt)))
|
| 251 | (for-each (lambda (file)
|
| 252 | (apply invoke
|
| 253 | `(,(string-append out "/bin/python")
|
| 254 | ,@opt
|
| 255 | "-m" "compileall"
|
| 256 | "-f" |
| 257 | |
| 258 | "-x" "lib2to3/.*"
|
| 259 | ,file)))
|
| 260 | (find-files out "\\.py$")))
|
| 261 | (list '() '("-O") '("-OO")))
|
| 262 | #t)))
|
| 263 | (add-after 'install 'move-tk-inter
|
| 264 | (lambda* (#:key outputs #:allow-other-keys)
|
| 265 | |
| 266 | |
| 267 | (let ((out (assoc-ref outputs "out"))
|
| 268 | (tk (assoc-ref outputs "tk")))
|
| 269 | (when tk
|
| 270 | (match (find-files out "tkinter.*\\.so")
|
| 271 | ((tkinter.so)
|
| 272 | |
| 273 | |
| 274 | (let* ((len (string-length out))
|
| 275 | (target (string-append
|
| 276 | tk "/"
|
| 277 | (string-drop
|
| 278 | (dirname (dirname tkinter.so))
|
| 279 | len)
|
| 280 | "/site-packages")))
|
| 281 | (install-file tkinter.so target)
|
| 282 | (delete-file tkinter.so)))))
|
| 283 | #t))))))
|
| 284 | (inputs
|
| 285 | `(("bzip2" ,bzip2)
|
| 286 | ("expat" ,expat)
|
| 287 | ("gdbm" ,gdbm)
|
| 288 | ("libffi" ,libffi) |
| 289 | ("sqlite" ,sqlite) |
| 290 | ("openssl" ,openssl)
|
| 291 | ("readline" ,readline)
|
| 292 | ("zlib" ,zlib)
|
| 293 | ("tcl" ,tcl)
|
| 294 | ("tk" ,tk))) |
| 295 | (native-inputs
|
| 296 | `(("pkg-config" ,pkg-config)))
|
| 297 | (native-search-paths
|
| 298 | (list (search-path-specification
|
| 299 | (variable "PYTHONPATH")
|
| 300 | (files '("lib/python2.7/site-packages")))))
|
| 301 | (home-page "https://www.python.org")
|
| 302 | (synopsis "High-level, dynamically-typed programming language")
|
| 303 | (description
|
| 304 | "Python is a remarkably powerful dynamic programming language that
|
| 305 | is used in a wide variety of application domains. Some of its key
|
| 306 | distinguishing features include: clear, readable syntax; strong
|
| 307 | introspection capabilities; intuitive object orientation; natural
|
| 308 | expression of procedural code; full modularity, supporting hierarchical
|
| 309 | packages; exception-based error handling; and very high level dynamic
|
| 310 | data types.")
|
| 311 | (properties '((cpe-name . "python")))
|
| 312 | (license license:psfl)))
|
| 313 |
|
| 314 | |
| 315 | (define-public python-2 python-2.7)
|
| 316 |
|
| 317 | (define-public python2-called-python
|
| 318 | |
| 319 | |
| 320 | |
| 321 | (package
|
| 322 | (inherit python-2)
|
| 323 | (name "python")
|
| 324 | (properties `((superseded . ,python-2)))))
|
| 325 |
|
| 326 | (define-public python-3.7
|
| 327 | (package (inherit python-2)
|
| 328 | (name "python")
|
| 329 | (version "3.7.4")
|
| 330 | (source (origin
|
| 331 | (method url-fetch)
|
| 332 | (uri (string-append "https://www.python.org/ftp/python/"
|
| 333 | version "/Python-" version ".tar.xz"))
|
| 334 | (patches (search-patches
|
| 335 | "python-3-fix-tests.patch"
|
| 336 | "python-3-deterministic-build-info.patch"
|
| 337 | "python-3-search-paths.patch"))
|
| 338 | (sha256
|
| 339 | (base32
|
| 340 | "0gxiv5617zd7dnqm5k9r4q2188lk327nf9jznwq9j6b8p0s92ygv"))
|
| 341 | (modules '((guix build utils)))
|
| 342 | (snippet
|
| 343 | '(begin
|
| 344 | |
| 345 | (delete-file-recursively "Modules/expat")
|
| 346 | (substitute* "Modules/Setup.dist"
|
| 347 | |
| 348 | (("^#pyexpat.*") "pyexpat pyexpat.c -lexpat\n"))
|
| 349 | #t))))
|
| 350 | (arguments
|
| 351 | (substitute-keyword-arguments (package-arguments python-2)
|
| 352 | ((#:make-flags _)
|
| 353 | `(list (string-append
|
| 354 | (format #f "TESTOPTS=-j~d" (parallel-job-count))
|
| 355 | |
| 356 | " --exclude test_mmap"
|
| 357 | |
| 358 | |
| 359 | " test_socket"
|
| 360 | |
| 361 | |
| 362 | ,@(if (string-prefix? "aarch64" (%current-system))
|
| 363 | '(" test_ctypes")
|
| 364 | '()))))
|
| 365 | ((#:phases phases)
|
| 366 | `(modify-phases ,phases
|
| 367 | (add-before 'check 'set-TZDIR
|
| 368 | (lambda* (#:key inputs #:allow-other-keys)
|
| 369 | |
| 370 | (setenv "TZDIR"
|
| 371 | (string-append (assoc-ref inputs "tzdata")
|
| 372 | "/share/zoneinfo"))
|
| 373 | #t))
|
| 374 | |
| 375 | |
| 376 | (add-before 'check 'unset-SOURCE_DATE_EPOCH
|
| 377 | (lambda _ (unsetenv "SOURCE_DATE_EPOCH") #t))
|
| 378 | (add-after 'check 'reset-SOURCE_DATE_EPOCH
|
| 379 | (lambda _ (setenv "SOURCE_DATE_EPOCH" "1") #t))
|
| 380 | (replace 'rebuild-bytecode
|
| 381 | (lambda* (#:key outputs #:allow-other-keys)
|
| 382 | (let ((out (assoc-ref outputs "out")))
|
| 383 | |
| 384 | |
| 385 | (setenv "PYTHONHASHSEED" "0")
|
| 386 | (for-each
|
| 387 | (lambda (opt)
|
| 388 | (format #t "Compiling with optimization level: ~a\n"
|
| 389 | (if (null? opt) "none" (car opt)))
|
| 390 | (for-each (lambda (file)
|
| 391 | (apply invoke
|
| 392 | `(,(string-append out "/bin/python3")
|
| 393 | ,@opt
|
| 394 | "-m" "compileall"
|
| 395 | "-f" |
| 396 | |
| 397 | "-x" "lib2to3/.*"
|
| 398 | ,file)))
|
| 399 | (find-files out "\\.py$")))
|
| 400 | (list '() '("-O") '("-OO")))
|
| 401 | #t)))))))
|
| 402 | (native-inputs
|
| 403 | `(("tzdata" ,tzdata-for-tests)
|
| 404 | ,@(package-native-inputs python-2)))
|
| 405 | (native-search-paths
|
| 406 | (list (search-path-specification
|
| 407 | (variable "PYTHONPATH")
|
| 408 | (files (list (string-append "lib/python"
|
| 409 | (version-major+minor version)
|
| 410 | "/site-packages"))))))))
|
| 411 |
|
| 412 | (define-public python-3.8
|
| 413 | (package
|
| 414 | (inherit python-3.7)
|
| 415 | (name "python-next")
|
| 416 | (version "3.8.0")
|
| 417 | (source
|
| 418 | (origin
|
| 419 | (inherit (package-source python-3.7))
|
| 420 | (uri (string-append "https://www.python.org/ftp/python/"
|
| 421 | version "/Python-" version ".tar.xz"))
|
| 422 | (sha256 (base32 "110d0did9rxn7rg85kf2fwli5hqq44xv2d8bi7d92m7v2d728mmk"))
|
| 423 | (patches (search-patches
|
| 424 | "python-3.8-search-paths.patch"
|
| 425 | "python-3-fix-tests.patch"
|
| 426 | "python-3.8-fix-tests.patch"
|
| 427 | "python-3-deterministic-build-info.patch"))
|
| 428 | (snippet
|
| 429 | '(begin
|
| 430 | |
| 431 | (delete-file-recursively "Modules/expat")
|
| 432 | (substitute* "Modules/Setup"
|
| 433 | |
| 434 | (("^#pyexpat.*") "pyexpat pyexpat.c -lexpat\n"))
|
| 435 | #t))))))
|
| 436 |
|
| 437 | |
| 438 | (define-public python-3 python-3.7)
|
| 439 |
|
| 440 | |
| 441 | (define-public python python-3)
|
| 442 |
|
| 443 | |
| 444 | |
| 445 |
|
| 446 | (define-public python2-minimal
|
| 447 | (package/inherit python-2
|
| 448 | (name "python2-minimal")
|
| 449 | (outputs '("out"))
|
| 450 |
|
| 451 | |
| 452 | |
| 453 | |
| 454 | |
| 455 | (inputs `(("expat" ,expat)
|
| 456 | ("libffi" ,libffi)
|
| 457 | ("zlib" ,zlib)))))
|
| 458 |
|
| 459 | (define-public python-minimal
|
| 460 | (package/inherit python
|
| 461 | (name "python-minimal")
|
| 462 | (outputs '("out"))
|
| 463 |
|
| 464 | |
| 465 | |
| 466 | |
| 467 | |
| 468 | (inputs `(("expat" ,expat)
|
| 469 | ("libffi" ,libffi)
|
| 470 | ("openssl" ,openssl)
|
| 471 | ("zlib" ,zlib)))))
|
| 472 |
|
| 473 | (define-public python-debug
|
| 474 | (package/inherit python
|
| 475 | (name "python-debug")
|
| 476 | (outputs '("out" "debug"))
|
| 477 | (build-system gnu-build-system)
|
| 478 | (arguments
|
| 479 | (substitute-keyword-arguments (package-arguments python)
|
| 480 | ((#:configure-flags flags '())
|
| 481 | `(cons "--with-pydebug" ,flags))))
|
| 482 | (synopsis
|
| 483 | "High-level, dynamically-typed programming language (for debugging)")
|
| 484 | (description
|
| 485 | "This variant of Python provides an interpreter built with
|
| 486 | @code{--with-pydebug} to help develop and debug extensions. See
|
| 487 | @url{https://pythonextensionpatterns.readthedocs.io/en/latest/debugging/debug.html},
|
| 488 | for more information.")))
|
| 489 |
|
| 490 | (define* (wrap-python3 python
|
| 491 | #:optional
|
| 492 | (name (string-append (package-name python) "-wrapper")))
|
| 493 | (package/inherit python
|
| 494 | (name name)
|
| 495 | (source #f)
|
| 496 | (build-system trivial-build-system)
|
| 497 | (outputs '("out"))
|
| 498 | (inputs `(("bash" ,bash)))
|
| 499 | (propagated-inputs `(("python" ,python)))
|
| 500 | (arguments
|
| 501 | `(#:modules ((guix build utils))
|
| 502 | #:builder
|
| 503 | (begin
|
| 504 | (use-modules (guix build utils))
|
| 505 | (let ((bin (string-append (assoc-ref %outputs "out") "/bin"))
|
| 506 | (python (string-append (assoc-ref %build-inputs "python") "/bin/")))
|
| 507 | (mkdir-p bin)
|
| 508 | (for-each
|
| 509 | (lambda (old new)
|
| 510 | (symlink (string-append python old)
|
| 511 | (string-append bin "/" new)))
|
| 512 | `("python3" ,"pydoc3" ,"idle3" ,"pip3")
|
| 513 | `("python" ,"pydoc" ,"idle" ,"pip"))
|
| 514 | |
| 515 | |
| 516 | (let ((bash (string-append (assoc-ref %build-inputs "bash")
|
| 517 | "/bin/bash"))
|
| 518 | (old (string-append python "python3-config"))
|
| 519 | (new (string-append bin "/python-config")))
|
| 520 | (with-output-to-file new
|
| 521 | (lambda ()
|
| 522 | (format #t "#!~a~%" bash)
|
| 523 | (format #t "exec \"~a\" \"$@\"~%" old)
|
| 524 | (chmod new #o755)
|
| 525 | #t)))))))
|
| 526 | (synopsis "Wrapper for the Python 3 commands")
|
| 527 | (description
|
| 528 | "This package provides wrappers for the commands of Python@tie{}3.x such
|
| 529 | that they can be invoked under their usual name---e.g., @command{python}
|
| 530 | instead of @command{python3}.")))
|
| 531 |
|
| 532 | (define-public python-wrapper (wrap-python3 python))
|
| 533 | (define-public python-minimal-wrapper (wrap-python3 python-minimal))
|
| 534 |
|
| 535 | (define-public micropython
|
| 536 | (package
|
| 537 | (name "micropython")
|
| 538 | (version "1.11")
|
| 539 | (source
|
| 540 | (origin
|
| 541 | (method url-fetch)
|
| 542 | (uri (string-append "https://github.com/micropython/micropython/"
|
| 543 | "releases/download/v" version
|
| 544 | "/micropython-" version ".tar.gz"))
|
| 545 | (sha256
|
| 546 | (base32
|
| 547 | "0px3xhw16rl0l7qifq7jw1gq92wzlnhd17dmszv9m2c3wbzs9p9f"))
|
| 548 | (modules '((guix build utils)))
|
| 549 | (snippet
|
| 550 | '(begin
|
| 551 | (delete-file-recursively "ports/cc3200/FreeRTOS")
|
| 552 | (with-directory-excursion "lib"
|
| 553 | |
| 554 | (for-each delete-file-recursively
|
| 555 | '("libffi" "lwip" "stm32lib" "nrfx")))
|
| 556 | #t))))
|
| 557 | (build-system gnu-build-system)
|
| 558 | (arguments
|
| 559 | `(#:phases
|
| 560 | (modify-phases %standard-phases
|
| 561 | (add-before 'build 'prepare-build
|
| 562 | (lambda _
|
| 563 | (chdir "ports/unix")
|
| 564 | |
| 565 | (substitute* "Makefile"
|
| 566 | (("-Os") "-Os -ffp-contract=off"))
|
| 567 | #t))
|
| 568 | (replace 'install-license-files
|
| 569 | |
| 570 | (lambda* (#:key outputs #:allow-other-keys)
|
| 571 | (let* ((out (assoc-ref outputs "out"))
|
| 572 | (dest (string-append out "/share/doc/" ,name "-" ,version "/")))
|
| 573 | (install-file "../../LICENSE" dest))
|
| 574 | #t))
|
| 575 | (delete 'configure)) |
| 576 | #:make-flags (list (string-append "PREFIX=" (assoc-ref %outputs "out"))
|
| 577 | "V=1")
|
| 578 | #:test-target "test"))
|
| 579 | (native-inputs
|
| 580 | `(("pkg-config" ,pkg-config)
|
| 581 | ("python" ,python-wrapper)))
|
| 582 | (inputs
|
| 583 | `(("libffi" ,libffi)))
|
| 584 | (home-page "https://micropython.org/")
|
| 585 | (synopsis "Python implementation for microcontrollers and constrained systems")
|
| 586 | (description "MicroPython is a lean and efficient implementation of the
|
| 587 | Python 3 programming language that includes a small subset of the Python
|
| 588 | standard library and is optimised to run on microcontrollers and in constrained
|
| 589 | environments. MicroPython is packed full of advanced features such as an
|
| 590 | interactive prompt, arbitrary precision integers, closures, list comprehension,
|
| 591 | generators, exception handling and more. Still it is compact enough to fit and
|
| 592 | run within just 256k of code space and 16k of RAM. MicroPython aims to be as
|
| 593 | compatible with normal Python as possible to allow you to transfer code with
|
| 594 | ease from the desktop to a microcontroller or embedded system.")
|
| 595 | (license license:expat)))
|