-
Notifications
You must be signed in to change notification settings - Fork 78
/
__init__.py
54 lines (43 loc) · 1.67 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""Provide a mechanism to add CLI plugins to sourmash.
See https://sourmash.readthedocs.io/en/latest/dev_plugins.html for docs,
src/sourmash/plugins.py for core sourmash implementation code, and
https://github.com/sourmash-bio/sourmash_plugin_template for a template repo
for making new plugins.
"""
# CTB TODO:
# * provide suggestions for documentation & metadata for authors:
# * provide guidance on how to test your CLI plugin at the CLI
# (minimal testing regime: sourmash scripts, look for description etc.)
import argparse
import sourmash
# Here, we decorate this module with the various extension objects
# e.g. 'sourmash scripts foo' will look up attribute 'scripts.foo'
# and we will return the extension class object, which will then
# be run by sourmash.__main__. This dictionary is loaded below
# by sourmash.plugins.add_cli_scripts.
_extension_dict = {}
def __getattr__(name):
if name in _extension_dict:
return _extension_dict[name]
raise AttributeError(name)
def subparser(subparsers):
subparser = subparsers.add_parser(
"scripts",
usage=argparse.SUPPRESS,
formatter_class=argparse.RawDescriptionHelpFormatter,
aliases=["ext"],
)
# get individual help strings:
descrs = list(sourmash.plugins.get_cli_scripts_descriptions())
if descrs:
description = "\n".join(descrs)
else:
description = "(No script plugins detected!)"
s = subparser.add_subparsers(
title="available plugin/extension commands",
dest="subcmd",
metavar="subcmd",
help=argparse.SUPPRESS,
description=description,
)
_extension_dict.update(sourmash.plugins.add_cli_scripts(s))