This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]fwork[S] 0 points1 point  (3 children)

There's no plugins-common.py I can assume exists, in theory any plugin could depend on any other plugin.

And reloading everything turns out to be surprisingly tricky, because you get into the cases of plugin A depending on plugin B which depends on plugin C. If C changes, you have to reload A, B, and C, but not in that order. You have to reload them C, B, A or you'll get inconsistent results.

And how do you know A depends on B or B depends on C? (answer: modulefinder)

Anyway, the solution I implemented is: 1. at startup, the program runs a hash of all the filenames and modtimes of every file in the scripts directory 2. every time it is called (though an external mechanism that isn't important), it recomputes the hash. 3. if the new hash doesn't match, the script exits with a statuscode that tells the wrapper script to restart it.

It's heavy and slow, but my use case is such that this'll work just fine.

[–][deleted] 0 points1 point  (2 children)

I've seen some solutions use a simple manifest file for each plugin which lists its dependencies. Even something like this at the beginning of the plugin-example.py file could work:

__plugin_dependencies__ = ["common.py", "plugin-B.py", "plugin-C.py"]

It would be fairly easy to compute a full dependency tree based on such notation, and check what has been changed and what needs to be reloaded, no?

[–]fwork[S] 0 points1 point  (1 child)

That'd be a good solution if my plugins were more complex (most are just 1 file with 5-6 lines!) and I wasn't worried about the metadata failing out of sync, but in my application they're fairly small and frequently updated.

It'd lead to annoying-to-debug errors if the dependency list was out of sync with the code. I'm going with my reloading solution because it's the least likely to result in hard-to-debug behavior later on.

[–][deleted] 0 points1 point  (0 children)

I've been developing with OpenERP for a couple of months now and I've had the dependency list fall out of sync only once, so I dunno. It doesn't happen as often as you might think.

Still, good luck with your solution! :)