Subject: [bug#33185] [PATCH 6/7] gnu: Add patchwork.

From: [email-masked] (Ludovic Courtès)
Date: Mon, 19 Nov 2018 17:37:43 +0100

Christopher Baines <[email-masked]> skribis:

> ---
>  gnu/packages/patchutils.scm | 103 ++++++++++++++++++++++++++++++++++++
>  1 file changed, 103 insertions(+)

[...]

> +         (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)))))

IMO these phases would be less intimidating with a few comments
explaining what’s going on.  :-)

> +    (synopsis "")
> +    (description "")
> +    (home-page "")
> +    (license "")))

As swedebugia noted, you’re missing a few things here and in the commit
log. :-)

With these things fixed it should be good!

Thanks,
Ludo’.