Subject: [bug#44730] [GAJIM]: Fix loading of installed plugins

From: Raghav Gururajan <[email-masked]>
Date: Thu, 19 Nov 2020 15:50:49 -0500

Hello Tobias!

> Thanks for taking care of Gajim.

Anytime! :-)

> Raghav Gururajan 写道：
>> fix plugins issue in Gajim.
> 
> Please provide more information: what was wrong with the original code, 
> and why and how will your patch fix it?  It's better to put this in the 
> commit message itself (above the change log), not just the cover letter 
> (your mail).  No more than a few lines.
> 
> The more clear your explanation, the faster the fix can be reviewed and 
> merged.

I keep doing this, my apologies. I have included comment in commit 
message of revised patch.

> I assume that the problem is the empty ‘Plugins’ list when I run:
> 
>   $ guix environment guix \
>     -- ./pre-inst-env guix environment \
>     --pure --ad-hoc gajim{,-openpgp,-omemo} \
>     -- gajim

Yes!

> However, the fix doesn't look right to me.
> 
> After applying your patch, Gajim is broken.  Menus don't work.
> 
> --8<---------------cut here---------------start------------->8---
> Traceback (most recent call last):
>   File 
>   "/gnu/store/zd02xplbafrmzs2swrj3r3zx1hrsvg4y-gajim-1.2.2/lib/python3.8/site-packages/gajim/application.py",  line 222, in _activate
>     self.interface.run(self)
>   File 
>   "/gnu/store/zd02xplbafrmzs2swrj3r3zx1hrsvg4y-gajim-1.2.2/lib/python3.8/site-packages/gajim/gui_interface.py",  line 1965, in run
>     app.plugin_manager = plugins.PluginManager()
>   File 
>   "/gnu/store/zd02xplbafrmzs2swrj3r3zx1hrsvg4y-gajim-1.2.2/lib/python3.8/site-packages/gajim/common/helpers.py",  line 1002, in __call__
>     cls._instances[cls] = super(Singleton, cls).__call__(
>   File 
>   "/gnu/store/zd02xplbafrmzs2swrj3r3zx1hrsvg4y-gajim-1.2.2/lib/python3.8/site-packages/gajim/plugins/pluginmanager.py",  line 224, in __init__
>     self._load_plugins()
>   File 
>   "/gnu/store/zd02xplbafrmzs2swrj3r3zx1hrsvg4y-gajim-1.2.2/lib/python3.8/site-packages/gajim/plugins/pluginmanager.py",  line 668, in _load_plugins
>     for plugin_dir in configpaths.get_plugin_dirs():
>   File 
>   "/gnu/store/zd02xplbafrmzs2swrj3r3zx1hrsvg4y-gajim-1.2.2/lib/python3.8/site-packages/gajim/common/configpaths.py",  line 50, in get_plugin_dirs
>     Path(os.getenv['PLUGINS_OS']),
> --8<---------------cut here---------------end--------------->8---

Sorry, I was misled by a dev. I tries your patch instead now.

> I wrote my own patch (attached; no, I don't speak much Python).  I think 
> it fixes the problem but I can't test it.

Thanks! I just tested it. It works. :-)

> The plug-ins are found, but won't load with my version of Gajim.
> 
> --8<---------------cut here---------------start------------->8---
> 11/19/20 15:10:01 (W) gajim.plugin_system        Plugin omemo not 
> loaded, newer version of gajim required: 1.2.91 <= 1.2.2 <= 1.3.90
> 11/19/20 15:10:01 (W) gajim.plugin_system        Plugin openpgp not 
> loaded, newer version of gajim required: 1.2.91 <= 1.2.2 <= 1.3.90
> --8<---------------cut here---------------end--------------->8---
> 
> This is on current master.  How are these plug-ins expected to be used?

I think you installed plugins, both via guix and via gajim's plugin 
installer. You should remove one of them.

>> -       (variable "GAJIM_PLUGIN_PATH")
>> +       (variable "PLUGINS_OS")
> 
> This doesn't look related to the fix at hand.
> 
> Why remove GAJIM_?
> Why rename _PATH?
> TBH, both strike me as unnecessary regressions.
I was discussing with a Gajim Dev. They agreed to merge our patch in 
Gajim's upstream. So it can be useful for other non-conventional distros 
as well.

Regards,
RG.
From e102e488114673069f879afb3796a8e6fb69aaf4 Mon Sep 17 00:00:00 2001
From: Raghav Gururajan <[email-masked]>
Date: Thu, 19 Nov 2020 15:36:48 -0500
Subject: [PATCH] gnu: gajim: Fix loading of os-installed plugins.

* gnu/packages/messaging.scm (gajim) [patches]: Add gajim-plugins-os.patch.
[arguments]<#:phases>['add-plugins-dir]: Remove phase.
[native-search-paths]: Modify.
* gnu/packages/patches/gajim-plugins-os.patch: New file.
* gnu/local.mk (dist_patch_DATA): Add it.

[1] The 'add-plugins-dir phase does not work for version 1.2.2,
so this patch is a work-around.
[2] The variable name is changed from GAJIM_PLUGINS_PATH to PLUGINS_OS,
to resonate close with variable names PLUGINS_BASE and PLUGINS_USER,
as this patch is planned to be merged in gajim's upstream.
---
 gnu/local.mk                                |  1 +
 gnu/packages/messaging.scm                  | 16 ++++---------
 gnu/packages/patches/gajim-plugins-os.patch | 25 +++++++++++++++++++++
 3 files changed, 30 insertions(+), 12 deletions(-)
 create mode 100644 gnu/packages/patches/gajim-plugins-os.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index 217c05eab6..7fd98876d7 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -991,6 +991,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/freedink-engine-fix-sdl-hints.patch	\
   %D%/packages/patches/freeimage-unbundle.patch		\
   %D%/packages/patches/fuse-overlapping-headers.patch				\
+  %D%/packages/patches/gajim-plugins-os.patch                          \
   %D%/packages/patches/ganeti-deterministic-manual.patch	\
   %D%/packages/patches/ganeti-disable-version-symlinks.patch	\
   %D%/packages/patches/ganeti-drbd-compat.patch			\
diff --git a/gnu/packages/messaging.scm b/gnu/packages/messaging.scm
index 624ad72c23..09834bfe63 100644
--- a/gnu/packages/messaging.scm
+++ b/gnu/packages/messaging.scm
@@ -743,7 +743,9 @@ of xmpppy.")
                        (version-major+minor version)
                        "/gajim-" version ".tar.gz"))
        (sha256
-        (base32 "1gfcp3b5nq43xxz5my8vfhfxnnli726j3hzcgwh9fzrzzd9ic3gx"))))
+        (base32 "1gfcp3b5nq43xxz5my8vfhfxnnli726j3hzcgwh9fzrzzd9ic3gx"))
+       (patches
+        (search-patches "gajim-plugins-os.patch"))))
     (build-system python-build-system)
     (arguments
      `(#:imported-modules
@@ -756,16 +758,6 @@ of xmpppy.")
         (guix build utils))
        #:phases
        (modify-phases %standard-phases
-         (add-after 'unpack 'add-plugin-dirs
-           (lambda _
-             (substitute* "gajim/common/configpaths.py"
-               (("_paths\\['PLUGINS_USER'\\]\\]")
-                "_paths['PLUGINS_USER']] + \
-([os.getenv('GAJIM_PLUGIN_PATH')] \
-if os.getenv('GAJIM_PLUGIN_PATH') \
-and Path(os.getenv('GAJIM_PLUGIN_PATH')).is_dir() \
-else [])"))
-             #t))
          (replace 'check
            (lambda _
              ;; Tests require a running X server.
@@ -795,7 +787,7 @@ else [])"))
     (native-search-paths
      (list
       (search-path-specification
-       (variable "GAJIM_PLUGIN_PATH")
+       (variable "PLUGINS_OS")
        (separator #f)                   ;single entry
        (files
         (list
diff --git a/gnu/packages/patches/gajim-plugins-os.patch b/gnu/packages/patches/gajim-plugins-os.patch
new file mode 100644
index 0000000000..80a0dfacaf
--- /dev/null
+++ b/gnu/packages/patches/gajim-plugins-os.patch
@@ -0,0 +1,25 @@
+From c8e8d29243222e52bb30e123f2c7321a9f418995 Mon Sep 17 00:00:00 2001
+From: Raghav Gururajan <[email-masked]>
+Date: Thu, 19 Nov 2020 15:20:38 -0500
+Subject: [PATCH 3/3] [PATCH]: Fix loading of OS-installed plugins.
+
+---
+ gajim/common/configpaths.py | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/gajim/common/configpaths.py b/gajim/common/configpaths.py
+index 0ac879314..f4418b020 100644
+--- a/gajim/common/configpaths.py
++++ b/gajim/common/configpaths.py
+@@ -47,7 +47,7 @@ def get_plugin_dirs() -> List[Path]:
+         return [Path(_paths['PLUGINS_BASE']),
+                 Path('/app/plugins')]
+     return [Path(_paths['PLUGINS_BASE']),
+-            Path(_paths['PLUGINS_USER'])]
++            Path(_paths['PLUGINS_USER'])] + ([Path(os.getenv('PLUGINS_OS'))] if os.getenv('PLUGINS_OS') and Path(os.getenv('PLUGINS_OS')).is_dir() else [])
+ 
+ 
+ def get_paths(type_: PathType) -> Generator[Path, None, None]:
+-- 
+2.29.2
+
-- 
2.29.2