Need help getting started with a new addon

I’m trying to develop a text report addon that would generate a table where the columns are persons selected using something like the “People of Interest” menu from “Family Lines Graph” graph. The rows would years, but with multiple lines per year similar to the 'Family Sheet" text report. I’m calling it “Timeline Contingency Report”. So far I have managed to:

But I seem to be unable to “register” the new code. Timeline Contingency does not appear in any menu, and I’m finding in information in the Wiki a trifle non-specific.

I would grateful for any constructive suggestions.

Welcome!

On lines 16-17 of your Gramps Plugin Registration file, it starts to double register the Report add-on and in the wrong (Tool) class. (You definitely want to run Gramps from the Console while debugging. That’s where the Registration error appeared that helped find this problem.)

Remove lines 16 & 17 and the Report registers successfully with no errors reported to the console. And now Timeline Contingency… appears in the Reports → Text Reports menu.

However, attempting to load the report echos the following messages to the Console:

Traceback (most recent call last):
  File "C:\Program Files\GrampsAIO64-5.1.5\gramps\gen\plug\_manager.py", line 252, in load_plugin
    _module = self.import_plugin(pdata)
  File "C:\Program Files\GrampsAIO64-5.1.5\gramps\gen\plug\_manager.py", line 285, in import_plugin
    module = __import__(pdata.mod_name)
  File "C:\Users\DistrictSupport\AppData\Roaming\gramps\gramps51\plugins\TimeContingency\timelinecontingency.py", line 67
    Class TimelineContingencyReport(Report)
                                  ^
SyntaxError: invalid syntax

Thanks for finding those errors. I deleted lines 16 and 17. When I tested the change, two errors occurred:
First there seemed to be some sort of conflict loading my family trees. I checked the version in the gramps help and it came up with 5.2.
Second, when I changed ‘gramps_target_version’ in the registration file to 5.2. The family tree loaded, but Timeline Contingency did not appear in the Reports → Test Reports menu.
I think I may have forked the wrong code. As I mentioned I’m finding the wiki a bit non-specific.

The code in timelinecontingency.py is mainly place holder, and I would not expect it to run correctly if at all. My first priority is getting the thin to show up on the menu.

@JohnS Are testing your new addon against a built (or installed) copy of Gramps 5.1.x? It sounds like you may be testing your addon against the latest code from gramps master branch which is versioned at 5.2 (next release). Unless your work requires Gramps 5.2, it’s probably better to target 5.1.

Typically when I work on changes (usually bug fixes) I create a new branch from the maintenance/gramps51 branch of the source, and I test changes against the installed version of Gramps 5.1.x on my system. Of course if you have a full-fledged gramps development environment, you can build and run maintenance/gramps51 branch too.

You’re probably familiar with git branching, but the wiki has steps on how to create a branch for developing against 5.1 near the end of this section: Get a local copy of Gramps and its addons.

I am trying to target version 5.1. But I was confused by suggestions in one of the development wiki pages. Executing gramps/Gramps.py’ starts v5.2.0, whereas executing gramps/scripts/gramps’ starts v5.1.2. Starting in Gnome terminal desktop emulator.

$uname -a
Linux kihikihi 5.4.0-128-generic #144-Ubuntu SMP Tue Sep 20 11:00:04 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

At my wits end: still unable to get my new addon to appear in the Reports>Text Report menu.

I resolved the gramps version question and managed to get gramps/scripts/gramps to load my family tree. But still no success with getting my TimelineContingency addon to appear in a menu.

Strange. The menu item appeared after creating a TimeContingency folder in my Gramps User Directory plugs folder (in Windows, that’s %appdata%/gramps/gramps51/plugins/TimeContingency) with your 2 files and changing the Gramps Plugin Registration file to the following:

register(REPORT,
    id    = "TimelineContingency",
    name  = _("Timeline Contingency"),
    description =  _("Creates a timeline table for selected persons."),
    version = "1.0.1",
    gramps_target_version = "5.1",
    status = STABLE,
    fname = "timelinecontingency.py",
    authors = ["John R. Sibert"],
    authors_email = ["johnrsibert@gmail.com"],
    category = CATEGORY_TEXT,
    reportclass = "TimelineContingency",
    optionclass = "TimelineContingency",
    report_modes = [REPORT_MODE_CLI, REPORT_MODE_GUI, REPORT_MODE_BKI],
    require_active = False,
    )

Although it appeared on the Tools → Text Reports submenu, here is its listing in the Report Selection dialog (launched from the image
button on the Toolbar.)

Make certain that the Gramps version number in the path to the plugins folder matches the version of Gramps that you are running.

