Browse Source

Add 'python-build-system'.

* guix/build-system/python.scm, guix/build/python-build-system.scm: New files.
* Makefile.am (MODULES): Add them.
gn-latest-20200428
Nikita Karetnikov 8 years ago
parent
commit
40506d5d92
3 changed files with 208 additions and 0 deletions
  1. +2
    -0
      Makefile.am
  2. +115
    -0
      guix/build-system/python.scm
  3. +91
    -0
      guix/build/python-build-system.scm

+ 2
- 0
Makefile.am View File

@ -46,6 +46,7 @@ MODULES = \
guix/build-system/cmake.scm \
guix/build-system/gnu.scm \
guix/build-system/perl.scm \
guix/build-system/python.scm \
guix/build-system/trivial.scm \
guix/ftp-client.scm \
guix/web.scm \
@ -56,6 +57,7 @@ MODULES = \
guix/build/cmake-build-system.scm \
guix/build/gnu-build-system.scm \
guix/build/perl-build-system.scm \
guix/build/python-build-system.scm \
guix/build/utils.scm \
guix/build/union.scm \
guix/build/rpath.scm \


+ 115
- 0
guix/build-system/python.scm View File

@ -0,0 +1,115 @@
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2013 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2013 Nikita Karetnikov <nikita@karetnikov.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 (guix build-system python)
#:use-module (guix store)
#:use-module (guix utils)
#:use-module (guix packages)
#:use-module (guix derivations)
#:use-module (guix build-system)
#:use-module (guix build-system gnu)
#:use-module (ice-9 match)
#:export (python-build
python-build-system))
;; Commentary:
;;
;; Standard build procedure for Python packages using 'setup.py'. This is
;; implemented as an extension of 'gnu-build-system'.
;;
;; Code:
(define* (python-build store name source inputs
#:key
(python (@ (gnu packages python) python))
(python-version
(string-take (package-version
(@ (gnu packages python) python)) 3))
(tests? #t)
(configure-flags ''())
(phases '(@ (guix build python-build-system)
%standard-phases))
(outputs '("out"))
(search-paths '())
(system (%current-system))
(guile #f)
(imported-modules '((guix build python-build-system)
(guix build gnu-build-system)
(guix build utils)))
(modules '((guix build python-build-system)
(guix build gnu-build-system)
(guix build utils))))
"Build SOURCE using PYTHON, and with INPUTS. This assumes that SOURCE
provides a 'setup.py' file as its build system."
(define python-search-paths
(append (package-native-search-paths python)
(standard-search-paths)))
(define builder
`(begin
(use-modules ,@modules)
(python-build #:name ,name
#:source ,(if (and source (derivation-path? source))
(derivation-path->output-path source)
source)
#:configure-flags ,configure-flags
#:system ,system
#:test-target "test"
#:tests? ,tests?
#:outputs %outputs
#:python-version ,python-version
#:search-paths ',(map search-path-specification->sexp
(append python-search-paths
search-paths))
#:inputs %build-inputs)))
(define guile-for-build
(match guile
((? package?)
(package-derivation store guile system))
((and (? string?) (? derivation-path?))
guile)
(#f ; the default
(let* ((distro (resolve-interface '(gnu packages base)))
(guile (module-ref distro 'guile-final)))
(package-derivation store guile system)))))
(let ((python (package-derivation store python system)))
(build-expression->derivation store name system
builder
`(,@(if source
`(("source" ,source))
'())
("python" ,python)
,@inputs
;; Keep the standard inputs of
;; 'gnu-build-system'.
,@(standard-inputs system))
#:modules imported-modules
#:outputs outputs
#:guile-for-build guile-for-build)))
(define python-build-system
(build-system (name 'python)
(description "The standard Python build system")
(build python-build)))
;;; python.scm ends here

+ 91
- 0
guix/build/python-build-system.scm View File

@ -0,0 +1,91 @@
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2013 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2013 Nikita Karetnikov <nikita@karetnikov.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 (guix build python-build-system)
#:use-module ((guix build gnu-build-system)
#:renamer (symbol-prefix-proc 'gnu:))
#:use-module (guix build utils)
#:use-module (ice-9 match)
#:use-module (ice-9 ftw)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-26)
#:export (%standard-phases
python-build))
;; Commentary:
;;
;; Builder-side code of the standard Python package build procedure.
;;
;; Code:
(define* (install #:key outputs (configure-flags '())
#:allow-other-keys)
"Install a given Python package."
(let ((out (assoc-ref outputs "out")))
(if (file-exists? "setup.py")
(let ((args `("setup.py" "install" ,(string-append "--prefix=" out)
,@configure-flags)))
(format #t "running 'python' with arguments ~s~%" args)
(zero? (apply system* "python" args)))
(error "no setup.py found"))))
(define* (wrap #:key outputs python-version #:allow-other-keys)
(define (list-of-files dir)
(map (cut string-append dir "/" <>)
(or (scandir dir (lambda (f)
(let ((s (stat (string-append dir "/" f))))
(eq? 'regular (stat:type s)))))
'())))
(define bindirs
(append-map (match-lambda
((_ . dir)
(list (string-append dir "/bin")
(string-append dir "/sbin"))))
outputs))
(let* ((out (assoc-ref outputs "out"))
(var `("PYTHONPATH" prefix
,(cons (string-append out "/lib/python"
python-version "/site-packages")
(search-path-as-string->list
(or (getenv "PYTHONPATH") ""))))))
(for-each (lambda (dir)
(let ((files (list-of-files dir)))
(for-each (cut wrap-program <> var)
files)))
bindirs)))
(define %standard-phases
;; 'configure' and 'build' phases are not needed. Everything is done during
;; 'install'.
(alist-cons-after
'install 'wrap
wrap
(alist-replace 'install install
(alist-delete 'configure
(alist-delete 'build
gnu:%standard-phases)))))
(define* (python-build #:key inputs (phases %standard-phases)
#:allow-other-keys #:rest args)
"Build the given Python package, applying all of PHASES in order."
(apply gnu:gnu-build #:inputs inputs #:phases phases args))
;;; python-build-system.scm ends here

Loading…
Cancel
Save