From patchwork Sun Nov 4 14:38:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Baines X-Patchwork-Id: 94 Return-Path: List-Id: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id E6A64167A8; Sun, 4 Nov 2018 14:38:27 +0000 (GMT) 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 localhost (unknown [185.80.85.115]) by mira.cbaines.net (Postfix) with ESMTPSA id AD17D16753 for ; Sun, 4 Nov 2018 14:38:27 +0000 (GMT) Received: from localhost (localhost [local]) by localhost (OpenSMTPD) with ESMTPA id ea44036f for ; Sun, 4 Nov 2018 14:38:27 +0000 (UTC) From: Christopher Baines To: guix-patchwork-test@mira.cbaines.net Subject: [PATCH v2 1/7] gnu: Add python-jsmin. Date: Sun, 4 Nov 2018 14:38:21 +0000 Message-Id: <20181104143827.21553-2-mail@cbaines.net> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181104143827.21553-1-mail@cbaines.net> References: <20181104143827.21553-1-mail@cbaines.net> X-getmail-retrieved-from-mailbox: Patches * gnu/packages/python-web.scm (python-jsmin, python2-jsmin): New variables. --- gnu/packages/python-web.scm | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/gnu/packages/python-web.scm b/gnu/packages/python-web.scm index eda796e01..3671454c2 100644 --- a/gnu/packages/python-web.scm +++ b/gnu/packages/python-web.scm @@ -2168,6 +2168,28 @@ It comes with safe defaults and easily configurable options.") (define-public python2-flask-htmlmin (package-with-python2 python-flask-htmlmin)) +(define-public python-jsmin + (package + (name "python-jsmin") + (version "2.2.2") + (source + (origin + (method url-fetch) + (uri (pypi-uri "jsmin" version)) + (sha256 + (base32 + "0fsmqbjvpxvff0984x7c0y8xmf49ax9mncz48b9xjx8wrnr9kpxn")))) + (build-system python-build-system) + (home-page "https://github.com/tikitu/jsmin/") + (synopsis "Python JavaScript minifier") + (description + "@code{jsmin} is a JavaScript minifier, usable from both Python code and +on the command line.") + (license license:expat))) + +(define-public python2-jsmin + (package-with-python2 python-jsmin)) + (define-public python-flask-login (package (name "python-flask-login") From patchwork Sun Nov 4 14:38:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Baines X-Patchwork-Id: 95 Return-Path: List-Id: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id F108D167A7; Sun, 4 Nov 2018 14:38:27 +0000 (GMT) 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 localhost (unknown [185.80.85.115]) by mira.cbaines.net (Postfix) with ESMTPSA id BD2AA167A1 for ; Sun, 4 Nov 2018 14:38:27 +0000 (GMT) Received: from localhost (localhost [local]) by localhost (OpenSMTPD) with ESMTPA id cc539f4e for ; Sun, 4 Nov 2018 14:38:27 +0000 (UTC) From: Christopher Baines To: guix-patchwork-test@mira.cbaines.net Subject: [PATCH v2 2/7] gnu: Add python-slimit. Date: Sun, 4 Nov 2018 14:38:22 +0000 Message-Id: <20181104143827.21553-3-mail@cbaines.net> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181104143827.21553-1-mail@cbaines.net> References: <20181104143827.21553-1-mail@cbaines.net> X-getmail-retrieved-from-mailbox: Patches * gnu/packages/python-web.scm (python-slimit, python2-slimit): New variables. --- gnu/packages/python-web.scm | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/gnu/packages/python-web.scm b/gnu/packages/python-web.scm index 3671454c2..26134e808 100644 --- a/gnu/packages/python-web.scm +++ b/gnu/packages/python-web.scm @@ -1983,6 +1983,34 @@ transfers.") `(("python2-futures" ,python2-futures) ,@(package-native-inputs base)))))) +(define-public python-slimit + (package + (name "python-slimit") + (version "0.8.1") + (source + (origin + (method url-fetch) + (uri (pypi-uri "slimit" version ".zip")) + (sha256 + (base32 + "02vj2x728rs1127q2nc27frrqra4fczivnb7gch6n5lzi7pxqczl")))) + (build-system python-build-system) + (native-inputs + `(("unzip" ,unzip))) + (propagated-inputs + `(("python-ply" ,python-ply))) + (home-page "https://slimit.readthedocs.io/") + (synopsis "JavaScript minifier, parser and lexer written in Python") + (description + "@code{SlimIt} is a JavaScript minifier written in Python. It compiles +JavaScript into more compact code so that it downloads and runs faster. +SlimIt also provides a library that includes a JavaScript parser, lexer, +pretty printer and a tree visitor.") + (license license:expat))) + +(define-public python2-slimit + (package-with-python2 python-slimit)) + (define-public python-flask-restful (package (name "python-flask-restful") From patchwork Sun Nov 4 14:38:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Baines X-Patchwork-Id: 96 Return-Path: List-Id: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 31006167A9; Sun, 4 Nov 2018 14:38:28 +0000 (GMT) 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 localhost (unknown [185.80.85.115]) by mira.cbaines.net (Postfix) with ESMTPSA id CBE7C167A6 for ; Sun, 4 Nov 2018 14:38:27 +0000 (GMT) Received: from localhost (localhost [local]) by localhost (OpenSMTPD) with ESMTPA id 71a0b758 for ; Sun, 4 Nov 2018 14:38:27 +0000 (UTC) From: Christopher Baines To: guix-patchwork-test@mira.cbaines.net Subject: [PATCH v2 3/7] gnu: Add python-django-pipeline. Date: Sun, 4 Nov 2018 14:38:23 +0000 Message-Id: <20181104143827.21553-4-mail@cbaines.net> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181104143827.21553-1-mail@cbaines.net> References: <20181104143827.21553-1-mail@cbaines.net> X-getmail-retrieved-from-mailbox: Patches * gnu/packages/django.scm (python-django-pipeline, python2-django-pipeline): New variables. --- gnu/packages/django.scm | 43 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/gnu/packages/django.scm b/gnu/packages/django.scm index dea925e56..589ba282e 100644 --- a/gnu/packages/django.scm +++ b/gnu/packages/django.scm @@ -518,6 +518,49 @@ project.") (define-public python2-django-overextends (package-with-python2 python-django-overextends)) +(define-public python-django-pipeline + (package + (name "python-django-pipeline") + (version "1.6.14") + (source + (origin + (method url-fetch) + (uri (pypi-uri "django-pipeline" version)) + (sha256 + (base32 + "1a207y71r7za033ira0qmh2yrgp5rq0l04gw2fg9b8jri7sslrzg")))) + (build-system python-build-system) + (arguments + '(#:phases + (modify-phases %standard-phases + (add-after 'unpack 'patch-source + (lambda _ + (substitute* "tests/tests/test_compiler.py" + (("\\/usr\\/bin\\/env") + (which "env"))))) + (replace 'check + (lambda*(#:key tests? #:allow-other-keys) + (or + (not tests?) + (begin + (setenv "DJANGO_SETTINGS_MODULE" "tests.settings") + (invoke "django-admin" "test" "tests")))))))) + (propagated-inputs + `(("python-django" ,python-django) + ("python-slimit" ,python-slimit) + ("python-jsmin" ,python-jsmin))) + (home-page + "https://github.com/jazzband/django-pipeline") + (synopsis "Asset packaging library for Django") + (description + "Pipeline is an asset packaging library for Django, providing both CSS +and JavaScript concatenation and compression, built-in JavaScript template +support, and optional data-URI image and font embedding.") + (license license:expat))) + +(define-public python2-django-pipeline + (package-with-python2 python-django-pipeline)) + (define-public python-django-redis (package (name "python-django-redis") From patchwork Sun Nov 4 14:38:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Baines X-Patchwork-Id: 97 Return-Path: List-Id: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 61487167A8; Sun, 4 Nov 2018 14:38:28 +0000 (GMT) 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 localhost (unknown [185.80.85.115]) by mira.cbaines.net (Postfix) with ESMTPSA id DBFF11666B for ; Sun, 4 Nov 2018 14:38:27 +0000 (GMT) Received: from localhost (localhost [local]) by localhost (OpenSMTPD) with ESMTPA id 1a5823e8 for ; Sun, 4 Nov 2018 14:38:27 +0000 (UTC) From: Christopher Baines To: guix-patchwork-test@mira.cbaines.net Subject: [PATCH v2 4/7] gnu: Add python-django-jinja. Date: Sun, 4 Nov 2018 14:38:24 +0000 Message-Id: <20181104143827.21553-5-mail@cbaines.net> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181104143827.21553-1-mail@cbaines.net> References: <20181104143827.21553-1-mail@cbaines.net> X-getmail-retrieved-from-mailbox: Patches * gnu/packages/django.scm (python-django-jinja, python2-django-jinja): New variables. --- gnu/packages/django.scm | 49 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/gnu/packages/django.scm b/gnu/packages/django.scm index 589ba282e..48f36835d 100644 --- a/gnu/packages/django.scm +++ b/gnu/packages/django.scm @@ -338,6 +338,55 @@ merging, minifying and compiling CSS and Javascript files.") (define-public python2-django-assets (package-with-python2 python-django-assets)) +(define-public python-django-jinja + (package + (name "python-django-jinja") + (version "2.4.1") + (source + (origin + (method url-fetch) + (uri (string-append + "https://github.com/niwinz/django-jinja/archive/" + version ".tar.gz")) + (file-name (string-append name "-" version ".tar.gz")) + (sha256 + (base32 + "0bzrb4m6wx9ph5cpvz7wpvg5k6ksvj0dnxlg0nhhqskhvp46brs1")))) + (build-system python-build-system) + (propagated-inputs + `(("python-django" ,python-django) + ("python-jinja2" ,python-jinja2) + ("python-pytz" ,python-pytz) + ("python-django-pipeline" ,python-django-pipeline))) + (arguments + '(;; TODO Tests currently fail due to issues with the configuration for + ;; django-pipeline + #:tests? #f + #:phases + (modify-phases %standard-phases + (replace 'check + (lambda* (#:key tests? #:allow-other-keys) + (or + (not tests?) + (with-directory-excursion "testing" + (invoke "python" "runtests.py")))))))) + (home-page + "https://niwinz.github.io/django-jinja/latest/") + (synopsis "Simple and nonobstructive jinja2 backend for Django") + (description + "Jinja2 provides certain advantages over the native system of Django, for +example, explicit calls to callable from templates and better performance. +@code{django-jinja} is a alternative to the jinja2 backend built in to Django.") + (license license:bsd-3))) + +(define-public python2-django-jinja + (let ((base (package-with-python2 (strip-python2-variant python-django-jinja)))) + (package + (inherit base) + (native-inputs + `(("python2-mock" ,python2-mock) + ,@(package-native-inputs base)))))) + (define-public python-django-jsonfield (package (name "python-django-jsonfield") From patchwork Sun Nov 4 14:38:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Baines X-Patchwork-Id: 100 Return-Path: List-Id: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 22095167A1; Sun, 4 Nov 2018 14:38:29 +0000 (GMT) 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 localhost (unknown [185.80.85.115]) by mira.cbaines.net (Postfix) with ESMTPSA id 044D116753 for ; Sun, 4 Nov 2018 14:38:28 +0000 (GMT) Received: from localhost (localhost [local]) by localhost (OpenSMTPD) with ESMTPA id ca7f3bd5 for ; Sun, 4 Nov 2018 14:38:27 +0000 (UTC) From: Christopher Baines To: guix-patchwork-test@mira.cbaines.net Subject: [PATCH v2 5/7] gnu: Add python-django-debug-toolbar. Date: Sun, 4 Nov 2018 14:38:25 +0000 Message-Id: <20181104143827.21553-6-mail@cbaines.net> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181104143827.21553-1-mail@cbaines.net> References: <20181104143827.21553-1-mail@cbaines.net> X-getmail-retrieved-from-mailbox: Patches * gnu/packages/django.scm (python-django-debug-toolbar, python2-django-debug-toolbar): New variables. --- gnu/packages/django.scm | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/gnu/packages/django.scm b/gnu/packages/django.scm index 48f36835d..3a761bf60 100644 --- a/gnu/packages/django.scm +++ b/gnu/packages/django.scm @@ -265,6 +265,44 @@ account authentication.") (define-public python2-django-allauth (package-with-python2 python-django-allauth)) +(define-public python-django-debug-toolbar + (package + (name "python-django-debug-toolbar") + (version "1.10.1") + (source + (origin + (method url-fetch) + (uri (string-append + "https://github.com/jazzband/django-debug-toolbar/archive/" + version ".tar.gz")) + (file-name (string-append name "-" version ".tar.gz")) + (sha256 + (base32 + "1rww056hyzks8spbgf4h7kf6ybxlc5p08a2b6gn1nqrrzs4yx9sy")))) + (build-system python-build-system) + (propagated-inputs + `(("python-sqlparse" ,python-sqlparse) + ("python-django" ,python-django))) + (native-inputs + `(("python-django-jinja" ,python-django-jinja) + ("python-html5lib" ,python-html5lib))) + (arguments + '(#:phases + (modify-phases %standard-phases + (replace 'check + (lambda _ + (invoke "make" "test")))))) + (home-page + "https://github.com/jazzband/django-debug-toolbar") + (synopsis "Toolbar to help with developing Django applications") + (description + "A configurable set of panels that display various debug information +about the current request/response.") + (license license:bsd-3))) + +(define-public python2-django-debug-toolbar + (package-with-python2 python-django-debug-toolbar)) + (define-public python-django-gravatar2 (package (name "python-django-gravatar2") From patchwork Sun Nov 4 14:38:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Baines X-Patchwork-Id: 98 Return-Path: List-Id: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 904D3167A6; Sun, 4 Nov 2018 14:38:28 +0000 (GMT) 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 localhost (unknown [185.80.85.115]) by mira.cbaines.net (Postfix) with ESMTPSA id 15496167A1 for ; Sun, 4 Nov 2018 14:38:28 +0000 (GMT) Received: from localhost (localhost [local]) by localhost (OpenSMTPD) with ESMTPA id 6addf9dc for ; Sun, 4 Nov 2018 14:38:27 +0000 (UTC) From: Christopher Baines To: guix-patchwork-test@mira.cbaines.net Subject: [PATCH v2 6/7] gnu: Add patchwork. Date: Sun, 4 Nov 2018 14:38:26 +0000 Message-Id: <20181104143827.21553-7-mail@cbaines.net> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181104143827.21553-1-mail@cbaines.net> References: <20181104143827.21553-1-mail@cbaines.net> X-getmail-retrieved-from-mailbox: Patches --- gnu/packages/patchutils.scm | 103 ++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/gnu/packages/patchutils.scm b/gnu/packages/patchutils.scm index 688e62cdc..0981cbc08 100644 --- a/gnu/packages/patchutils.scm +++ b/gnu/packages/patchutils.scm @@ -29,6 +29,8 @@ #:use-module (gnu packages ed) #:use-module (gnu packages base) #:use-module (gnu packages bash) + #: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) @@ -240,3 +242,104 @@ hexadecimal and ASCII (or EBCDIC). It can also display two files at once, and highlight the differences between them. It works well with large files (up to 4 GiB).") (license gpl2+))) + +(define-public patchwork + (package + (name "patchwork") + (version "2.1.1") + (source (origin + (method url-fetch) + (uri (string-append + "https://github.com/getpatchwork/patchwork/archive/v" + version ".tar.gz")) + (sha256 + (base32 + "1q4i46gwwxvr8gjj983r8aacfsssp062dzi29ha7zba380fsxayy")) + (file-name (string-append name "-" version)))) + (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 'patch-wsgi.py + (lambda* (#:key inputs outputs #:allow-other-keys) + (substitute* "patchwork/wsgi.py" + (("import os") + (string-append + "import os, sys + +sys.path.extend('" (string-append (getenv "PYTHONPATH") ":" (site-packages inputs outputs)) "'.split(':'))")) + (("'patchwork\\.settings\\.production'") + "os.getenv('DJANGO_SETTINGS_MODULE', 'guix.patchwork.settings')")))) + (replace 'check + (lambda* (#:key tests? #:allow-other-keys) + (or (not tests?) + (begin + (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"))) + (for-each (lambda (directory) + (copy-recursively + directory + (string-append (site-packages inputs outputs) + "/" directory))) + '("patchwork" + "templates")) + (delete-file-recursively (string-append + (site-packages inputs outputs) + "patchwork/tests")) + (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")) + + (copy-recursively "lib" + (string-append + out "/share/doc/" ,name "-" ,version))) + #t)) + (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) + (display "#!/usr/bin/env python3 +import os, sys + +if __name__ == \"__main__\": + os.environ.setdefault( + \"DJANGO_SETTINGS_MODULE\", + \"guix.patchwork.settings\" + ) + + from django.core.management import execute_from_command_line + + execute_from_command_line(sys.argv)" port))) + (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 "") + (description "") + (home-page "") + (license ""))) From patchwork Sun Nov 4 14:38:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Baines X-Patchwork-Id: 99 Return-Path: List-Id: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id CDEEB167A1; Sun, 4 Nov 2018 14:38:28 +0000 (GMT) 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 localhost (unknown [185.80.85.115]) by mira.cbaines.net (Postfix) with ESMTPSA id 254CC167A7 for ; Sun, 4 Nov 2018 14:38:28 +0000 (GMT) Received: from localhost (localhost [local]) by localhost (OpenSMTPD) with ESMTPA id d3642e51 for ; Sun, 4 Nov 2018 14:38:27 +0000 (UTC) From: Christopher Baines To: guix-patchwork-test@mira.cbaines.net Subject: [PATCH v2 7/7] services: Add patchwork. Date: Sun, 4 Nov 2018 14:38:27 +0000 Message-Id: <20181104143827.21553-8-mail@cbaines.net> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181104143827.21553-1-mail@cbaines.net> References: <20181104143827.21553-1-mail@cbaines.net> X-getmail-retrieved-from-mailbox: Patches --- gnu/services/web.scm | 297 ++++++++++++++++++++++++++++++++++++++++++- gnu/tests/web.scm | 104 ++++++++++++++- 2 files changed, 399 insertions(+), 2 deletions(-) diff --git a/gnu/services/web.scm b/gnu/services/web.scm index fcf453c24..41db75153 100644 --- a/gnu/services/web.scm +++ b/gnu/services/web.scm @@ -32,12 +32,16 @@ #:use-module (gnu system pam) #:use-module (gnu system shadow) #:use-module (gnu packages admin) + #:use-module (gnu packages databases) #:use-module (gnu packages web) + #:use-module (gnu packages patchutils) #:use-module (gnu packages php) + #:use-module (gnu packages python) #:use-module (gnu packages guile) #:use-module (gnu packages logging) #:use-module (guix records) #:use-module (guix modules) + #:use-module (guix utils) #:use-module (guix gexp) #:use-module ((guix store) #:select (text-file)) #:use-module ((guix utils) #:select (version-major)) @@ -210,7 +214,41 @@ varnish-configuration-parameters varnish-configuration-extra-options - varnish-service-type)) + varnish-service-type + + + patchwork-database-configuration + patchwork-database-configuration? + patchwork-database-configuration-engine + patchwork-database-configuration-name + patchwork-database-configuration-user + patchwork-database-configuration-password + patchwork-database-configuration-host + patchwork-database-configuration-port + + + patchwork-settings-module + patchwork-settings-module? + patchwork-settings-module-database-configuration + patchwork-settings-module-secret-key + patchwork-settings-module-allowed-hosts + patchwork-settings-module-default-from-email + patchwork-settings-module-static-url + patchwork-settings-module-admins + patchwork-settings-module-debug? + patchwork-settings-module-enable-rest-api? + patchwork-settings-module-enable-xmlrpc? + patchwork-settings-module-force-https-links? + patchwork-settings-module-extra-settings + + + patchwork-configuration + patchwork-configuration? + patchwork-configuration-patchwork + patchwork-configuration-settings-module + patchwork-configuration-domain + + patchwork-service-type)) ;;; Commentary: ;;; @@ -1261,3 +1299,260 @@ files.") varnish-shepherd-service))) (default-value (varnish-configuration)))) + + +;;; +;;; Patchwork +;;; + +(define-record-type* + patchwork-database-configuration make-patchwork-database-configuration + patchwork-database-configuration? + (engine patchwork-database-configuration-engine + (default "django.db.backends.postgresql_psycopg2")) + (name patchwork-database-configuration-name + (default "patchwork")) + (user patchwork-database-configuration-user + (default "")) + (password patchwork-database-configuration-password + (default "")) + (host patchwork-database-configuration-host + (default "")) + (port patchwork-database-configuration-port + (default ""))) + +(define-record-type* + patchwork-settings-module make-patchwork-settings-module + patchwork-settings-module? + (database-configuration patchwork-settings-module-database-configuration + (default (patchwork-database-configuration))) + (secret-key patchwork-settings-module-secret-key) + (allowed-hosts patchwork-settings-module-allowed-hosts) + (default-from-email patchwork-settings-module-default-from-email) + (static-url patchwork-settings-module-static-url + (default "/static/")) + (admins patchwork-settings-module-admins + (default '())) + (debug? patchwork-settings-module-debug? + (default #f)) + (enable-rest-api? patchwork-settings-module-enable-rest-api? + (default #t)) + (enable-xmlrpc? patchwork-settings-module-enable-xmlrpc? + (default #t)) + (force-https-links? patchwork-settings-module-force-https-links? + (default #t)) + (extra-settings patchwork-settings-module-extra-settings + (default ""))) + +(define-record-type* + patchwork-configuration make-patchwork-configuration + patckwork-configuration? + (patchwork patchwork-configuration-patchwork + (default patchwork)) + (settings-module patchwork-configuration-settings-module) + (domain patchwork-configuration-domain)) + +(define-gexp-compiler (patchwork-settings-module-compiler + (file ) system target) + (match file + (($ database-configuration secret-key + allowed-hosts default-from-email + static-url admins debug? enable-rest-api? + enable-xmlrpc? force-https-links? + extra-configuration) + (gexp->derivation + "patchwork-settings" + (with-imported-modules '((guix build utils)) + #~(let ((output #$output)) + (define (create-__init__.py filename) + (call-with-output-file filename + (lambda (port) (display "" port)))) + + (use-modules (guix build utils) + (srfi srfi-1)) + + (mkdir-p (string-append output "/guix/patchwork")) + (create-__init__.py + (string-append output "/guix/__init__.py")) + (create-__init__.py + (string-append output "/guix/patchwork/__init__.py")) + + (call-with-output-file + (string-append output "/guix/patchwork/settings.py") + (lambda (port) + (display + (string-append "from patchwork.settings.base import * + +# Configuration from Guix +SECRET_KEY = '" #$secret-key "' + +ALLOWED_HOSTS = [ +" #$(string-concatenate + (map (lambda (allowed-host) + (string-append " '" allowed-host "'\n")) + allowed-hosts)) +"] + +DEBUG = " #$(if debug? "True" "False") " + +ENABLE_REST_API = " #$(if enable-xmlrpc? "True" "False") " +ENABLE_XMLRPC = " #$(if enable-xmlrpc? "True" "False") " + +FORCE_HTTPS_LINKS = " #$(if force-https-links? "True" "False") " + +DATABASES = { + 'default': { +" #$(match database-configuration + (($ + engine name user password host port) + (string-append + " 'ENGINE': '" engine "',\n" + " 'NAME': '" name "',\n" + " 'USER': '" user "',\n" + " 'PASSWORD': '" password "',\n" + " 'HOST': '" host "',\n" + " 'PORT': '" port "',\n"))) " + }, +} + +" #$(if debug? + #~(string-append "STATIC_ROOT = '" #$(file-append patchwork "/share/patchwork/htdocs") "'") + #~(string-append "STATIC_URL = '" #$static-url "'")) " + +STATICFILES_STORAGE = ( + 'django.contrib.staticfiles.storage.StaticFilesStorage' +) + +# Guix Extra Configuration +" #$extra-configuration " +") port))) + #t)) + #:local-build? #t)))) + +(define (patchwork-wsgi-wrapper patchwork) + (define patchwork-wsgi.py + (file-append patchwork + (string-append + "/lib/python" + (version-major+minor + (package-version python)) + "/site-packages/patchwork/wsgi.py"))) + + (mixed-text-file + "patchwork-wsgi.py" + "import os\n" + "\n" + "exec(open(\"" patchwork-wsgi.py "\").read())\n")) + +(define patchwork-httpd-configuration + (match-lambda + (($ patchwork settings-module + domain) + + (define wsgi.py (patchwork-wsgi-wrapper patchwork)) + + (list "WSGISocketPrefix /var/run/mod_wsgi" + (list "LoadModule wsgi_module " + (file-append mod-wsgi "/modules/mod_wsgi.so")) + (httpd-virtualhost + "*:8080" + `("ServerAdmin admin@example.com +ServerName " ,domain " + +LogFormat \"%v %h %l %u %t \\\"%r\\\" %>s %b \\\"%{Referer}i\\\" \\\"%{User-Agent}i\\\"\" customformat +LogLevel info +CustomLog \"/var/log/httpd/" ,domain "-access_log\" customformat + +ErrorLog /var/log/httpd/error.log + +WSGIScriptAlias / " ,wsgi.py " +WSGIDaemonProcess patchwork user=httpd group=httpd processes=1 threads=2 display-name=%{GROUP} lang='en_US.UTF-8' locale='en_US.UTF-8' python-path=" ,settings-module " +WSGIProcessGroup patchwork +WSGIPassAuthorization On + + + Require all granted + + +Alias /static " ,patchwork "/share/patchwork/htdocs + + AllowOverride None + Options MultiViews Indexes SymlinksIfOwnerMatch IncludesNoExec + Require method GET POST OPTIONS +")))))) + +(define (patchwork-setup-gexp settings-module) + (with-imported-modules (source-module-closure + '((guix build utils))) + #~(lambda () + (catch #t + (lambda () + (let ((pid (primitive-fork)) + (user (getpwnam "postgres"))) + (if (eq? pid 0) + (dynamic-wind + (const #t) + (lambda () + (setgid (passwd:gid user)) + (setuid (passwd:uid user)) + (primitive-exit + (if (and + (zero? + (system* #$(file-append postgresql "/bin/createuser") + "httpd")) + (zero? + (system* #$(file-append postgresql "/bin/createdb") + "-O" "httpd" "patchwork"))) + 0 + 1))) + (lambda () + (primitive-exit 1))) + (zero? (cdr (waitpid pid))))) + (let ((pid (primitive-fork)) + (user (getpwnam "httpd"))) + (if (eq? pid 0) + (dynamic-wind + (const #t) + (lambda () + (setgid (passwd:gid user)) + (setuid (passwd:uid user)) + ;; TODO Extract + (setenv "DJANGO_SECRET_KEY" "testsecretkey") + (setenv "DATABASE_NAME" "patchwork") + (setenv "PYTHONPATH" #$settings-module) + (primitive-exit + (if (and + (zero? + (system* #$(file-append patchwork + "/bin/patchwork-admin") + "migrate"))) + 0 + 1))) + (lambda () + (primitive-exit 1))) + (zero? (cdr (waitpid pid)))))) + (lambda (key . parameters) + (format (current-error-port) + "Uncaught throw to '~a: ~a\n" key parameters) + #f))))) + +(define patchwork-service-type + (service-type + (name 'patchwork-setup) + (extensions + (list (service-extension httpd-service-type + patchwork-httpd-configuration) + (service-extension + shepherd-root-service-type + (match-lambda + (($ patchwork settings-module + domain) + (list (shepherd-service + (requirement '(postgres)) + (provision '(patchwork-setup)) + (start (patchwork-setup-gexp settings-module)) + (stop #~(const #f)) + (respawn? #f) + (documentation "Setup patchwork.")))))))) + (description + "patchwork"))) diff --git a/gnu/tests/web.scm b/gnu/tests/web.scm index 319655396..fbdf78a03 100644 --- a/gnu/tests/web.scm +++ b/gnu/tests/web.scm @@ -28,15 +28,27 @@ #:use-module (gnu system vm) #:use-module (gnu services) #:use-module (gnu services web) + #:use-module (gnu services databases) #:use-module (gnu services networking) + #:use-module (gnu services shepherd) + #:use-module (gnu packages databases) + #:use-module (gnu packages patchutils) + #:use-module (gnu packages python) + #:use-module (gnu packages web) + #:use-module (guix packages) + #:use-module (guix modules) + #:use-module (guix records) #:use-module (guix gexp) #:use-module (guix store) + #:use-module (guix utils) + #:use-module (ice-9 match) #:export (%test-httpd %test-nginx %test-varnish %test-php-fpm %test-hpcguix-web - %test-tailon)) + %test-tailon + %test-patchwork)) (define %index.html-contents ;; Contents of the /index.html file. @@ -498,3 +510,93 @@ HTTP-PORT." (name "tailon") (description "Connect to a running Tailon server.") (value (run-tailon-test)))) + + +;;; +;;; Patchwork +;;; + +(define %patchwork-os + (simple-operating-system + (service dhcp-client-service-type) + (service httpd-service-type + (httpd-configuration + (config + (httpd-config-file + (listen '("8080")))))) + (service postgresql-service-type) + (service patchwork-service-type + (patchwork-configuration + (settings-module + (patchwork-settings-module + (secret-key "00000") + (allowed-hosts '("*")) + (default-from-email "") + (debug? #t))) + (domain "localhost"))))) + +(define* (run-patchwork-test) + "Run tests in %NGINX-OS, which has nginx running and listening on +HTTP-PORT." + (define os + (marionette-operating-system + %patchwork-os + #:imported-modules '((gnu services herd) + (guix combinators)))) + + (define forwarded-port 8080) + + (define vm + (virtual-machine + (operating-system os) + (port-forwardings `((8080 . ,forwarded-port))))) + + (define test + (with-imported-modules '((gnu build marionette)) + #~(begin + (use-modules (srfi srfi-11) (srfi srfi-64) + (gnu build marionette) + (web uri) + (web client) + (web response)) + + (define marionette + (make-marionette (list #$vm))) + + (mkdir #$output) + (chdir #$output) + + (test-begin "patchwork") + + (test-assert "httpd service running" + (marionette-eval + '(begin + (use-modules (gnu services herd)) + (match (start-service 'httpd) + (#f #f) + (('service response-parts ...) + (match (assq-ref response-parts 'running) + ((#t) #t) + ((pid) (number? pid)))))) + marionette)) + + ;; Retrieve the index.html file we put in /srv. + (test-equal "http-get" + 200 + (let-values + (((response text) + (http-get #$(simple-format + #f "http://localhost:~A/" forwarded-port) + #:decode-body? #t))) + (response-code response))) + + (test-end) + (exit (= (test-runner-fail-count (test-runner-current)) 0))))) + + (gexp->derivation "patchwork-test" test)) + +(define %test-patchwork + (system-test + (name "patchwork") + (description "") + (value (run-patchwork-test))))