;;; Guix Past --- Packages from the past for GNU Guix.
;;; Copyright © 2022 Ricardo Wurmus <rekado@elephly.net>
;;;
;;; This file is part of Guix Past.
;;;
;;; Guix Past 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.
;;;
;;; Guix Past 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 Guix Past.  If not, see <http://www.gnu.org/licenses/>.

(define-module (past packages python-xyz)
  #:use-module (guix utils)
  #:use-module (guix gexp)
  #:use-module (guix packages)
  #:use-module (guix download)
  #:use-module (guix build-system python)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (gnu packages)
  #:use-module (gnu packages python)
  #:use-module (ice-9 match))

(define (%python2-replacement name)
  (match name
    ("python-pyparsing" (delay python2-pyparsing))
    ("python-more-itertools" (delay python2-more-itertools))
    (_ #f)))

(define* (package-with-explicit-python python old-prefix new-prefix)
  "Return a procedure of one argument, P.  The procedure creates a package with
the same fields as P, which is assumed to use PYTHON-BUILD-SYSTEM, such that
it is compiled with PYTHON instead.  The inputs are changed recursively
accordingly.  If the name of P starts with OLD-PREFIX, this is replaced by
NEW-PREFIX; otherwise, NEW-PREFIX is prepended to the name."
  (define package-variant
    (lambda (package)
      (%python2-replacement (package-name package))))

  (define (transform p)
    (cond
     ;; Use a package variant if it exists
     ((package-variant p)
      => force)

     ;; Otherwise build the new package object graph.
     ((eq? (package-build-system p) python-build-system)
      (package/inherit p
        (location (package-location p))
        (name (let ((name (package-name p)))
                (string-append new-prefix
                               (if (string-prefix? old-prefix name)
                                   (substring name
                                              (string-length old-prefix))
                                   name))))
        (arguments
         (let ((python (if (promise? python)
                           (force python)
                           python)))
           (ensure-keyword-arguments (package-arguments p)
                                     `(#:python ,python))))))
     (else p)))

  (define (cut? p)
    (or (not (eq? (package-build-system p) python-build-system))
        (package-variant p)))

  (package-mapping transform cut?))

(define python2-package
  ;; Note: delay call to 'default-python2' until after the 'arguments' field
  ;; of packages is accessed to avoid a circular dependency when evaluating
  ;; the top-level of (gnu packages python).
  (package-with-explicit-python (delay (default-python2))
                                "python-" "python2-"))


(define-public python2-funcsigs (package (name "python2-funcsigs") (version "1.0.2") (source (origin (method url-fetch) (uri (pypi-uri "funcsigs" version)) (sha256 (base32 "0l4g5818ffyfmfs1a924811azhjj8ax9xd1cffr1mzd3ycn0zfx7")))) (build-system python-build-system) (arguments `(#:tests? #false ;keep it simple to avoid a dependency cycle #:python ,python-2)) (home-page "http://funcsigs.readthedocs.org") (synopsis "Python function signatures from PEP362") (description "Backport of @code{funcsigs} which was introduced in Python 3.3.") (license license:asl2.0))) ;; The 5.x series are the last versions supporting Python 2.7. (define-public python2-more-itertools (package (name "python2-more-itertools") (version "5.0.0") (source (origin (method url-fetch) (uri (pypi-uri "more-itertools" version)) (sha256 (base32 "1r12cm6mcdwdzz7d47a6g4l437xsvapdlgyhqay3i2nrlv03da9q")))) (arguments `(#:python ,python-2)) (propagated-inputs (list (specification->package "python2-six"))) (build-system python-build-system) (home-page "https://github.com/erikrose/more-itertools") (synopsis "More routines for operating on iterables, beyond itertools") (description "Python's built-in @code{itertools} module implements a number of iterator building blocks inspired by constructs from APL, Haskell, and SML. @code{more-itertools} includes additional building blocks for working with iterables.") (license license:expat))) ;;; This is the last release compatible with Python 2. (define-public python2-pyparsing (package (name "python2-pyparsing") (version "2.4.7") (source (origin (method url-fetch) (uri (pypi-uri "pyparsing" version)) (sha256 (base32 "1hgc8qrbq1ymxbwfbjghv01fm3fbpjwpjwi0bcailxxzhf3yq0y2")))) (build-system python-build-system) (outputs '("out" "doc")) (arguments `(#:tests? #f ;no test target #:python ,python-2 #:phases (modify-phases %standard-phases (add-after 'install 'install-doc (lambda* (#:key outputs #:allow-other-keys) (let* ((doc (string-append (assoc-ref outputs "doc") "/share/doc/" ,name "-" ,version)) (html-doc (string-append doc "/html")) (examples (string-append doc "/examples"))) (mkdir-p html-doc) (mkdir-p examples) (for-each (lambda (dir tgt) (map (lambda (file) (install-file file tgt)) (find-files dir ".*"))) (list "docs" "htmldoc" "examples") (list doc html-doc examples)))))))) (home-page "https://github.com/pyparsing/pyparsing") (synopsis "Python parsing class library") (description "The pyparsing module is an alternative approach to creating and executing simple grammars, vs. the traditional lex/yacc approach, or the use of regular expressions. The pyparsing module provides a library of classes that client code uses to construct the grammar directly in Python code.") (license license:expat))) ;; Pytest 4.x are the last versions that support Python 2. (define-public python2-pytest (package (name "python2-pytest") (version "4.6.11") (source (origin (method url-fetch) (uri (pypi-uri "pytest" version)) (sha256 (base32 "0ls3pqr86xgif6bphsb6wrww9r2vc7p7a2naq8zcq8115wwq5yjh")))) (build-system python-build-system) (arguments `(#:python ,python-2 #:phases (modify-phases %standard-phases (add-before 'build 'pretend-version ;; The version string is usually derived via setuptools-scm, but ;; without the git metadata available, the version string is set to ;; '0.0.0'. (lambda _ (setenv "SETUPTOOLS_SCM_PRETEND_VERSION" ,version))) (replace 'check (lambda* (#:key (tests? #t) #:allow-other-keys) (setenv "TERM" "dumb") ;attempt disabling markup tests (if tests? (invoke "pytest" "-vv" "-k" (string-append ;; This test involves the /usr directory, and fails. " not test_argcomplete" ;; These test do not honor the isatty detection and ;; fail. " and not test_code_highlight" " and not test_color_yes")) (format #t "test suite not run~%"))))))) (propagated-inputs (cons* python2-funcsigs python2-more-itertools (map (compose python2-package specification->package) (list "python-atomicwrites" "python-attrs-bootstrap" ;"python-importlib-metadata-bootstrap" "python-packaging-bootstrap" "python-pathlib2" "python-pluggy" "python-py" "python-six-bootstrap" "python-wcwidth")))) #; (native-inputs (cons (specification->package "bash") ;tests require 'compgen' (map (compose python2-package specification->package) (list "python-hypothesis" "python-nose" ;"python-mock" "python-setuptools-scm")))) (home-page "https://docs.pytest.org/en/latest/") (synopsis "Python testing library") (description "Pytest is a testing tool that provides auto-discovery of test modules and functions, detailed info on failing assert statements, modular fixtures, and many external plugins.") (license license:expat))) #; (define-public python2-cython (package (name "python2-cython") (version "0.29.24") (source (origin (method url-fetch) (uri (pypi-uri "Cython" version)) (sha256 (base32 "0hw4gs18rh4slij1fg252argxhraypld9apbqbl60230qc3lvw6d")))) (build-system python-build-system) ;; we need the full python package and not just the python-wrapper ;; because we need libpython2.7m.so (inputs (list python-2)) (arguments `(#:phases (modify-phases %standard-phases (add-before 'check 'set-HOME ;; some tests require access to "$HOME/.cython" (lambda _ (setenv "HOME" "/tmp"))) (add-before 'check 'adjust-test_embed (lambda _ (substitute* "runtests.py" ;; test_embed goes great lengths to find the static libpythonX.Y.a ;; so it can give the right -L flag to GCC when embedding static ;; builds of Python. It is unaware that the Python "config" ;; directory (where the static library lives) was renamed in ;; Python 3, and falls back to sysconfig.get_config_var('LIBDIR'), ;; which works fine, because that is where the shared library is. ;; ;; It also appears to be unaware that the Makefile in Demos/embed ;; already unconditionally pass the static library location to GCC, ;; after checking sysconfig.get_config_var('LIBPL). ;; ;; The effect is that the linker is unable to resolve libexpat ;; symbols when building for Python 2, because neither the Python 2 ;; shared library nor Expat is available. To fix it, we can either ;; add Expat as an input and make it visible to the linker, or just ;; prevent it from overriding the Python shared library location. ;; The end result is identical, so we take the easy route. ((" or libname not in os\\.listdir\\(libdir\\)") "")))) (replace 'check (lambda* (#:key tests? #:allow-other-keys) ;; Disable compiler optimizations to greatly reduce the running ;; time of the test suite. (setenv "CFLAGS" "-O0") (when tests? (invoke "python" "runtests.py" "-vv" "-j" (number->string (parallel-job-count)) ;; XXX: On 32-bit architectures, running the parallel tests ;; fails on many-core systems, see ;; <https://github.com/cython/cython/issues/2807>. ,@(if (not (target-64bit?)) '("-x" "run.parallel") '()) ;; This test fails when running on 24 cores. "-x" "cpp_stl_conversion"))))))) (home-page "https://cython.org/") (synopsis "C extensions for Python") (description "Cython is an optimising static compiler for both the Python programming language and the extended Cython programming language. It makes writing C extensions for Python as easy as Python itself.") (license license:asl2.0))) ;; Numpy 1.16.x is the last version that supports Python 2. #; (define-public python2-numpy (package (name "python2-numpy") (version "1.16.5") (source (origin (method url-fetch) (uri (string-append "https://github.com/numpy/numpy/releases/download/v" version "/numpy-" version ".tar.gz")) (sha256 (base32 "0lg1cycxzi4rvvrd5zxinpdz0ni792fpx6xjd75z1923zcac8qrb")))) (build-system python-build-system) (arguments (list #:python python-2 #:modules '((guix build utils) (guix build python-build-system) (ice-9 format)) #:phases #~(modify-phases %standard-phases (add-before 'build 'parallelize-build (lambda _ (setenv "NPY_NUM_BUILD_JOBS" (number->string (parallel-job-count))))) (add-before 'build 'configure-blas (lambda* (#:key inputs #:allow-other-keys) (call-with-output-file "site.cfg" (lambda (port) (format port "\ [openblas] libraries = openblas library_dirs = ~a/lib include_dirs = ~:*~a/include~%" #$(this-package-input "openblas")))))) (add-before 'build 'fix-executable-paths (lambda* (#:key inputs #:allow-other-keys) ;; Make /gnu/store/...-bash-.../bin/sh the default shell, ;; instead of /bin/sh. (substitute* "numpy/distutils/exec_command.py" (("'/bin/sh'") (format #f "~s" (search-input-file inputs "bin/bash")))))) (add-after 'unpack 'delete-failing-tests (lambda _ ;; There's just one failing test here. (delete-file "numpy/linalg/tests/test_linalg.py") ;; ...and this one depends on the previous one. (delete-file "numpy/matrixlib/tests/test_matrix_linalg.py"))) (replace 'check ;; Older versions don't cope well with the extra Pytest ;; options, so remove them. (lambda* (#:key tests? outputs inputs #:allow-other-keys) (when tests? (invoke "./runtests.py" "-vv" "--no-build" "--mode=fast" "-j" (number->string (parallel-job-count))))))))) (inputs (map specification->package (list "bash" "openblas"))) (native-inputs (cons gfortran (map specification->package (list "python2-cython" "python2-pytest")))) (home-page "https://numpy.org") (synopsis "Fundamental package for scientific computing with Python") (description "NumPy is the fundamental package for scientific computing with Python. It contains among other things: a powerful N-dimensional array object, sophisticated (broadcasting) functions, tools for integrating C/C++ and Fortran code, useful linear algebra, Fourier transform, and random number capabilities.") (license license:bsd-3)))

Generated by Ricardo Wurmus using scpaste at Thu Jun 2 11:32:20 2022. CEST. (original)