Skip to content
New issue

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

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

Already on GitHub? # to your account

Support custom plugin locations and arbitrary plugin modules #160

Merged
merged 1 commit into from
Oct 1, 2019

Conversation

csams
Copy link
Contributor

@csams csams commented Nov 30, 2018

Allow users to write their own plugins without needing to download the project repo. They can install did and use the config file to point to their custom plugins. This also makes it easier to share plugins outside of the project itself.

  • Refactor the plugin loading logic to use importlib and pkgutil so it can load plugins from an egg (already on the PYTHONPATH) as well as arbitrary places on the file system.
  • Add a custom_plugins option to the general section of the config. Users can add a space or comma separated list of directories where custom plugins reside, and they'll automatically get loaded if the directories are valid python2 packages (include __init__.py files).
  • Refactor the plugin system so StatsGroup subclasses register themselves. This removes the need to scan modules individually and allows plugins to be defined at any level in a package hierarchy.

This PR introduces no new dependencies, but it does use importlib, which only comes installed with python 2.7 and beyond. It's available in pypi for python 2.6. The new loader code is python2/3 compatible.

Example config:

[general]
email = Joe User <joe@example.com>
custom_plugins = ~/.did/custom_plugins

[thing]
type = thing

Example file (thing.py) in ~/did/custom_plugins:

from did.stats import EmptyStatsGroup


class Thing(EmptyStatsGroup):
    """ This is a Thing! """
    pass

Example help:

└> did -h
usage: did [this|last] [week|month|quarter|year] [options]

optional arguments:
  -h, --help            show this help message and exit

Select:
  --email EMAILS        User email address(es)
  --since SINCE         Start date in the YYYY-MM-DD format
  --until UNTIL         End date in the YYYY-MM-DD format

This is a Thing!:
  --thing               All above

Format:
  --format FORMAT       Output style, possible values: text (default) or wiki
  --width WIDTH         Maximum width of the report output (default: 79)
  --brief               Show brief summary only, do not list individual items
  --verbose             Include more details (like modified git directories)

Utils:
  --config FILE         Use alternate configuration file (default: 'config')
  --total               Append total stats after listing individual users
  --merge               Merge stats of all users into a single report
  --debug               Turn on debugging output, do not catch exceptions
  --test                Run a simple smoke test against the github server

@coveralls
Copy link

coveralls commented Nov 30, 2018

Coverage Status

Coverage increased (+0.07%) to 81.972% when pulling b08a934 on csams:refactor_plugin_loading into 2b73b75 on psss:master.

@csams csams force-pushed the refactor_plugin_loading branch from 13de598 to 2c2c89f Compare November 30, 2018 21:26
The idea is to allow users to write their own plugins without needing to
download the code. They can pip install or dnf install and use the config
file to point to their custom plugins.

* Refactor the loading logic to use importlib and pkgutil so it can load plugins
from an egg and arbitrary places on the filesystem.

* Add a custom_plugins option to the general section of the config. Users
can add a space separated list of directories where custom plugins reside.

Example:
```
[general]
email = Joe User <joe@example.com>
custom_plugins = ~/.did/custom_plugins

[thing]
type = thing
```
@csams csams force-pushed the refactor_plugin_loading branch from 2c2c89f to b08a934 Compare November 30, 2018 21:47
@csams
Copy link
Contributor Author

csams commented Dec 1, 2018

@psss Would you rather this PR go against devel?

@psss
Copy link
Owner

psss commented Dec 18, 2018

Thanks for the enhancement. This looks good. I just need a bit more time to review the changes. Hopefully in the coming days. No need to update this against the devel branch.

psss added a commit that referenced this pull request Oct 1, 2019
@psss psss merged commit b08a934 into psss:master Oct 1, 2019
psss added a commit to mweetman-redhat/did that referenced this pull request Jan 30, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants