pyproject.scm 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2021 Lars-Dominik Braun <lars@6xq.net>
  3. ;;; Copyright © 2022 Marius Bakke <marius@gnu.org>
  4. ;;;
  5. ;;; This file is part of GNU Guix.
  6. ;;;
  7. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  8. ;;; under the terms of the GNU General Public License as published by
  9. ;;; the Free Software Foundation; either version 3 of the License, or (at
  10. ;;; your option) any later version.
  11. ;;;
  12. ;;; GNU Guix is distributed in the hope that it will be useful, but
  13. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;;; GNU General Public License for more details.
  16. ;;;
  17. ;;; You should have received a copy of the GNU General Public License
  18. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  19. (define-module (guix build-system pyproject)
  20. #:use-module ((gnu packages) #:select (search-auxiliary-file))
  21. #:use-module (guix gexp)
  22. #:use-module (guix store)
  23. #:use-module (guix utils)
  24. #:use-module (guix gexp)
  25. #:use-module (guix monads)
  26. #:use-module (guix packages)
  27. #:use-module (guix search-paths)
  28. #:use-module (guix build-system)
  29. #:use-module (guix build-system gnu)
  30. #:use-module (guix build-system python)
  31. #:use-module (srfi srfi-1)
  32. #:export (%pyproject-build-system-modules
  33. default-python
  34. pyproject-build
  35. pyproject-build-system))
  36. ;; Commentary:
  37. ;;
  38. ;; Standard build procedure for Python packages using 'pyproject.toml'.
  39. ;; This is implemented as an extension of 'python-build-system'.
  40. ;;
  41. ;; Code:
  42. (define %pyproject-build-system-modules
  43. ;; Build-side modules imported by default.
  44. `((guix build pyproject-build-system)
  45. (guix build json)
  46. ,@%python-build-system-modules))
  47. (define (default-python)
  48. "Return the default Python package."
  49. ;; Lazily resolve the binding to avoid a circular dependency.
  50. (let ((python (resolve-interface '(gnu packages python))))
  51. (module-ref python 'python-toolchain)))
  52. (define sanity-check.py
  53. (search-auxiliary-file "python/sanity-check.py"))
  54. (define* (lower name
  55. #:key source inputs native-inputs outputs system target
  56. (python (default-python))
  57. #:allow-other-keys
  58. #:rest arguments)
  59. "Return a bag for NAME."
  60. (define private-keywords
  61. '(#:target #:python #:inputs #:native-inputs))
  62. (and (not target) ;XXX: no cross-compilation
  63. (bag
  64. (name name)
  65. (system system)
  66. (host-inputs `(,@(if source
  67. `(("source" ,source))
  68. '())
  69. ,@inputs
  70. ;; Keep the standard inputs of 'gnu-build-system'.
  71. ,@(standard-packages)))
  72. (build-inputs `(("python" ,python)
  73. ("sanity-check.py" ,(local-file sanity-check.py))
  74. ,@native-inputs))
  75. (outputs (append outputs '(wheel)))
  76. (build pyproject-build)
  77. (arguments (strip-keyword-arguments private-keywords arguments)))))
  78. (define* (pyproject-build name inputs
  79. #:key source
  80. (tests? #t)
  81. (configure-flags ''())
  82. (build-backend #f)
  83. (test-backend #f)
  84. (test-flags ''())
  85. (phases '%standard-phases)
  86. (outputs '("out" "wheel"))
  87. (search-paths '())
  88. (system (%current-system))
  89. (guile #f)
  90. (imported-modules %pyproject-build-system-modules)
  91. (modules '((guix build pyproject-build-system)
  92. (guix build utils))))
  93. "Build SOURCE using PYTHON, and with INPUTS."
  94. (define build
  95. (with-imported-modules imported-modules
  96. #~(begin
  97. (use-modules #$@(sexp->gexp modules))
  98. #$(with-build-variables inputs outputs
  99. #~(pyproject-build
  100. #:name #$name
  101. #:source #+source
  102. #:configure-flags #$configure-flags
  103. #:system #$system
  104. #:build-backend #$build-backend
  105. #:test-backend #$test-backend
  106. #:test-flags #$test-flags
  107. #:tests? #$tests?
  108. #:phases #$(if (pair? phases)
  109. (sexp->gexp phases)
  110. phases)
  111. #:outputs %outputs
  112. #:search-paths '#$(sexp->gexp
  113. (map search-path-specification->sexp
  114. search-paths))
  115. #:inputs %build-inputs)))))
  116. (mlet %store-monad ((guile (package->derivation (or guile (default-guile))
  117. system #:graft? #f)))
  118. (gexp->derivation name build
  119. #:system system
  120. #:graft? #f ;consistent with 'gnu-build'
  121. #:target #f
  122. #:guile-for-build guile)))
  123. (define pyproject-build-system
  124. (build-system
  125. (name 'pyproject)
  126. (description "The PEP517-compliant Python build system")
  127. (lower lower)))
  128. ;;; pyproject.scm ends here