From patchwork Fri May 3 19:30:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Christopher Baines X-Patchwork-Id: 13889 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 4C9C916F58; Fri, 3 May 2019 20:32:10 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,UNPARSEABLE_RELAY, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTP id 3FBA416F4D for ; Fri, 3 May 2019 20:32:08 +0100 (BST) Received: from localhost ([127.0.0.1]:46446 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMduh-0007cD-RS for patchwork@mira.cbaines.net; Fri, 03 May 2019 15:32:07 -0400 Received: from eggs.gnu.org ([209.51.188.92]:60872) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMdue-0007ay-Fi for guix-patches@gnu.org; Fri, 03 May 2019 15:32:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hMduc-0001GR-PX for guix-patches@gnu.org; Fri, 03 May 2019 15:32:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:36171) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hMduc-0001GJ-M1 for guix-patches@gnu.org; Fri, 03 May 2019 15:32:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hMduc-0002wu-HO for guix-patches@gnu.org; Fri, 03 May 2019 15:32:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#33185] [PATCH 2/3] gnu: Add patchwork. Resent-From: Christopher Baines Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 03 May 2019 19:32:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 33185 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 33185@debbugs.gnu.org Received: via spool by 33185-submit@debbugs.gnu.org id=B33185.155691186511237 (code B ref 33185); Fri, 03 May 2019 19:32:02 +0000 Received: (at 33185) by debbugs.gnu.org; 3 May 2019 19:31:05 +0000 Received: from localhost ([127.0.0.1]:49708 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hMdtU-0002uQ-Sc for submit@debbugs.gnu.org; Fri, 03 May 2019 15:31:02 -0400 Received: from mira.cbaines.net ([212.71.252.8]:58914) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hMdtH-0002tm-3q for 33185@debbugs.gnu.org; Fri, 03 May 2019 15:30:42 -0400 Received: from localhost (cpc102582-walt20-2-0-cust14.13-2.cable.virginm.net [86.27.34.15]) by mira.cbaines.net (Postfix) with ESMTPSA id CCE5516F53 for <33185@debbugs.gnu.org>; Fri, 3 May 2019 20:30:37 +0100 (BST) Received: from localhost (localhost [local]) by localhost (OpenSMTPD) with ESMTPA id c4d969d9 for <33185@debbugs.gnu.org>; Fri, 3 May 2019 19:30:37 +0000 (UTC) From: Christopher Baines Date: Fri, 3 May 2019 20:30:36 +0100 Message-Id: <20190503193037.27035-2-mail@cbaines.net> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190503193037.27035-1-mail@cbaines.net> References: <87o94jqrff.fsf@cbaines.net> <20190503193037.27035-1-mail@cbaines.net> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * gnu/packages/patchutils.scm (patchwork): New variable. --- gnu/packages/patchutils.scm | 167 ++++++++++++++++++++++++++++++++++++ 1 file changed, 167 insertions(+) diff --git a/gnu/packages/patchutils.scm b/gnu/packages/patchutils.scm index f6197b98ee..687864c008 100644 --- a/gnu/packages/patchutils.scm +++ b/gnu/packages/patchutils.scm @@ -2,6 +2,7 @@ ;;; Copyright © 2014, 2018 Eric Bavier ;;; Copyright © 2015, 2018 Leo Famulari ;;; Copyright © 2018, 2019 Tobias Geerinckx-Rice +;;; Copyright © 2019 Christopher Baines ;;; ;;; This file is part of GNU Guix. ;;; @@ -31,6 +32,8 @@ #:use-module (gnu packages base) #:use-module (gnu packages bash) #:use-module (gnu packages check) + #:use-module (gnu packages databases) + #:use-module (gnu packages django) #:use-module (gnu packages file) #:use-module (gnu packages gawk) #:use-module (gnu packages gettext) @@ -300,3 +303,167 @@ directories, and has support for many popular version control systems. Meld helps you review code changes and understand patches. It might even help you to figure out what is going on in that merge you keep avoiding.") (license gpl2))) + +(define-public patchwork + (package + (name "patchwork") + (version "2.1.2") + (source (origin + (method git-fetch) + (uri (git-reference + (url "https://github.com/getpatchwork/patchwork.git") + (commit (string-append "v" version)))) + (file-name (git-file-name name version)) + (sha256 + (base32 + "06ng5pv6744w98zkyfm0ldkmpdgnsql3gbbbh6awq61sr2ndr3qw")))) + (build-system python-build-system) + (arguments + `(;; TODO: Tests require a running database + #:tests? #f + #:phases + (modify-phases %standard-phases + (delete 'configure) + (delete 'build) + (add-after 'unpack 'replace-wsgi.py + (lambda* (#:key inputs outputs #:allow-other-keys) + (delete-file "patchwork/wsgi.py") + (call-with-output-file "patchwork/wsgi.py" + (lambda (port) + ;; Embed the PYTHONPATH containing the dependencies, as well + ;; as the python modules in this package in the wsgi.py file, + ;; as this will ensure they are available at runtime. + (define pythonpath + (string-append (getenv "PYTHONPATH") + ":" + (site-packages inputs outputs))) + (display + (string-append " +import os, sys + +sys.path.extend('" pythonpath "'.split(':')) + +from django.core.wsgi import get_wsgi_application + +# By default, assume that patchwork is running as a Guix service, which +# provides the settings as the 'guix.patchwork.settings' Python module. +# +# When using httpd, it's hard to set environment variables, so rely on the +# default set here. +os.environ['DJANGO_SETTINGS_MODULE'] = os.getenv( + 'DJANGO_SETTINGS_MODULE', + 'guix.patchwork.settings' # default +) + +application = get_wsgi_application()\n") port))))) + (replace 'check + (lambda* (#:key tests? #:allow-other-keys) + (when tests? + (setenv "DJANGO_SETTINGS_MODULE" "patchwork.settings.dev") + (invoke "python" "-Wonce" "./manage.py" "test" "--noinput")) + #t)) + (replace 'install + (lambda* (#:key inputs outputs #:allow-other-keys) + (let ((out (assoc-ref outputs "out")) + (out-site-packages (site-packages inputs outputs))) + (for-each (lambda (directory) + (copy-recursively + directory + (string-append out-site-packages directory))) + '(;; Contains the python code + "patchwork" + ;; Contains the templates for the generated HTML + "templates")) + (delete-file-recursively + (string-append out-site-packages "patchwork/tests")) + + ;; Install patchwork related tools + (for-each (lambda (file) + (install-file file (string-append out "/bin"))) + (list + (string-append out-site-packages + "patchwork/bin/pwclient") + (string-append out-site-packages + "patchwork/bin/parsemail.sh") + (string-append out-site-packages + "patchwork/bin/parsemail-batch.sh"))) + + ;; Delete the symlink to pwclient, and replace it with the + ;; actual file, as this can cause issues when serving the file + ;; from a webserver. + (let ((template-pwclient (string-append + out-site-packages + "patchwork/templates/patchwork/pwclient"))) + (delete-file template-pwclient) + (copy-file (string-append out-site-packages + "patchwork/bin/pwclient") + template-pwclient)) + + ;; Collect the static assets, this includes JavaScript, CSS and + ;; fonts. This is a standard Django process when running a + ;; Django application for regular use, and includes assets for + ;; dependencies like the admin site from Django. + ;; + ;; The intent here is that you can serve files from this + ;; directory through a webserver, which is recommended when + ;; running Django applications. + (let ((static-root + (string-append out "/share/patchwork/htdocs"))) + (mkdir-p static-root) + (copy-file "patchwork/settings/production.example.py" + "patchwork/settings/assets.py") + (setenv "DJANGO_SECRET_KEY" "dummyvalue") + (setenv "DJANGO_SETTINGS_MODULE" "patchwork.settings.assets") + (setenv "STATIC_ROOT" static-root) + (invoke "./manage.py" "collectstatic" "--no-input")) + + ;; The lib directory includes example configuration files that + ;; may be useful when deploying patchwork. + (copy-recursively "lib" + (string-append + out "/share/doc/" ,name "-" ,version))) + #t)) + ;; The hasher script is used from the post-receive.hook + (add-after 'install 'install-hasher + (lambda* (#:key inputs outputs #:allow-other-keys) + (let* ((out (assoc-ref outputs "out")) + (out-site-packages (site-packages inputs outputs)) + (out-hasher.py (string-append out-site-packages + "/patchwork/hasher.py"))) + (chmod out-hasher.py #o555) + (symlink out-hasher.py (string-append out "/bin/hasher"))) + #t)) + ;; Create a patchwork specific version of Django's command line admin + ;; utility. + (add-after 'install 'install-patchwork-admin + (lambda* (#:key inputs outputs #:allow-other-keys) + (let* ((out (assoc-ref outputs "out"))) + (mkdir-p (string-append out "/bin")) + (call-with-output-file (string-append out "/bin/patchwork-admin") + (lambda (port) + (simple-format port "#!~A +import os, sys + +if __name__ == \"__main__\": + from django.core.management import execute_from_command_line + + execute_from_command_line(sys.argv)" (which "python")))) + (chmod (string-append out "/bin/patchwork-admin") #o555)) + #t))))) + (inputs + `(("python-wrapper" ,python-wrapper))) + (propagated-inputs + `(("python-django" ,python-django) + ;; TODO: Make this configurable + ("python-psycopg2" ,python-psycopg2) + ("python-mysqlclient" ,python-mysqlclient) + ("python-django-filter" ,python-django-filter) + ("python-djangorestframework" ,python-djangorestframework) + ("python-django-debug-toolbar" ,python-django-debug-toolbar))) + (synopsis "Web based patch tracking system") + (description + "Patchwork is a patch tracking system. It takes in emails containing +patches, and displays the patches along with comments and state information. +Users can login allowing them to change the state of patches.") + (home-page "http://jk.ozlabs.org/projects/patchwork/") + (license gpl2+)))