gnu: patchwork: Switch to pyproject.

* gnu/packages/patchutils.scm (patchwork): Run guix style.
[build-system]: Switch to pyproject-build-system.
[arguments]: Refresh them, run guix style, remove trailing #t.
[native-inputs]: Add python-setuptools.

Change-Id: I811c5ded2b517e35c49f2ae2a67178e4e3417e67
Signed-off-by: Sharlatan Hellseher <sharlatanus@gmail.com>
This commit is contained in:
Nicolas Graves 2025-09-27 15:46:28 +02:00 committed by Sharlatan Hellseher
parent af4acb48a0
commit 3c62bfeba3
No known key found for this signature in database
GPG key ID: 76D727BFF62CD2B5

View file

@ -35,6 +35,7 @@
#:use-module (guix build-system glib-or-gtk) #:use-module (guix build-system glib-or-gtk)
#:use-module (guix build-system meson) #:use-module (guix build-system meson)
#:use-module (guix build-system ocaml) #:use-module (guix build-system ocaml)
#:use-module (guix build-system pyproject)
#:use-module (guix build-system python) #:use-module (guix build-system python)
#:use-module (gnu packages) #:use-module (gnu packages)
#:use-module (gnu packages autotools) #:use-module (gnu packages autotools)
@ -367,40 +368,37 @@ you to figure out what is going on in that merge you keep avoiding.")
(package (package
(name "patchwork") (name "patchwork")
(version "3.2.1") (version "3.2.1")
(source (origin (source
(method git-fetch) (origin
(uri (git-reference (method git-fetch)
(url "https://github.com/getpatchwork/patchwork") (uri (git-reference
(commit (string-append "v" version)))) (url "https://github.com/getpatchwork/patchwork")
(file-name (git-file-name name version)) (commit (string-append "v" version))))
(sha256 (file-name (git-file-name name version))
(base32 (sha256
"04ikawdyhjwspxvhazbp5f5vym672y0jcw8rd2m75h9ipcpnyxim")))) (base32 "04ikawdyhjwspxvhazbp5f5vym672y0jcw8rd2m75h9ipcpnyxim"))))
(build-system python-build-system) (build-system pyproject-build-system)
(arguments (arguments
`(;; TODO: Tests require a running database (list
#:tests? #f #:tests? #f ;TODO: Tests require a running database
#:phases #:phases
(modify-phases %standard-phases #~(modify-phases %standard-phases
(delete 'configure) (delete 'configure)
(delete 'build) (delete 'build)
(add-after 'unpack 'replace-wsgi.py (add-after 'unpack 'replace-wsgi.py
(lambda* (#:key inputs outputs #:allow-other-keys) (lambda* (#:key inputs outputs #:allow-other-keys)
(delete-file "patchwork/wsgi.py") (delete-file "patchwork/wsgi.py")
(call-with-output-file "patchwork/wsgi.py" (call-with-output-file "patchwork/wsgi.py"
(lambda (port) (lambda (port)
;; Embed the PYTHONPATH containing the dependencies, as well ;; Embed the PYTHONPATH containing the dependencies, as well
;; as the python modules in this package in the wsgi.py file, ;; as the python modules in this package in the wsgi.py file,
;; as this will ensure they are available at runtime. ;; as this will ensure they are available at runtime.
(define pythonpath (define pythonpath
(string-append (getenv "GUIX_PYTHONPATH") (string-append (getenv "GUIX_PYTHONPATH") ":"
":" (site-packages inputs outputs)))
(site-packages inputs outputs))) (display (string-append
(display "\nimport os, sys\n\nsys.path.extend('" pythonpath
(string-append " "'.split(':'))
import os, sys
sys.path.extend('" pythonpath "'.split(':'))
from django.core.wsgi import get_wsgi_application from django.core.wsgi import get_wsgi_application
@ -415,89 +413,88 @@ os.environ['DJANGO_SETTINGS_MODULE'] = os.getenv(
) )
application = get_wsgi_application()\n") port))))) application = get_wsgi_application()\n") port)))))
(replace 'check (replace 'check
(lambda* (#:key tests? #:allow-other-keys) (lambda* (#:key tests? #:allow-other-keys)
(when tests? (when tests?
(setenv "DJANGO_SETTINGS_MODULE" "patchwork.settings.dev") (setenv "DJANGO_SETTINGS_MODULE" "patchwork.settings.dev")
(invoke "python" "-Wonce" "./manage.py" "test" "--noinput")) (invoke "python" "-Wonce" "./manage.py" "test" "--noinput"))))
#t)) (replace 'install
(replace 'install (lambda* (#:key inputs outputs #:allow-other-keys)
(lambda* (#:key inputs outputs #:allow-other-keys) (let ((out (assoc-ref outputs "out"))
(let ((out (assoc-ref outputs "out")) (out-site-packages (site-packages inputs outputs)))
(out-site-packages (site-packages inputs outputs))) (for-each (lambda (directory)
(for-each (lambda (directory) (copy-recursively directory
(copy-recursively (string-append out-site-packages
directory "/" directory)))
(string-append out-site-packages "/" directory))) '( ;Contains the python code
'(;; Contains the python code "patchwork"
"patchwork" ;; Contains the templates for the generated HTML
;; Contains the templates for the generated HTML "templates"))
"templates")) (delete-file-recursively (string-append out-site-packages
(delete-file-recursively "/patchwork/tests"))
(string-append out-site-packages "/patchwork/tests"))
;; Install patchwork related tools ;; Install patchwork related tools
(for-each (lambda (file) (for-each (lambda (file)
(install-file file (string-append out "/bin"))) (install-file file
(list (string-append out "/bin")))
(string-append out-site-packages (list (string-append out-site-packages
"/patchwork/bin/parsemail.sh") "/patchwork/bin/parsemail.sh")
(string-append out-site-packages (string-append out-site-packages
"/patchwork/bin/parsemail-batch.sh"))) "/patchwork/bin/parsemail-batch.sh")))
;; Collect the static assets, this includes JavaScript, CSS and ;; Collect the static assets, this includes JavaScript, CSS and
;; fonts. This is a standard Django process when running a ;; fonts. This is a standard Django process when running a
;; Django application for regular use, and includes assets for ;; Django application for regular use, and includes assets for
;; dependencies like the admin site from Django. ;; dependencies like the admin site from Django.
;; ;;
;; The intent here is that you can serve files from this ;; The intent here is that you can serve files from this
;; directory through a webserver, which is recommended when ;; directory through a webserver, which is recommended when
;; running Django applications. ;; running Django applications.
(let ((static-root (let ((static-root (string-append out
(string-append out "/share/patchwork/htdocs"))) "/share/patchwork/htdocs")))
(mkdir-p static-root) (mkdir-p static-root)
(copy-file "patchwork/settings/production.example.py" (copy-file "patchwork/settings/production.example.py"
"patchwork/settings/assets.py") "patchwork/settings/assets.py")
(setenv "DJANGO_SECRET_KEY" "dummyvalue") (setenv "DJANGO_SECRET_KEY" "dummyvalue")
(setenv "DJANGO_SETTINGS_MODULE" "patchwork.settings.assets") (setenv "DJANGO_SETTINGS_MODULE" "patchwork.settings.assets")
(setenv "STATIC_ROOT" static-root) (setenv "STATIC_ROOT" static-root)
(invoke "./manage.py" "collectstatic" "--no-input")) (invoke "./manage.py" "collectstatic" "--no-input"))
;; The lib directory includes example configuration files that ;; The lib directory includes example configuration files that
;; may be useful when deploying patchwork. ;; may be useful when deploying patchwork.
(copy-recursively "lib" (copy-recursively "lib"
(string-append (string-append out "/share/doc/"
out "/share/doc/" ,name "-" ,version))) #$name "-"
#t)) #$version)))))
;; The hasher script is used from the post-receive.hook ;; The hasher script is used from the post-receive.hook
(add-after 'install 'install-hasher (add-after 'install 'install-hasher
(lambda* (#:key inputs outputs #:allow-other-keys) (lambda* (#:key inputs outputs #:allow-other-keys)
(let* ((out (assoc-ref outputs "out")) (let* ((out (assoc-ref outputs "out"))
(out-site-packages (site-packages inputs outputs)) (out-site-packages (site-packages inputs outputs))
(out-hasher.py (string-append out-site-packages (out-hasher.py (string-append out-site-packages
"/patchwork/hasher.py"))) "/patchwork/hasher.py")))
(chmod out-hasher.py #o555) (chmod out-hasher.py #o555)
(symlink out-hasher.py (string-append out "/bin/hasher"))) (symlink out-hasher.py
#t)) (string-append out "/bin/hasher")))))
;; Create a patchwork specific version of Django's command line admin ;; Create a patchwork specific version of Django's command line admin
;; utility. ;; utility.
(add-after 'install 'install-patchwork-admin (add-after 'install 'install-patchwork-admin
(lambda* (#:key inputs outputs #:allow-other-keys) (lambda _
(let* ((out (assoc-ref outputs "out"))) (mkdir-p (string-append #$output "/bin"))
(mkdir-p (string-append out "/bin")) (call-with-output-file (string-append #$output
(call-with-output-file (string-append out "/bin/patchwork-admin") "/bin/patchwork-admin")
(lambda (port) (lambda (port)
(simple-format port "#!~A (simple-format port "#!~A
import os, sys import os, sys
if __name__ == \"__main__\": if __name__ == \"__main__\":
from django.core.management import execute_from_command_line from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)" (which "python")))) execute_from_command_line(sys.argv)" (which "python"))))
(chmod (string-append out "/bin/patchwork-admin") #o555)) (chmod (string-append #$output "/bin/patchwork-admin")
#t))))) #o555))))))
(inputs (native-inputs (list python-setuptools))
(list python-wrapper)) (inputs (list python-wrapper))
(propagated-inputs (propagated-inputs
(list python-django (list python-django
;; TODO: Make this configurable ;; TODO: Make this configurable