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