Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autodetection of plugin modules and Python path modification #19

Open
ErikBjare opened this issue Mar 4, 2016 · 5 comments
Open

Autodetection of plugin modules and Python path modification #19

ErikBjare opened this issue Mar 4, 2016 · 5 comments

Comments

@ErikBjare
Copy link
Member

It may be a good idea to try and import the entire packages of plugin modules and then simply iterate over the package namespace to try and find any subclasses of Agent (and Event/Action, if we want to pursue the idea mentioned in #17).

A possibly better idea is to decorate classes in the plugins and register them that way. I think we discussed doing this before but never got around to doing it for whatever reason and the idea disappeared into the ether.

I got these ideas while browsing the source of ZeroNet for leisure while sick. It's definately recommended reading, especially the PluginManager. It seems like they add the directory containing all plugins to the Python path (sys.path), as has been discussed, along with a few other source directories important to the project which can be found in this search.

I think adding to the Python path is a good course of action. I'm likely to introduce something similar into ActivityWatch, and if we can make a general PluginManager that'd be cool. I'd also like to introduce a ~/.config/homebrain (when running as a user service) and /var/lib/homebrain (when running as a system service under a user homebrain). These folders should each contain a plugin folder and configuration (such as which agents to start and how to connect them upon starting).

Ping @johan-bjareholt @vlthr, what do you think?

@ErikBjare ErikBjare added this to the 0.1 milestone Mar 4, 2016
@johan-bjareholt
Copy link
Collaborator

A decorator for agents would be a great idea so we can skip the agentclass variable in the init.py files.

As seen here, we already add the agents folder to the sys.path and import each one, so that's nothing new though.

After that we could move the autostart variable in init.py to a static class variable inside the agentclasses or something like that. We still need some place to put settings for the agents.

This doesn't add any functionality but makes things more clear, I'm all for that.

The /var/lib/homebrain and .config/homebrain have we already talked about and you know that i would like to see that aswell.

@johan-bjareholt
Copy link
Collaborator

6d9bc56

Agents will now be loaded from /var/lib/homebrain/agents/ if run as users root or homebrain, and otherwise from /home/$USER/.config/homebrain/agents/.

@ErikBjare
Copy link
Member Author

@johan-bjareholt It would probably be wise to make Homebrain refuse start if ran as root.

@johan-bjareholt
Copy link
Collaborator

@ErikBjare Hehe, good point.

Fixed so homebrain will not start if run as root in d76df2d.

@johan-bjareholt
Copy link
Collaborator

7e4dcc9

Made alot of changes.
The init.py files no longer specify the agentclass nor autostart and only import the agent files.
The module manager now instead finds all agent classes by itself, and if a agent wants to autostart it has to set "autostart = true" as a static class variable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants