From 4d0fa42919eb007b1fc19875fef1cb395226b891 Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Thu, 17 Nov 2022 10:16:24 +0100 Subject: move Guix packaging to a module --- guix-module-dir/koszko-org-website.scm | 103 +++++++++++++++++++++++++++++++++ guix.scm | 95 +++--------------------------- 2 files changed, 112 insertions(+), 86 deletions(-) create mode 100644 guix-module-dir/koszko-org-website.scm diff --git a/guix-module-dir/koszko-org-website.scm b/guix-module-dir/koszko-org-website.scm new file mode 100644 index 0000000..4e80037 --- /dev/null +++ b/guix-module-dir/koszko-org-website.scm @@ -0,0 +1,103 @@ +;; SPDX-License-Identifier: CC0-1.0 + +;; Copyright (C) 2022 Wojtek Kosior +;; +;; Available under the terms of Creative Commons Zero v1.0 Universal. + +(define-module (koszko-org-website)) + +(use-modules + (ice-9 rdelim) + (ice-9 regex)) + +(define %source-dir + (let* ((this-file (search-path %load-path "koszko-org-website.scm")) + (proj-dir (dirname (dirname this-file)))) + (if (absolute-file-name? proj-dir) + proj-dir + (string-append (getcwd) "/" proj-dir)))) + +;; The PKG-INFO file is generated when running `python3 -m build -s` or similar. +;; It is also automatically included in the source release tarballs. +(define %pkg-info-path + (string-append %source-dir "/src/koszko_org_website.egg-info/PKG-INFO")) + +(define %website-version + (if (access? %pkg-info-path R_OK) + (call-with-input-file %pkg-info-path + (lambda (port) + (let ((process-line + (lambda (self-ref) + (let ((match-result + (string-match "^Version: (.*)" (read-line port)))) + (if match-result (match:substring match-result 1) + (self-ref self-ref)))))) + (process-line process-line)))) + "unknown")) + +(define source-tarball-name + (string-append "koszko_org_website-" %website-version ".tar.gz")) + +(use-modules + (guix packages) + (guix gexp) + (guix build-system python) + ((guix licenses) #:prefix license:) + (gnu packages python-build) + (gnu packages python-web) + (gnu packages python-xyz) + (gnu packages python-check)) + +(define-public koszko-org-website + (package + (name "koszko-org-website") + (version %website-version) + (source + ;; setuptools_scm makes it impossible to build directly from git + ;; 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)))))) + (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/koszko-org-website"))) + (mkdir-p share-dir) + (copy-file "wsgi.py" (string-append share-dir "/wsgi.py")))))))) + (propagated-inputs + (list python-flask)) + (native-inputs + (list python-setuptools-scm + python-babel + python-pypa-build + python-mypy)) + (home-page "https://git.koszko.org/koszko-org-website") + (synopsis "koszko.org website") + (description "This is the packaging of the website at https://koszko.org.") + (license (list license:cc0 + license:cc-by3.0 + (license:non-copyleft + "file://LICENSES/LicenseRef-Yahoo-BSD-3.txt") + (license:x11-style + "file://LICENSES/LicenseRef-Normalize-CSS-MIT.txt") + (license:fsdg-compatible + "file://LICENSES/LicenseRef-no-facebook.txt"))))) diff --git a/guix.scm b/guix.scm index 7277e95..1c2e034 100644 --- a/guix.scm +++ b/guix.scm @@ -4,92 +4,15 @@ ;; ;; Available under the terms of Creative Commons Zero v1.0 Universal. -;; This file is based on `hydrilla-guix/hydrilla.scm` from Hydrilla&Haketilo -;; repository at ../pydrilla. +;; We need the actual website package to be defined in a module so that the +;; parent repository can more easily use it with `guix system`. Hence, the bulk +;; of Guile code resides in `guix-modules/hydrilla.scm` and this file is just a +;; thin wrapper around that. -(use-modules - (ice-9 rdelim) - (ice-9 regex)) +(add-to-load-path (string-append + (dirname (current-filename)) + "/guix-module-dir")) -;; We're mostly running from Makefile, so it's pretty safe to use `getcwd`. -(define %source-dir (getcwd)) +(use-modules (koszko-org-website)) -;; The PKG-INFO file is generated when running `python3 -m build -s` or similar. -;; It is also automatically included in the source release tarballs. -(define %website-version - (if (access? "src/koszko_org_website.egg-info/PKG-INFO" R_OK) - (let* ((port (open-input-file "src/koszko_org_website.egg-info/PKG-INFO")) - (process-line - (lambda (self-ref) - (let ((match-result - (string-match "^Version: (.*)" (read-line port)))) - (if match-result (match:substring match-result 1) - (self-ref self-ref)))))) - (process-line process-line)) - "unknown")) - -(define source-tarball-name - (string-append "koszko_org_website-" %website-version ".tar.gz")) - -(use-modules - (guix packages) - (guix gexp) - (guix build-system python) - ((guix licenses) #:prefix license:) - (gnu packages python-build) - (gnu packages python-web) - (gnu packages python-xyz) - (gnu packages python-check)) - -(package - (name "koszko-org-website") - (version %website-version) - (source - ;; setuptools_scm makes it impossible to build directly from git - ;; 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)))))) - (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/koszko-org-website"))) - (mkdir-p share-dir) - (copy-file "wsgi.py" (string-append share-dir "/wsgi.py")))))))) - (propagated-inputs - (list python-flask)) - (native-inputs - (list python-setuptools-scm - python-babel - python-pypa-build - python-mypy)) - (home-page "https://git.koszko.org/koszko-org-website") - (synopsis "koszko.org website") - (description "This is the packaging of the website at https://koszko.org.") - (license (list license:cc0 - license:cc-by3.0 - (license:non-copyleft - "file://LICENSES/LicenseRef-Yahoo-BSD-3.txt") - (license:x11-style - "file://LICENSES/LicenseRef-Normalize-CSS-MIT.txt") - (license:fsdg-compatible - "file://LICENSES/LicenseRef-no-facebook.txt")))) +koszko-org-website -- cgit v1.2.3