From 5f9a6f0e4fa8c5dbc8fda167cbf50a5764446b1a Mon Sep 17 00:00:00 2001 From: Ezra Citron Date: Wed, 30 Jun 2021 17:30:02 -0700 Subject: [PATCH 1/5] format per PEP 8 --- Algorithmia/__main__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Algorithmia/__main__.py b/Algorithmia/__main__.py index edd149f..5b04290 100644 --- a/Algorithmia/__main__.py +++ b/Algorithmia/__main__.py @@ -199,17 +199,17 @@ def main(): elif args.cmd == 'cat': print(CLI().cat(args.path, client)) - + elif args.cmd == 'languages': response = CLI().list_languages(client) for line in response: print(line) elif args.cmd == 'template': - CLI().get_template(args.envid,args.dest,client) + CLI().get_template(args.envid,args.dest, client) elif args.cmd == 'environment': - response = CLI().get_environment_by_language(args.language,client) + response = CLI().get_environment_by_language(args.language, client) print(response) elif args.cmd == 'builds': From db0fc7eadab4dcc8ad840bf1381749149751c5d6 Mon Sep 17 00:00:00 2001 From: Ezra Citron Date: Wed, 30 Jun 2021 18:06:00 -0700 Subject: [PATCH 2/5] pretty-print output from listing envs --- Algorithmia/CLI.py | 13 +++++++++---- Algorithmia/__main__.py | 5 +++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Algorithmia/CLI.py b/Algorithmia/CLI.py index 76e1da3..7a64807 100644 --- a/Algorithmia/CLI.py +++ b/Algorithmia/CLI.py @@ -289,10 +289,15 @@ def cp(self, src, dest, client): def get_environment_by_language(self,language,client): response = client.get_environment(language) - if "error" in response: - return json.dumps(response) - return json.dumps(response['environments'],indent=1) - + table = [] + if "error" not in response: + table.append("{:<45} {:<40}".format('Name', 'Environment Specification ID')) + for env in response['environments']: + table.append("{:<45} {:<40}".format( + env['display_name'], env['environment_specification_id'])) + else: + table.append(json.dumps(response)) + return table def list_languages(self, client): response = client.get_supported_languages() diff --git a/Algorithmia/__main__.py b/Algorithmia/__main__.py index 5b04290..60ee1d0 100644 --- a/Algorithmia/__main__.py +++ b/Algorithmia/__main__.py @@ -210,7 +210,8 @@ def main(): elif args.cmd == 'environment': response = CLI().get_environment_by_language(args.language, client) - print(response) + for line in response: + print(line) elif args.cmd == 'builds': print(CLI().getBuildLogs(args.user, args.algo, client)) @@ -225,4 +226,4 @@ def main(): if __name__ == '__main__': #main() - main() \ No newline at end of file + main() From 07c5ee7d9c6c0e059da6dece4480333a5bbf5801 Mon Sep 17 00:00:00 2001 From: Ezra Citron Date: Wed, 30 Jun 2021 18:19:15 -0700 Subject: [PATCH 3/5] sort environments and prettify table --- Algorithmia/CLI.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Algorithmia/CLI.py b/Algorithmia/CLI.py index 7a64807..0b6419d 100644 --- a/Algorithmia/CLI.py +++ b/Algorithmia/CLI.py @@ -291,10 +291,18 @@ def get_environment_by_language(self,language,client): response = client.get_environment(language) table = [] if "error" not in response: - table.append("{:<45} {:<40}".format('Name', 'Environment Specification ID')) + # extract properties of interest for faster sort + subset_props = [] for env in response['environments']: + subset_props.append( + (env['display_name'], env['environment_specification_id'])) + # sort environments by display_name + subset_props = sorted(subset_props, key=lambda tup: tup[0] ) + table.append("{:<45} {:<40}".format('Name', 'Environment Specification ID')) + table.append('*' * 80) + for tup in subset_props: table.append("{:<45} {:<40}".format( - env['display_name'], env['environment_specification_id'])) + tup[0], tup[1])) else: table.append(json.dumps(response)) return table @@ -304,6 +312,7 @@ def list_languages(self, client): table = [] if "error" not in response: table.append("{:<25} {:<35}".format('Name','Description')) + table.append('*' * 80) for lang in response: table.append("{:<25} {:<35}".format(lang['name'],lang['display_name'])) else: From 4c9bbdf573b7ae3cea1937dc9cb029316f9cfda3 Mon Sep 17 00:00:00 2001 From: Ezra Citron Date: Wed, 30 Jun 2021 18:22:14 -0700 Subject: [PATCH 4/5] change headers to match names of properties --- Algorithmia/CLI.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Algorithmia/CLI.py b/Algorithmia/CLI.py index 0b6419d..7ec7eba 100644 --- a/Algorithmia/CLI.py +++ b/Algorithmia/CLI.py @@ -298,7 +298,7 @@ def get_environment_by_language(self,language,client): (env['display_name'], env['environment_specification_id'])) # sort environments by display_name subset_props = sorted(subset_props, key=lambda tup: tup[0] ) - table.append("{:<45} {:<40}".format('Name', 'Environment Specification ID')) + table.append("{:<45} {:<40}".format('Display Name', 'Specification ID')) table.append('*' * 80) for tup in subset_props: table.append("{:<45} {:<40}".format( @@ -311,7 +311,7 @@ def list_languages(self, client): response = client.get_supported_languages() table = [] if "error" not in response: - table.append("{:<25} {:<35}".format('Name','Description')) + table.append("{:<25} {:<35}".format('Name','Display Name')) table.append('*' * 80) for lang in response: table.append("{:<25} {:<35}".format(lang['name'],lang['display_name'])) From 1bcbf988260cc85bf78bc1ad687a5c17db40c375 Mon Sep 17 00:00:00 2001 From: Ezra Citron Date: Wed, 30 Jun 2021 18:43:15 -0700 Subject: [PATCH 5/5] fix test to accomodate new output format --- Test/CLI_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Test/CLI_test.py b/Test/CLI_test.py index 4636fc6..5e0591b 100644 --- a/Test/CLI_test.py +++ b/Test/CLI_test.py @@ -177,7 +177,7 @@ def test_get_environment(self): print(result) if("error" in result): print(result) - self.assertTrue(result is not None and "display_name" in result) + self.assertTrue(result is not None and "Python 2.7" in result) def test_list_languages(self): result = CLI().list_languages(self.client)