You indicated you had a 5.2 prototype installed as well as the 5.1 general release version. The .gpr.py is a 5.1 version. So the addon has to be installed in the gramps/gramps51/plugins/ subfolder and you have to launch that 5.1 version of Gramps.

It appears that I neglected to build gramps from source after I downloaded to my local repo. I’m not able to specify version 5.1. The build script insists on building 5.2. I have the feeling that I should start again from zero. I’m building as a unique user to protect my standard installation.

Before you start from scratch…

Manually tweak the TimeContingency report folder in your local Gramps 5.1 plugins folder. Ignore the build scripts for this simple test.

If you don’t have a copy of your addon in that plugins folder, drag a copy there and use a simple text Editor (like Notepad++) to change the target version in the .gpr.py file.

The report should then build & show up in your menus.

A bit of success will go a long way towards reducing your frustration level… which makes any next steps less aggravating.

Hah! Small success indeed.
Pasting the TimelineContingency report folder in my local gramps51 plugins folder.
However, pasting it into my gramps52 editing the gpr file to version 5.2 (with vim) caused the adddon to appear in the menu. It even produced the expected output and error.

So a bit of success. But I think I need to be targeting gramps 5.1. No?

Thanks for your help and patience.

Unless your report uses features only available in the new 5.2 core, then YES! Definitely target 5.1 version.

Your pool of available beta testers (& Weblate translators) will be too small with a 5.2 target.

I decided to start again from scratch and I’m following guidance in the Addons Development Wiki. The wiki advises

To test your addon as you develop it is suggested that you copy your NewProjectName plugin into your Gramps user plugin directory from your addon development directory, prior to testing. Or just edit in the Gramps user plugin directory until it is ready to publish, then copy back to your addon development directory.

Your installed Gramps will search this folder (and subdirectories) for .gpr.py files, and add them to the plugin list.

The result is positive. My currently installed gramps software recognizes my new addon and executes it as expected.

However, the wiki advice runs contrary to my usual workflow with with github hosted code, which includes frequent commits to a forked repo. Copying new code back and forth between two directories is a bother and an invitation to error. So my instinct was to simply use a soft link eg
ln -s ~/GrampsTesting/addons-source/TimelineContingency/ ~/.gramps/gramps51/plugins, but when I tried the soft link, my gramps did not recognize the new addon.

So, two questions: (1) is it necessary to build gramps from source if one is simply writing a new addon; (2) is soft link problem linux quirk that I’n not understanding or a gramps feature?

Thanks again for all your attention and help.

I could help with diagnosing the registration file but am out of my depth when the GitHub side is involved.

As a dilettante, my exploring Python environment has been just been Notepad++ and Isotammi’s SuperTool add-on. (With cursory forays into PyCharm & Glade. ‘Curse’ being the operative term.)

Other than forking Gramps – which I deleted this week, my first use of personal repositories was yesterday!

We need to attract the mentoring attention of an experienced Gramps developer. @Nick-Hall , could you invite a developer with experience posting Report add-ons?

No.

Looking at the code, the plugins directory itself can be a symbolic link, but links are not followed when searching sub-directories with os.walk. We do not specify followlinks=True.

1 Like

Thanks for the reply. Presumably on would need to change lines 133-134 to

for (dirpath, dirnames, filenames) in os.walk(direct, followlinks=True
                                                          topdown=True):

which would require a build from source

You don’t need to build from source if you modify the code. I don’t suggest that you modify your production code though, unless you know what you are doing.

The build is mainly used for translations and manual pages, but it does build a few xml files.

Was about to raise it as an issue but can see one already !

1 Like

This is a bit late as you’ve progressed since and it would be better to stay with your setup if you’ve got it working.

However, you can try this when you’re ready to experiment again, or experiment in a separate source tree. Once you clone gramps and addons-source git repos, to work in gramps51 you can switch both repos to the origin/maintenance/gramps51 branch.

When you start new work, you can create a branch starting at the commit for origin/maintenance/gramps51 so you can develop code compatible with 5.1.

Git has a feature called ‘worktree’ which is also very helpful in creating a separate worktrees for working with different versions, but that’s a topic for another day.

1 Like

Thanks, but for nowI’m working around the symlink “problem” by simply copying files as needed using a simple bash script.

Nevertheless, I’m still missing something: The Report appears in the menu as expected, but does not seem to execute correctly. It seems to simply fall through code and exit with the message
AttributeError: type object ‘TimelineContingency’ has no attribute ‘load_previous_values’
running from my standard installation of gramps 5.1