From 2b2c70932bf6ffcd77fbe5f6c59a203299f755a5 Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Wed, 23 Nov 2022 11:02:36 +0100 Subject: add WSGI script --- guix-module-dir/hydrilla-website.scm | 32 ++++++++++++++++++++++++++++++++ src/hydrilla_website/__init__.py | 2 +- wsgi.py | 16 ++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 wsgi.py diff --git a/guix-module-dir/hydrilla-website.scm b/guix-module-dir/hydrilla-website.scm index af593bf..ce76784 100644 --- a/guix-module-dir/hydrilla-website.scm +++ b/guix-module-dir/hydrilla-website.scm @@ -57,6 +57,38 @@ ;; checkout. We instead build from source tarball generated under ./dist/. (local-file (string-append %source-dir "/dist/" source-tarball-name))) (build-system python-build-system) + (arguments + `(#:phases + (modify-phases %standard-phases + (add-after 'unpack 'replace-wsgi.py + (lambda* (#:key inputs outputs #:allow-other-keys) + ;; In the wsgi.py file, embed the PYTHONPATH containing both the + ;; dependencies and the python modules of this package. This will + ;; make them available at runtime. + (let ((pythonpath + (string-append (getenv "GUIX_PYTHONPATH") + ":" + (site-packages inputs outputs)))) + (substitute* "wsgi.py" + (("^from .* import .*" import-line) + (string-append + "# Make Guix-installed dependencies visible to Python.\n" + "import sys\n" + "sys.path.extend('" pythonpath "'.split(':'))\n" + "\n" + import-line)) + (("^set_secret.*") + (string-append + "from pathlib import Path\n" + "path_to_secret = Path('/etc/hydrilla-website/secret.txt')\n" + "if path_to_secret.exists():\n" + " set_secret(path_to_secret.read_text().strip())")))))) + (add-after 'install 'install-wsgi-script + (lambda* (#:key inputs outputs #:allow-other-keys) + (let* ((out (assoc-ref outputs "out")) + (share-dir (string-append out "/share/hydrilla-website"))) + (mkdir-p share-dir) + (copy-file "wsgi.py" (string-append share-dir "/wsgi.py")))))))) (propagated-inputs (list python-flask)) (native-inputs diff --git a/src/hydrilla_website/__init__.py b/src/hydrilla_website/__init__.py index 3ac4327..f3bd4e7 100644 --- a/src/hydrilla_website/__init__.py +++ b/src/hydrilla_website/__init__.py @@ -4,4 +4,4 @@ # # Available under the terms of Creative Commons Zero v1.0 Universal. -from .app import website_app +from .app import website_app, set_secret diff --git a/wsgi.py b/wsgi.py new file mode 100644 index 0000000..d43f8e3 --- /dev/null +++ b/wsgi.py @@ -0,0 +1,16 @@ +# SPDX-License-Identifier: CC0-1.0 + +# WSGI script for Hydrilla&Haketilo website. +# +# Copyright (C) 2022 Wojtek Kosior + +# Uncomment the lines below if you want to use a virtualenv installation of +# the website package. + +#from pathlib import Path +#path = Path('/path/to/virtualenv/bin/activate_this.py') +#exec(path.read_text(), {'__file__': str(path)}) + +from hydrilla_website import website_app as application, set_secret + +set_secret('please replace this with something appropriate') -- cgit v1.2.3