diff --git a/setup.py b/setup.py index 1c59babab..576660080 100755 --- a/setup.py +++ b/setup.py @@ -36,4 +36,9 @@ def read(fname): 'pytest-isort==0.3.1', 'pytest-timeout==1.3.4', ], + entry_points={ + 'console_scripts': [ + 'permscope=tilescopethree.cli:main', + ] + } ) 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 diff --git a/tilescopethree/cli.py b/tilescopethree/cli.py new file mode 100644 index 000000000..8cc137da5 --- /dev/null +++ b/tilescopethree/cli.py @@ -0,0 +1,63 @@ +import argparse + +from comb_spec_searcher import StrategyPack +from tilescopethree import StrategyPacks, TileScopeTHREE +from tilings import Tiling + + +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 + 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 + 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') + 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()