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

Adding plugin support #53

Merged
merged 3 commits into from
Jul 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions qha/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def main():
qha_plotter = QHAPlotter()
parser.add_program('plot', qha_plotter)

parser.add_plugin_programs()

parser.parse_args()


Expand Down
11 changes: 10 additions & 1 deletion qha/cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import argparse
import sys
import pkg_resources

from qha import __version__
from qha.cli.program import QHAProgram
Expand All @@ -25,7 +26,15 @@ def add_program(self, cmd: str, prog: QHAProgram, aliases: list = []):
'aliases': aliases
})
prog.init_parser(subparser)


def add_plugin_programs(self):
for entry_point in pkg_resources.iter_entry_points(group='qha.applications'):
klass = entry_point.load()
command = entry_point.name
aliases = klass.aliases if 'aliases' in dir(klass) else None
program = klass()
self.add_program(command, program, aliases)

def parse_args(self, args=None, namespace=None):
namespace = self.parser.parse_args(args, namespace)
command = namespace.command
Expand Down