How can I make a `.gpr.py` registration that is compatible with 4.x and 5.2?

How can an add-on plug-in be made to be compatible with both 4.x and the new registration features of 5.2?

Kari’s use of the gramps.version is a start:

from gramps.version import major_version, VERSION_TUPLE

         gramps_target_version = major_version,

But what about the incompatible Registration tags like:

     icons = [('____', _('____'))],
     stock_icon='____',
     requires_mod=['____', '____'],
     help_url = "Addon:____",

For the Fitler+ multiple Category gramplets, @kku wrote the appended registration.
It seems to address the adaptations. It this the recommended method for backward compatibility?

#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2023 Gramps developers, Kari Kujansuu
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#


"""
Gramps registration file
"""

# See https://github.com/Taapeli/isotammi-addons/tree/master/source/Filter+
# or https://gramps-project.org/wiki/index.php/Addon:Isotammi_addons#Filter.2B

from gramps.version import major_version, VERSION_TUPLE

objs = """
Person
Family
Event
Place
Citation
Source
Repository
Media
Note
"""

help_url = "https://gramps-project.org/wiki/index.php/Addon:Isotammi_addons#Filter.2B"

if VERSION_TUPLE < (5, 2, 0):
    additional_args = {}
else:
    additional_args = {
        "audience": EXPERT,
        "help_url": help_url,
    }


for obj in objs.splitlines():
    obj = obj.strip()
    if obj == "": continue

    register(GRAMPLET,
             id=obj + "-Filter+",
             name=_(obj + " Filter+"),
             description = _("Gramplet providing a filter (enhanced)"),
             version="1.0.8",
             gramps_target_version=major_version,
             status = STABLE,
             fname="filter+.py",
             height=200,
             gramplet = obj + 'FilterPlus',
             gramplet_title=_("Filter+"),
             navtypes=[obj],
             **additional_args,
     )


register(RULE,
  id    = 'HasEventBase+',
  name  = _("HasEventBase+"),
  description = _("HasEventBase+ - used by Filter+"),
  version = '1.0.8',
  authors = ["Kari Kujansuu"],
  authors_email = ["kari.kujansuu@gmail.com"],
  gramps_target_version = major_version,
  status = STABLE,
  fname = "filter+.py",
  ruleclass = 'HasEventBasePlus',  # rule class name
  namespace = 'Event',  # one of the primary object classes
  **additional_args,
)

register(RULE,
  id    = 'HasSourceBase+',
  name  = _("HasSourceBase+"),
  description = _("HasSourceBase+ - used by Filter+"),
  version = '1.0.8',
  authors = ["Kari Kujansuu"],
  authors_email = ["kari.kujansuu@gmail.com"],
  gramps_target_version = major_version,
  status = STABLE,
  fname = "filter+.py",
  ruleclass = 'HasSourceBasePlus',  # rule class name
  namespace = 'Source',  # one of the primary object classes
  **additional_args,
)

Need some descriptions (or hotlinks) for the requires options in the plugin registration.
They have not yet been added to the Register section of the Sphinx documentation.

Added in Register Options section of the Gramplets wiki page.

  • requires_mod: — :zap:new for version 5.2.0
  • requires_gi: — :zap:new for version 5.2.0
  • requires_exe: — :zap:new for version 5.2.0

for the Consanguinity gramplet by Hans Boldt ( @ukulelehans )

#
# Gramps plugin registration file - a GTK+/GNOME based genealogy program
#  File: Consanguinity.gpr.py
#
# Copyright (C) 2021-2024        Hans Boldt
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#

from gramps.version import major_version, VERSION_TUPLE

# extended the help_url for plugin types other than Gramplets with 5.2 PR 1451 0009677
# https://github.com/gramps-project/gramps/blob/master/gramps/gen/plug/_pluginreg.py#L55
# old my_help_url = "https://github.com/hgboldt/consanguinity"
my_help_url = "Addon:Consanguinity_Gramplet"

if VERSION_TUPLE < (5, 2, 0):
    additional_args = {
        "status": STABLE,
        "help_url": my_help_url,
    }
else:
    additional_args = {
        "status": BETA,
        "audience": EVERYONE,
        "maintainers": [],
        "maintainers_email": [],
#        "requires_mod": "",
#        "requires_gi": "",
#        "requires_exe": "",
        "help_url": my_help_url,
    }

register(GRAMPLET,
        id="Consanguinity",
        name=_("Consanguinity"),
        gramplet = 'ConsanguinityGramplet',
        gramplet_title=_("Consanguinity"),
        navtypes=['Person'],
        description = _("Gramplet showing pedigree collapse and spousal consanguinity."),
        authors=["Hans Boldt"],
        authors_email=["hans@boldts.net"],
        version="1.0.1",
        gramps_target_version = major_version,
        fname="consanguinity.py",
        height = 50,
        detached_width = 400,
        detached_height = 500,
        **additional_args,
        )

Why the duplicate line ? Do you mean requires_exe instead of one of the requires_gi?

Are you suggesting that for 5.3, we adopt a backward-compatible style for gpr files for all addons? And each gets modified to make it backward compatible before we release?

Is there an easier way to make a new addon backward compatible? Ignore keywords that are unidentified? Omit the gramps_target_version keyword?

I suggest we have a policy before addon developers make the changes you suggest.

oops should be exe for the last one

Making the registration more fault tolerant for 5.3 and forward seems more likely to be supportable. (Feature request filed. see 0013405: Add fault tolerance to Gramps Plugin Registration )

This backwards compatibility additional_args hack demonstrates how clumsy it makes the .gpr.py structure. Instead, the plugin registering core code should ignore unrecognized keywords or values for keywords and just report them to the Gramps Logfile. Somewhat similarly to the way the GEDCOM import logs unrecognized tags. (Troubleshooting Gramps Plugin Registration is a royal pain since there is no feedback.)

The registration is going to need further expansions to support automating some of the wiki… like building a Addon List or templates for starting an Addon wiki page. See this GitHub PR 1312 comment for examples of needed expansions.