From 7cab0cc4f5fb5739ebd600891b9f546b472a152d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89mile=20Nadeau?= Date: Fri, 24 Jan 2020 16:32:52 +0000 Subject: [PATCH 1/3] adding a cli --- setup.py | 5 ++++ tilescopethree/cli.py | 60 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 tilescopethree/cli.py diff --git a/setup.py b/setup.py index 63375b392..2baa678e6 100755 --- a/setup.py +++ b/setup.py @@ -35,4 +35,9 @@ def read(fname): 'pytest-pep8==1.0.6', 'pytest-isort==0.3.1', ], + entry_points={ + 'console_scripts': [ + 'permscope=tilescopethree.cli:main', + ] + } ) diff --git a/tilescopethree/cli.py b/tilescopethree/cli.py new file mode 100644 index 000000000..0dded5fbc --- /dev/null +++ b/tilescopethree/cli.py @@ -0,0 +1,60 @@ +import argparse + +from tilescopethree import StrategyPacks +from tilescopethree import TileScopeTHREE +from tilings import Tiling +from comb_spec_searcher import StrategyPack + + +def list_stratpacks(args): + """ + Prints out every strategy pack available. + """ + for pack in dir(StrategyPacks): + if isinstance(getattr(StrategyPacks, pack), StrategyPack): + print(pack) + return 0 + +def search_tree(args): + """ + Search for a tree. + """ + print('searching for a tree') + try: + pack_to_run = getattr(StrategyPacks, args.strategy_pack) + except AttributeError as e: + print("Strategy pack '{}' was not found".format(args.strategy_pack)) + return 1 + start_class = Tiling.from_string(args.basis) + css = TileScopeTHREE(start_class, pack_to_run) + css.auto_search(status_update=30) + return 0 + +def main(): + parser = argparse.ArgumentParser( + description='A command line tool for the Periscope algorithm.' + ) + subparsers = parser.add_subparsers(title='subcommands') + #List command + parser_list = subparsers.add_parser('list', help='List all the strategy ' + 'packs available.') + parser_list.set_defaults(func=list_stratpacks) + #Tree command + parser_tree = subparsers.add_parser('tree', help='Search for a tree with ' + 'for a given permutation class with a ' + 'given strategy pack.') + parser_tree.add_argument('basis', type=str, help='The basis of the permutation ' + 'class. The permutation can be 1 or 0-based and are ' + 'separated by an underscore') + parser_tree.add_argument('strategy_pack', type=str, help='The strategy pack to ' + 'run. The strategy defines the set of strategy that ' + 'will be used to expand the universe of combinatorial' + ' classes.') + parser_tree.set_defaults(func=search_tree) + # Running the parsers + args = parser.parse_args() + return args.func(args) + + +if __name__ == "__main__": + main() From 7593e63b7167b3c897f8fd93292abbe776fe0fdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89mile=20Nadeau?= Date: Tue, 28 Jan 2020 16:10:14 +0000 Subject: [PATCH 2/3] test for cli --- tests/test_cli.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 tests/test_cli.py diff --git a/tests/test_cli.py b/tests/test_cli.py new file mode 100644 index 000000000..ea0cb66b8 --- /dev/null +++ b/tests/test_cli.py @@ -0,0 +1,27 @@ +import os + +import pytest + + +def test_entrypoints(): + exit_status = os.system('permscope --help') + assert exit_status == 0 + exit_status = os.system('permscope list --help') + assert exit_status == 0 + exit_status = os.system('permscope tree --help') + assert exit_status == 0 + + +def test_list(): + exit_status = os.system('permscope list') + assert exit_status == 0 + + +@pytest.mark.timeout(20) +def test_tree(): + exit_status = os.system('permscope tree 132 point_placements') + assert exit_status == 0 + exit_status = os.system('permscope tree 132') + assert exit_status != 0 + exit_status = os.system('permscope tree point_placements') + assert exit_status != 0 From 889ad61d8503de0918019cebb74836543e0f1146 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89mile=20Nadeau?= Date: Tue, 28 Jan 2020 16:23:13 +0000 Subject: [PATCH 3/3] improve cli help --- tilescopethree/cli.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tilescopethree/cli.py b/tilescopethree/cli.py index 708e3e4bc..8cc137da5 100644 --- a/tilescopethree/cli.py +++ b/tilescopethree/cli.py @@ -37,13 +37,15 @@ def main(): ) subparsers = parser.add_subparsers(title='subcommands') # List command - parser_list = subparsers.add_parser('list', help='List all the strategy ' - 'packs available.') + helpstr = 'List all the strategy pack available' + parser_list = subparsers.add_parser('list', help=helpstr, + description=helpstr) parser_list.set_defaults(func=list_stratpacks) # Tree command - parser_tree = subparsers.add_parser('tree', help='Search for a tree with ' - 'for a given permutation class with a ' - 'given strategy pack.') + helpstr = ('Search for a tree with for a given permutation class with a ' + 'given strategy pack.') + parser_tree = subparsers.add_parser('tree', help=helpstr, + description=helpstr) parser_tree.add_argument('basis', type=str, help='The basis of the ' 'permutation class. The permutation can be 1 or ' '0-based and are separated by an underscore')