diff mbox series

[bug#56803,6/6] gnu: Add hydrus-network.

Message ID 9622a5d87b172e7f9ae838da45f15eb0ba95e374.1658946720.git.tj@schwi.pl
State Accepted
Headers show
Series Add hydrus network and its dependencies | expand

Checks

Context Check Description
cbaines/comparison success View comparision
cbaines/git-branch success View Git branch
cbaines/applying patch success View Laminar job
cbaines/issue success View issue

Commit Message

Tomasz Jeneralczyk July 27, 2022, 7 p.m. UTC
Hydrus-network has a weekly release cycle and is meant to be used from its own
directory so I artificially spread it out to comply with guix's expectations.

Three binaries from inputs are copied into a directory hydrus knows about:
  * ffmpeg - works as expected
  * swftools - does not do anything neither on guix or Arch linux - possibly
  an unfinished feature, but I left it in, in case it gets fixed in a future version.
  * miniupnpc - times out on my system, but it should work otherwise.

I was not able to build the program's help files. Updating
python-pymdown-extensions to its latest version might be the solution, but
this would require also packaging its new build system that is not present in
guix yet. I decided to cut short there.

Also adds copyright and new used modules.

* gnu/packages/image-viewers.scm (hydrus-network): Add variable.
---
 gnu/packages/image-viewers.scm | 127 +++++++++++++++++++++++++++++++++
 1 file changed, 127 insertions(+)

Comments

Ludovic Courtès Aug. 9, 2022, 3:09 p.m. UTC | #1
Hi Tomasz,

Tomasz Jeneralczyk <tj@schwi.pl> skribis:

> Hydrus-network has a weekly release cycle and is meant to be used from its own
> directory so I artificially spread it out to comply with guix's expectations.
>
> Three binaries from inputs are copied into a directory hydrus knows about:
>   * ffmpeg - works as expected
>   * swftools - does not do anything neither on guix or Arch linux - possibly
>   an unfinished feature, but I left it in, in case it gets fixed in a future version.
>   * miniupnpc - times out on my system, but it should work otherwise.
>
> I was not able to build the program's help files. Updating
> python-pymdown-extensions to its latest version might be the solution, but
> this would require also packaging its new build system that is not present in
> guix yet. I decided to cut short there.

Perhaps these comments, or some of them, should go as comments in the
source?  That will prove helpful next time you or someone else tries to
work on the package.

> +      (with-imported-modules '((guix build utils))

This is unnecessary as (guix build utils) is always present on the build
side.

> +              (replace 'install
> +                (lambda* (#:key outputs inputs #:allow-other-keys)
> +                  (let* ((out (assoc-ref outputs "out"))
> +                         (python (assoc-ref inputs "python"))
> +                         (client-path (string-append out "/bin/hydrus"))
> +                         (server-path (string-append out "/bin/hydrus-server")))

Nitpick: GNU and Guix convention is to use the term “path” to denote a
search path (like $PATH, etc.) and to use “file name” (or “file”) to
denote a file name, as is the case here.

In this case it might be enough to write ‘client’ instead of
‘client-path’, and similarly for ‘server-path’.

> +              ;; Hydrus searches for some binaries at bin-dir so it's important
> +              ;; to put them there so it can find and use them.

In general, the solution here, rather than copy files like the ‘ffmpeg’
executable, would be to patch Hydrus so that it contains the absolute
file name of ‘ffmpeg’ as returned by (search-input-file inputs "/bin/ffmpeg").

How does that sound?

Thanks,
Ludo’.
diff mbox series

Patch

diff --git a/gnu/packages/image-viewers.scm b/gnu/packages/image-viewers.scm
index 8d4d2351c3..9574384761 100644
--- a/gnu/packages/image-viewers.scm
+++ b/gnu/packages/image-viewers.scm
@@ -24,6 +24,7 @@ 
 ;;; Copyright © 2021 Zheng Junjie <873216071@qq.com>
 ;;; Copyright © 2021 dissent <disseminatedissent@protonmail.com>
 ;;; Copyright © 2022 Michael Rohleder <mike@rohleder.de>
+;;; Copyright © 2022 Tomasz Jeneralczyk <tj@schwi.pl>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -54,6 +55,7 @@  (define-module (gnu packages image-viewers)
   #:use-module (guix build-system qt)
   #:use-module (gnu packages autotools)
   #:use-module (gnu packages algebra)
+  #:use-module (gnu packages animation)
   #:use-module (gnu packages backup)
   #:use-module (gnu packages base)
   #:use-module (gnu packages bash)
@@ -84,14 +86,20 @@  (define-module (gnu packages image-viewers)
   #:use-module (gnu packages photo)
   #:use-module (gnu packages pkg-config)
   #:use-module (gnu packages python)
+  #:use-module (gnu packages python-check)
+  #:use-module (gnu packages python-compression)
+  #:use-module (gnu packages python-crypto)
+  #:use-module (gnu packages python-web)
   #:use-module (gnu packages python-xyz)
   #:use-module (gnu packages qt)
   #:use-module (gnu packages suckless)
   #:use-module (gnu packages terminals)
+  #:use-module (gnu packages upnp)
   #:use-module (gnu packages version-control)
   #:use-module (gnu packages video)
   #:use-module (gnu packages web)
   #:use-module (gnu packages xdisorg)
+  #:use-module (gnu packages xml)
   #:use-module (gnu packages xorg)
   #:use-module (gnu packages))
 
@@ -973,3 +981,122 @@  (define-public xzgv
     (description
      "xzgv is a fast image viewer that provides extensive keyboard support.")
     (license license:gpl2+)))
+
+(define-public hydrus-network
+  (package
+    (name "hydrus-network")
+    (version "492")
+    (source
+     (origin
+       (method git-fetch)
+       (uri (git-reference
+             (url "https://github.com/hydrusnetwork/hydrus")
+             (commit (string-append "v" version))))
+       (file-name (git-file-name name version))
+       (sha256
+        (base32
+         "0cyc499is97r8wri0y86yw6kpfcvc0a1yslr8g8sk4vhlly8gnra"))))
+    (build-system python-build-system)
+    (arguments
+     (list
+      #:phases
+      (with-imported-modules '((guix build utils))
+        #~(let ((bin-dir "/libexec/hydrus")
+                (static-dir "/share/hydrus/static"))
+            (modify-phases %standard-phases
+              ;; Hydrus is a python program but does not uses setup.py or any
+              ;; other build system to build itself - it's delivered ready to
+              ;; run from the source.
+              (replace 'check
+                (lambda _
+                  (setenv "DISPLAY" ":0")
+                  (setenv "XDG_CACHE_HOME" (getcwd))
+                  (setenv "HOME" (getcwd))
+                  (system "Xvfb &")
+                  (invoke "python" "test.py")))
+              (delete 'build)
+              (add-before 'install 'patch-variables
+                (lambda* (#:key outputs #:allow-other-keys)
+                  (let ((out (assoc-ref outputs "out")))
+                    (substitute* "hydrus/core/HydrusConstants.py"
+                      (("STATIC_DIR = (.*)\n")
+                       (string-append "STATIC_DIR = \"" out static-dir "\""))
+                      (("BIN_DIR = (.*)\n")
+                       (string-append "BIN_DIR = \"" out bin-dir "\"\n"))))))
+              (replace 'install
+                (lambda* (#:key outputs inputs #:allow-other-keys)
+                  (let* ((out (assoc-ref outputs "out"))
+                         (python (assoc-ref inputs "python"))
+                         (client-path (string-append out "/bin/hydrus"))
+                         (server-path (string-append out "/bin/hydrus-server")))
+                    (copy-recursively "static"
+                                      (string-append out static-dir))
+                    (copy-recursively "hydrus"
+                                      (string-append out
+                                                     "/lib/python"
+                                                     (python-version python)
+                                                     "/site-packages/hydrus"))
+                    (mkdir (string-append out "/bin"))
+                    (copy-file "client.py" client-path)
+                    (chmod client-path #o0555)
+                    (copy-file "server.py" server-path)
+                    (chmod server-path #o0555))))
+              ;; Hydrus searches for some binaries at bin-dir so it's important
+              ;; to put them there so it can find and use them.
+              (add-after 'install 'pupulate-libexec
+                (lambda* (#:key outputs inputs #:allow-other-keys)
+                  (let* ((out (assoc-ref outputs "out"))
+                         (out/bin-dir (string-append out bin-dir)))
+                    (mkdir-p out/bin-dir)
+                    (copy-file
+                     (string-append (assoc-ref inputs "swftools") "/bin/swfrender")
+                     (string-append out/bin-dir "/swfrender_linux"))
+                    (copy-file
+                     (string-append (assoc-ref inputs "ffmpeg") "/bin/ffmpeg")
+                     (string-append out/bin-dir "/ffmpeg"))
+                    (copy-file
+                     (string-append (assoc-ref inputs "miniupnpc") "/bin/upnpc")
+                     (string-append out/bin-dir "/miniupnpc"))))))))))
+    ;; All native-inputs are only needed for the the check phase
+    (native-inputs
+     (list
+      python-nose
+      python-mock
+      python-httmock
+      xorg-server-for-tests))
+    ;; All python packages were taken from static/build_files/linux/requirements.txt
+    (propagated-inputs
+     (list
+      python-beautifulsoup4
+      python-cbor2
+      python-chardet
+      python-cloudscraper
+      python-html5lib
+      python-lxml
+      python-lz4
+      python-numpy
+      opencv-with-python ; drop-in replacement for opencv-python-headless
+      python-pillow
+      python-psutil
+      python-pylzma
+      python-pyopenssl
+      python-pyside-2
+      python-pysocks
+      python-mpv
+      python-pyyaml
+      python-qtpy
+      python-requests
+      python-send2trash
+      python-service-identity
+      python-six
+      python-twisted))
+    (inputs (list swftools ffmpeg miniupnpc))
+    (synopsis "Organize your media with tags like a dektop booru")
+    (description
+     "The hydrus network client is an application written for
+internet-fluent media nerds who have large image/swf/webm collections.
+It browses with tags instead of folders, a little like a booru on your desktop.
+Advanced users can share tags and files anonymously through custom servers that
+any user may run.  Everything is free and privacy is the first concern.")
+    (home-page "https://hydrusnetwork.github.io/hydrus/")
+    (license license:wtfpl2)))