mirror of
https://codeberg.org/guix/guix.git
synced 2026-01-25 03:55:08 -06:00
build-system/pyproject: Add phase 'set-version.
Rationale: When gradually moving sources to git-fetch, a lot of 'set-version phases have been added within the python packages. To support moving to git source even more, add a 'set-version phase that does this work automatically. * guix/build/pyproject-build-system.scm (set-version): New variable. (%standard-phases): Record 'set-version phase.
This commit is contained in:
parent
bc2fc4a117
commit
14ff05bae7
1 changed files with 36 additions and 0 deletions
|
|
@ -28,6 +28,7 @@
|
|||
#:use-module (ice-9 rdelim)
|
||||
#:use-module (ice-9 regex)
|
||||
#:use-module (srfi srfi-1)
|
||||
#:use-module (srfi srfi-2)
|
||||
#:use-module (srfi srfi-26)
|
||||
#:use-module (srfi srfi-34)
|
||||
#:use-module (srfi srfi-35)
|
||||
|
|
@ -152,6 +153,40 @@ by Cython."
|
|||
(format #t "Possible Cythonized file found: ~a~%" generated-file))))
|
||||
(find-files "." "\\.pyx$")))
|
||||
|
||||
(define* (set-version #:key name inputs #:allow-other-keys)
|
||||
"Set the expect package version environment variable in Semantic Versioning
|
||||
format when python-setuptools-scm or python-pbr is present."
|
||||
|
||||
(define (extract-version name)
|
||||
"Extract version from a name-version string."
|
||||
;; Note: This fails if the package-name contains a dot.
|
||||
(and-let* ((first-dot (or (string-index name #\.)
|
||||
(string-length name)))
|
||||
(prev-hyphen (string-rindex name #\- 0 first-dot)))
|
||||
(substring name (+ prev-hyphen 1))))
|
||||
|
||||
(let ((package (and=> (any (cute assoc <> inputs)
|
||||
(list "python-setuptools-scm"
|
||||
"python-setuptools-scm-bootstrap"
|
||||
"python-pbr"))
|
||||
car)))
|
||||
;; Both git and hg use -checkout suffixes.
|
||||
(if (and package (string-suffix? "-checkout" (assoc-ref inputs "source")))
|
||||
(and-let* ((version (extract-version name))
|
||||
;; version here can be semver-revision-commit.
|
||||
(version (first (string-split version #\-))))
|
||||
(match package
|
||||
((or "python-setuptools-scm" "python-setuptools-scm-bootstrap")
|
||||
(setenv "SETUPTOOLS_SCM_PRETEND_VERSION" version))
|
||||
("python-pbr"
|
||||
(setenv "PBR_VERSION" version))
|
||||
(_ ;should never happen.
|
||||
#f)))
|
||||
;; Otherwise, it is probably from a wheel and doesn't require
|
||||
;; the phase in the first place.
|
||||
(format #t "The source doesn't seem to use version control, \
|
||||
python-setuptools-scm is likely unnecessary as a native-input.~%"))))
|
||||
|
||||
(define* (build #:key outputs build-backend backend-path configure-flags #:allow-other-keys)
|
||||
"Build a given Python package."
|
||||
|
||||
|
|
@ -501,6 +536,7 @@ installed with setuptools."
|
|||
enable-bytecode-determinism)
|
||||
(add-after 'enable-bytecode-determinism 'ensure-no-cythonized-files
|
||||
ensure-no-cythonized-files)
|
||||
(add-after 'ensure-no-cythonized-files 'set-version set-version)
|
||||
(delete 'bootstrap)
|
||||
(replace 'set-SOURCE-DATE-EPOCH set-SOURCE-DATE-EPOCH*)
|
||||
(delete 'configure) ;not needed
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue