Skip to content

Commit

Permalink
Merge branch 'latest' into update/plugins_argparse_support
Browse files Browse the repository at this point in the history
  • Loading branch information
luizirber authored Aug 12, 2023
2 parents 6415239 + 02d2331 commit 5f94be8
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/sourmash/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

def main(arglist=None):
import sourmash
args = sourmash.cli.get_parser().parse_args(arglist)
args = sourmash.cli.parse_args(arglist)
if hasattr(args, 'subcmd'):
mod = getattr(sourmash.cli, args.cmd)
submod = getattr(mod, args.subcmd)
Expand Down
17 changes: 17 additions & 0 deletions src/sourmash/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,20 @@ def get_parser():
getattr(sys.modules[__name__], op).subparser(sub)
parser._action_groups.reverse()
return parser


def parse_args(arglist=None):
"""
Return an argparse 'args' object from parsing arglist.
By default pulls arguments from sys.argv.
Example usage:
```
args = parse_args(['sig', 'filter', '-m', '10'])
sourmash.sig.filter.__main__.filter(args)
```
"""
return get_parser().parse_args(arglist)
2 changes: 1 addition & 1 deletion src/sourmash/sig/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .__main__ import main
from .__main__ import * # bring all functions into top-level
from . import grep
9 changes: 9 additions & 0 deletions tests/test_cmd_signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ def test_run_sourmash_sig_cmd():
assert status != 0 # no args provided, ok ;)


def test_run_cat_via_parse_args():
# run a command ('sourmash.sig.cat') with args constructed via parse_args
import sourmash.sig, sourmash.cli
sig47 = utils.get_test_data('47.fa.sig')

args = sourmash.cli.parse_args(['sig', 'cat', sig47])
sourmash.sig.cat(args)


def test_sig_merge_1_use_full_signature_in_cmd(runtmp):
c = runtmp

Expand Down
6 changes: 4 additions & 2 deletions tests/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -1947,13 +1947,15 @@ def test_standalone_manifest_signatures_prefix_fail(runtmp):
row['internal_location'] = os.path.basename(row['internal_location'])

## got a manifest! ok, now test out StandaloneManifestIndex
mm = StandaloneManifestIndex(mi.manifest, None, prefix='foo')
mm = StandaloneManifestIndex(mi.manifest, None,
prefix=runtmp.output('foo'))

# should fail
with pytest.raises(ValueError) as exc:
list(mm.signatures())

assert "Error while reading signatures from 'foo/47.fa.sig'" in str(exc)
assert "Error while reading signatures from " in str(exc)
assert "foo/47.fa.sig'" in str(exc)


def test_standalone_manifest_load_from_dir(runtmp):
Expand Down
9 changes: 9 additions & 0 deletions tests/test_sourmash.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,15 @@ def test_compare_quiet(runtmp):
assert not c.last_result.err


def test_compare_do_traverse_directory_parse_args(runtmp):
# test 'compare' on a directory, using sourmash.cli.parse_args.
import sourmash.commands, sourmash.cli
args = sourmash.cli.parse_args(['compare', '-k', '21', '--dna',
utils.get_test_data('compare')])

sourmash.commands.compare(args)


def test_compare_do_traverse_directory(runtmp):
# test 'compare' on a directory
c = runtmp
Expand Down

0 comments on commit 5f94be8

Please sign in to comment.