From 12874ebaf10a983530add578da142b2612f24085 Mon Sep 17 00:00:00 2001 From: Besir Kurtulmus Date: Tue, 5 Feb 2019 02:47:25 -0800 Subject: [PATCH 01/15] Support algorithn .create() .update() .publish() and .getInfo() methods --- Algorithmia/algorithm.py | 62 ++++++++++++++++++++++++++++++++++++++++ Algorithmia/client.py | 4 +++ setup.py | 3 +- 3 files changed, 68 insertions(+), 1 deletion(-) diff --git a/Algorithmia/algorithm.py b/Algorithmia/algorithm.py index eaea1af..b85d655 100644 --- a/Algorithmia/algorithm.py +++ b/Algorithmia/algorithm.py @@ -6,6 +6,9 @@ from Algorithmia.algo_response import AlgoResponse from Algorithmia.errors import ApiError, ApiInternalError from enum import Enum +from algorithmia_api_client.rest import ApiException +from algorithmia_api_client import CreateRequest, UpdateRequest, VersionRequest, Details, Settings, SettingsMandatory, SettingsPublish, \ + CreateRequestVersionInfo, VersionInfo OutputType = Enum('OutputType','default raw void') @@ -17,6 +20,10 @@ def __init__(self, client, algoRef): if m is not None: self.client = client self.path = m.group(1) + self.username = self.path.split("/")[0] + self.algoname = self.path.split("/")[1] + if len(self.path.split("/")) > 2: + self.version = self.path.split("/")[2] self.url = '/v1/algo/' + self.path self.query_parameters = {} self.output_type = OutputType.default @@ -29,6 +36,61 @@ def set_options(self, timeout=300, stdout=False, output=OutputType.default, **qu self.query_parameters.update(query_parameters) return self + # Create a new algorithm + def create(self, details, settings, version_info): + detailsObj = Details(**details) + settingsObj = SettingsMandatory(**settings) + createRequestVersionInfoObj = CreateRequestVersionInfo(**version_info) + create_parameters = {"name": self.algoname, "details": detailsObj, "settings": settingsObj, "version_info": createRequestVersionInfoObj} + create_request = CreateRequest(**create_parameters) + try: + # Create Algorithm + api_response = self.client.manageApi.create_algorithm(self.username, create_request) + print(api_response) + return api_response + except ApiException as e: + print("Exception when calling DefaultApi->create_algorithm: %s\n" % e) + + # Update the settings in an algorithm + def update(self, details, settings, version_info): + detailsObj = Details(**details) + settingsObj = Settings(**settings) + createRequestVersionInfoObj = CreateRequestVersionInfo(**version_info) + update_parameters = {"details": detailsObj, "settings": settingsObj, "version_info": createRequestVersionInfoObj} + update_request = UpdateRequest(**update_parameters) + try: + # Update Algorithm + api_response = self.client.manageApi.update_algorithm(self.username, self.algoname, update_request) + print(api_response) + return api_response + except ApiException as e: + print("Exception when calling DefaultApi->update_algorithm: %s\n" % e) + + # Publish an algorithm + def publish(self, details, settings, version_info): + detailsObj = Details(**details) + settingsObj = SettingsPublish(**settings) + versionRequestObj = VersionInfo(**version_info) + publish_parameters = {"details": detailsObj, "settings": settingsObj, "version_info": versionRequestObj} + version_request = VersionRequest(**publish_parameters) # VersionRequest | Publish Version Request + try: + # Publish Algorithm + api_response = self.client.manageApi.publish_algorithm(self.username, self.algoname, version_request) + print(api_response) + return api_response + except ApiException as e: + print("Exception when calling DefaultApi->publish_algorithm: %s\n" % e) + + # Get info on an algorithm + def getInfo(self): + try: + # Get Algorithm + api_response = self.client.manageApi.get_algorithm(self.username, self.algoname) + pprint(api_response) + return api_response + except ApiException as e: + print("Exception when calling DefaultApi->get_algorithm: %s\n" % e) + # Pipe an input into this algorithm def pipe(self, input1): diff --git a/Algorithmia/client.py b/Algorithmia/client.py index 4ea3eee..5c53c77 100644 --- a/Algorithmia/client.py +++ b/Algorithmia/client.py @@ -4,6 +4,7 @@ from Algorithmia.algorithm import Algorithm from Algorithmia.datafile import DataFile from Algorithmia.datadirectory import DataDirectory +from algorithmia_api_client import Configuration, DefaultApi, ApiClient import json, re, requests, six import os @@ -23,6 +24,9 @@ def __init__(self, apiKey = None, apiAddress = None): self.apiAddress = apiAddress else: self.apiAddress = Algorithmia.getApiAddress() + config = Configuration() + config.api_key['Authorization'] = self.apiKey + self.manageApi = DefaultApi(ApiClient(config)) def algo(self, algoRef): return Algorithm(self, algoRef) diff --git a/setup.py b/setup.py index cda1770..3b0c9cb 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,8 @@ install_requires=[ 'requests', 'six', - 'enum34' + 'enum34', + 'algorithmia-api-client==1.0.0' ], include_package_data=True, classifiers=[ From b9ed7a5961ae6c061b4e54481a99ef20045a6226 Mon Sep 17 00:00:00 2001 From: Besir Kurtulmus Date: Tue, 5 Feb 2019 18:51:13 -0800 Subject: [PATCH 02/15] Don't use pretty print for printing the api_reponse --- Algorithmia/algorithm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Algorithmia/algorithm.py b/Algorithmia/algorithm.py index b85d655..ef4fab8 100644 --- a/Algorithmia/algorithm.py +++ b/Algorithmia/algorithm.py @@ -86,7 +86,7 @@ def getInfo(self): try: # Get Algorithm api_response = self.client.manageApi.get_algorithm(self.username, self.algoname) - pprint(api_response) + print(api_response) return api_response except ApiException as e: print("Exception when calling DefaultApi->get_algorithm: %s\n" % e) From aab14ab4afa8630eba15009bb9b2db79743715b2 Mon Sep 17 00:00:00 2001 From: Besir Kurtulmus Date: Fri, 8 Feb 2019 13:11:52 -0800 Subject: [PATCH 03/15] Remove print statements from new methods --- Algorithmia/algorithm.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Algorithmia/algorithm.py b/Algorithmia/algorithm.py index ef4fab8..d0872b1 100644 --- a/Algorithmia/algorithm.py +++ b/Algorithmia/algorithm.py @@ -46,7 +46,6 @@ def create(self, details, settings, version_info): try: # Create Algorithm api_response = self.client.manageApi.create_algorithm(self.username, create_request) - print(api_response) return api_response except ApiException as e: print("Exception when calling DefaultApi->create_algorithm: %s\n" % e) @@ -61,7 +60,6 @@ def update(self, details, settings, version_info): try: # Update Algorithm api_response = self.client.manageApi.update_algorithm(self.username, self.algoname, update_request) - print(api_response) return api_response except ApiException as e: print("Exception when calling DefaultApi->update_algorithm: %s\n" % e) @@ -76,7 +74,6 @@ def publish(self, details, settings, version_info): try: # Publish Algorithm api_response = self.client.manageApi.publish_algorithm(self.username, self.algoname, version_request) - print(api_response) return api_response except ApiException as e: print("Exception when calling DefaultApi->publish_algorithm: %s\n" % e) @@ -86,7 +83,6 @@ def getInfo(self): try: # Get Algorithm api_response = self.client.manageApi.get_algorithm(self.username, self.algoname) - print(api_response) return api_response except ApiException as e: print("Exception when calling DefaultApi->get_algorithm: %s\n" % e) From 80df5362c1a91e01b66d203f10decc6a89a377c5 Mon Sep 17 00:00:00 2001 From: Besir Kurtulmus Date: Fri, 8 Feb 2019 13:36:26 -0800 Subject: [PATCH 04/15] Raise ApiError when you get an ApiException --- Algorithmia/algorithm.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Algorithmia/algorithm.py b/Algorithmia/algorithm.py index d0872b1..cc35a72 100644 --- a/Algorithmia/algorithm.py +++ b/Algorithmia/algorithm.py @@ -48,7 +48,7 @@ def create(self, details, settings, version_info): api_response = self.client.manageApi.create_algorithm(self.username, create_request) return api_response except ApiException as e: - print("Exception when calling DefaultApi->create_algorithm: %s\n" % e) + raise ApiError("Exception when calling DefaultApi->create_algorithm: %s\n" % e) # Update the settings in an algorithm def update(self, details, settings, version_info): @@ -62,7 +62,7 @@ def update(self, details, settings, version_info): api_response = self.client.manageApi.update_algorithm(self.username, self.algoname, update_request) return api_response except ApiException as e: - print("Exception when calling DefaultApi->update_algorithm: %s\n" % e) + raise ApiError("Exception when calling DefaultApi->update_algorithm: %s\n" % e) # Publish an algorithm def publish(self, details, settings, version_info): @@ -76,7 +76,7 @@ def publish(self, details, settings, version_info): api_response = self.client.manageApi.publish_algorithm(self.username, self.algoname, version_request) return api_response except ApiException as e: - print("Exception when calling DefaultApi->publish_algorithm: %s\n" % e) + raise ApiError("Exception when calling DefaultApi->publish_algorithm: %s\n" % e) # Get info on an algorithm def getInfo(self): @@ -85,7 +85,7 @@ def getInfo(self): api_response = self.client.manageApi.get_algorithm(self.username, self.algoname) return api_response except ApiException as e: - print("Exception when calling DefaultApi->get_algorithm: %s\n" % e) + raise ApiError("Exception when calling DefaultApi->get_algorithm: %s\n" % e) # Pipe an input into this algorithm def pipe(self, input1): From 396128055f65bdff731b3d70e4a47354e63c6d67 Mon Sep 17 00:00:00 2001 From: Besir Kurtulmus Date: Fri, 8 Feb 2019 13:42:05 -0800 Subject: [PATCH 05/15] Change algorithmia-api-client dependency from a version to a version range --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 3b0c9cb..7f5a1c9 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ 'requests', 'six', 'enum34', - 'algorithmia-api-client==1.0.0' + 'algorithmia-api-client>=1.0.0,<2.0' ], include_package_data=True, classifiers=[ From 90ab3cae8aa0140db7ab4c00c58bb8be1acdda32 Mon Sep 17 00:00:00 2001 From: Besir Kurtulmus Date: Mon, 11 Feb 2019 11:07:33 -0800 Subject: [PATCH 06/15] Use VersionInfoPublish for publishing algorithms --- Algorithmia/algorithm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Algorithmia/algorithm.py b/Algorithmia/algorithm.py index cc35a72..7c6aa1c 100644 --- a/Algorithmia/algorithm.py +++ b/Algorithmia/algorithm.py @@ -8,7 +8,7 @@ from enum import Enum from algorithmia_api_client.rest import ApiException from algorithmia_api_client import CreateRequest, UpdateRequest, VersionRequest, Details, Settings, SettingsMandatory, SettingsPublish, \ - CreateRequestVersionInfo, VersionInfo + CreateRequestVersionInfo, VersionInfo, VersionInfoPublish OutputType = Enum('OutputType','default raw void') @@ -68,7 +68,7 @@ def update(self, details, settings, version_info): def publish(self, details, settings, version_info): detailsObj = Details(**details) settingsObj = SettingsPublish(**settings) - versionRequestObj = VersionInfo(**version_info) + versionRequestObj = VersionInfoPublish(**version_info) publish_parameters = {"details": detailsObj, "settings": settingsObj, "version_info": versionRequestObj} version_request = VersionRequest(**publish_parameters) # VersionRequest | Publish Version Request try: From f3fb7dadff9228a84a906b3ef4aef1fbe6235c5e Mon Sep 17 00:00:00 2001 From: Besir Kurtulmus Date: Mon, 11 Feb 2019 11:13:21 -0800 Subject: [PATCH 07/15] Take in publish parameters optiuonally --- Algorithmia/algorithm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Algorithmia/algorithm.py b/Algorithmia/algorithm.py index 7c6aa1c..002bea3 100644 --- a/Algorithmia/algorithm.py +++ b/Algorithmia/algorithm.py @@ -65,7 +65,7 @@ def update(self, details, settings, version_info): raise ApiError("Exception when calling DefaultApi->update_algorithm: %s\n" % e) # Publish an algorithm - def publish(self, details, settings, version_info): + def publish(self, details={}, settings={}, version_info={}): detailsObj = Details(**details) settingsObj = SettingsPublish(**settings) versionRequestObj = VersionInfoPublish(**version_info) From 04d3352474fbaab445dead544437e6bd03676057 Mon Sep 17 00:00:00 2001 From: Besir Kurtulmus Date: Mon, 11 Feb 2019 12:23:33 -0800 Subject: [PATCH 08/15] Add compile() method to .algo() --- Algorithmia/algorithm.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Algorithmia/algorithm.py b/Algorithmia/algorithm.py index 002bea3..6660371 100644 --- a/Algorithmia/algorithm.py +++ b/Algorithmia/algorithm.py @@ -87,6 +87,15 @@ def getInfo(self): except ApiException as e: raise ApiError("Exception when calling DefaultApi->get_algorithm: %s\n" % e) + # Compile an algorithm + def compile(self): + try: + # Compile algorithm + api_response = self.client.manageApi.algorithms_username_algoname_compile_post(self.username, self.algoname) + return api_response + except ApiException as e: + print("Exception when calling DefaultApi->algorithms_username_algoname_compile_post: %s\n" % e) + # Pipe an input into this algorithm def pipe(self, input1): From c4f7798a1263cc90697d690b80777a90dbda951b Mon Sep 17 00:00:00 2001 From: Besir Kurtulmus Date: Mon, 11 Feb 2019 15:27:12 -0800 Subject: [PATCH 09/15] Make all parameters optional to algo management api's since the server response w/ appropiate error anyway --- Algorithmia/algorithm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Algorithmia/algorithm.py b/Algorithmia/algorithm.py index 6660371..a7514bb 100644 --- a/Algorithmia/algorithm.py +++ b/Algorithmia/algorithm.py @@ -37,7 +37,7 @@ def set_options(self, timeout=300, stdout=False, output=OutputType.default, **qu return self # Create a new algorithm - def create(self, details, settings, version_info): + def create(self, details={}, settings={}, version_info={}): detailsObj = Details(**details) settingsObj = SettingsMandatory(**settings) createRequestVersionInfoObj = CreateRequestVersionInfo(**version_info) @@ -51,7 +51,7 @@ def create(self, details, settings, version_info): raise ApiError("Exception when calling DefaultApi->create_algorithm: %s\n" % e) # Update the settings in an algorithm - def update(self, details, settings, version_info): + def update(self, details={}, settings={}, version_info={}): detailsObj = Details(**details) settingsObj = Settings(**settings) createRequestVersionInfoObj = CreateRequestVersionInfo(**version_info) From aa81ef8437fe84d19df1c78f44fd8dd92c132a45 Mon Sep 17 00:00:00 2001 From: Besir Kurtulmus Date: Mon, 11 Feb 2019 16:26:49 -0800 Subject: [PATCH 10/15] Support custom algorithmia API endpoints --- Algorithmia/client.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Algorithmia/client.py b/Algorithmia/client.py index 5c53c77..7dcfd59 100644 --- a/Algorithmia/client.py +++ b/Algorithmia/client.py @@ -26,6 +26,7 @@ def __init__(self, apiKey = None, apiAddress = None): self.apiAddress = Algorithmia.getApiAddress() config = Configuration() config.api_key['Authorization'] = self.apiKey + config.host = "{}/v1".format(self.apiAddress) self.manageApi = DefaultApi(ApiClient(config)) def algo(self, algoRef): From 0ccdd72c71e1ce18d9a8a500ec6ed3a0507426fd Mon Sep 17 00:00:00 2001 From: Besir Kurtulmus Date: Fri, 22 Feb 2019 14:27:30 -0800 Subject: [PATCH 11/15] Rename the getInfo() to info() for algo(), add algo_hash to info(), and add the versions() method to algo() --- Algorithmia/algorithm.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Algorithmia/algorithm.py b/Algorithmia/algorithm.py index a7514bb..a0f1d56 100644 --- a/Algorithmia/algorithm.py +++ b/Algorithmia/algorithm.py @@ -79,14 +79,27 @@ def publish(self, details={}, settings={}, version_info={}): raise ApiError("Exception when calling DefaultApi->publish_algorithm: %s\n" % e) # Get info on an algorithm - def getInfo(self): + def info(self, algo_hash=None): try: # Get Algorithm - api_response = self.client.manageApi.get_algorithm(self.username, self.algoname) + if algo_hash: + api_response = self.client.manageApi.get_algorithm_hash_version(self.username, self.algoname, algo_hash) + else: + api_response = self.client.manageApi.get_algorithm(self.username, self.algoname) return api_response except ApiException as e: raise ApiError("Exception when calling DefaultApi->get_algorithm: %s\n" % e) + # Get all versions of the algorithm, with the given filters + def versions(self, limit=10, marker=None, published=True, callable=True): + try: + # Get Algorithm versions + api_response = self.client.manageApi.get_algorithm_versions(self.username, self.algoname, limit=limit, marker=marker, published=published, callable=callable) + return api_response + except ApiException as e: + raise ApiError("Exception when calling DefaultApi->get_algorithm_versions: %s\n" % e) + + # Compile an algorithm def compile(self): try: From a30991d2a5b15fdef4e7547e7a7bad98ad41960c Mon Sep 17 00:00:00 2001 From: Besir Kurtulmus Date: Mon, 25 Feb 2019 15:22:43 -0800 Subject: [PATCH 12/15] Use dict unpacking in the .versions() method in .algo() --- Algorithmia/algorithm.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Algorithmia/algorithm.py b/Algorithmia/algorithm.py index a0f1d56..5169c6e 100644 --- a/Algorithmia/algorithm.py +++ b/Algorithmia/algorithm.py @@ -91,10 +91,19 @@ def info(self, algo_hash=None): raise ApiError("Exception when calling DefaultApi->get_algorithm: %s\n" % e) # Get all versions of the algorithm, with the given filters - def versions(self, limit=10, marker=None, published=True, callable=True): + def versions(self, limit=None, marker=None, published=None, callable=None): + kwargs = {} + if limit: + kwargs["limit"] = limit + if marker: + kwargs["marker"] = marker + if published: + kwargs["published"] = published + if callable: + kwargs["callable"] = callable try: # Get Algorithm versions - api_response = self.client.manageApi.get_algorithm_versions(self.username, self.algoname, limit=limit, marker=marker, published=published, callable=callable) + api_response = self.client.manageApi.get_algorithm_versions(self.username, self.algoname, **kwargs) return api_response except ApiException as e: raise ApiError("Exception when calling DefaultApi->get_algorithm_versions: %s\n" % e) From 27f88724c0784c5eb864240ace465f27c37e3e07 Mon Sep 17 00:00:00 2001 From: Besir Kurtulmus Date: Mon, 25 Feb 2019 16:56:33 -0800 Subject: [PATCH 13/15] Return error message instead of debug info in new methods, and pass lowercase for .versions() bool query parameters --- Algorithmia/algorithm.py | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/Algorithmia/algorithm.py b/Algorithmia/algorithm.py index 5169c6e..3e0a36c 100644 --- a/Algorithmia/algorithm.py +++ b/Algorithmia/algorithm.py @@ -1,6 +1,7 @@ 'Algorithmia Algorithm API Client (python)' import base64 +import json import re from Algorithmia.async_response import AsyncResponse from Algorithmia.algo_response import AlgoResponse @@ -48,7 +49,8 @@ def create(self, details={}, settings={}, version_info={}): api_response = self.client.manageApi.create_algorithm(self.username, create_request) return api_response except ApiException as e: - raise ApiError("Exception when calling DefaultApi->create_algorithm: %s\n" % e) + error_message = json.loads(e.body)["error"]["message"] + raise ApiError(error_message) # Update the settings in an algorithm def update(self, details={}, settings={}, version_info={}): @@ -62,7 +64,8 @@ def update(self, details={}, settings={}, version_info={}): api_response = self.client.manageApi.update_algorithm(self.username, self.algoname, update_request) return api_response except ApiException as e: - raise ApiError("Exception when calling DefaultApi->update_algorithm: %s\n" % e) + error_message = json.loads(e.body)["error"]["message"] + raise ApiError(error_message) # Publish an algorithm def publish(self, details={}, settings={}, version_info={}): @@ -76,7 +79,8 @@ def publish(self, details={}, settings={}, version_info={}): api_response = self.client.manageApi.publish_algorithm(self.username, self.algoname, version_request) return api_response except ApiException as e: - raise ApiError("Exception when calling DefaultApi->publish_algorithm: %s\n" % e) + error_message = json.loads(e.body)["error"]["message"] + raise ApiError(error_message) # Get info on an algorithm def info(self, algo_hash=None): @@ -88,7 +92,8 @@ def info(self, algo_hash=None): api_response = self.client.manageApi.get_algorithm(self.username, self.algoname) return api_response except ApiException as e: - raise ApiError("Exception when calling DefaultApi->get_algorithm: %s\n" % e) + error_message = json.loads(e.body)["error"]["message"] + raise ApiError(error_message) # Get all versions of the algorithm, with the given filters def versions(self, limit=None, marker=None, published=None, callable=None): @@ -98,15 +103,22 @@ def versions(self, limit=None, marker=None, published=None, callable=None): if marker: kwargs["marker"] = marker if published: - kwargs["published"] = published + if str(published) == "True": + kwargs["published"] = str(published).lower() + else: + kwargs["published"] = published if callable: - kwargs["callable"] = callable + if str(callable) == "True": + kwargs["callable"] = str(callable).lower() + else: + kwargs["callable"] = callable try: # Get Algorithm versions api_response = self.client.manageApi.get_algorithm_versions(self.username, self.algoname, **kwargs) return api_response except ApiException as e: - raise ApiError("Exception when calling DefaultApi->get_algorithm_versions: %s\n" % e) + error_message = json.loads(e.body)["error"]["message"] + raise ApiError(error_message) # Compile an algorithm @@ -116,7 +128,8 @@ def compile(self): api_response = self.client.manageApi.algorithms_username_algoname_compile_post(self.username, self.algoname) return api_response except ApiException as e: - print("Exception when calling DefaultApi->algorithms_username_algoname_compile_post: %s\n" % e) + error_message = json.loads(e.body)["error"]["message"] + raise ApiError(error_message) # Pipe an input into this algorithm def pipe(self, input1): From 6f71f8cf1a68969c64d91351b7b8be6dc78ace45 Mon Sep 17 00:00:00 2001 From: Besir Kurtulmus Date: Mon, 25 Feb 2019 17:10:44 -0800 Subject: [PATCH 14/15] Additionally support lower casing False in .versions() under .algo() --- Algorithmia/algorithm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Algorithmia/algorithm.py b/Algorithmia/algorithm.py index 3e0a36c..e71b6da 100644 --- a/Algorithmia/algorithm.py +++ b/Algorithmia/algorithm.py @@ -103,12 +103,12 @@ def versions(self, limit=None, marker=None, published=None, callable=None): if marker: kwargs["marker"] = marker if published: - if str(published) == "True": + if str(published) in ["True", "False"]: kwargs["published"] = str(published).lower() else: kwargs["published"] = published if callable: - if str(callable) == "True": + if str(callable) in ["True", "False"]: kwargs["callable"] = str(callable).lower() else: kwargs["callable"] = callable From 314e8e2ca1c6ecbbb1d6f28c804d806b8ffeb43d Mon Sep 17 00:00:00 2001 From: Besir Kurtulmus Date: Mon, 25 Feb 2019 17:24:46 -0800 Subject: [PATCH 15/15] Refactor & simplify logic in .versions() under .algo() thanks to @peckjon --- Algorithmia/algorithm.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/Algorithmia/algorithm.py b/Algorithmia/algorithm.py index e71b6da..3f0b817 100644 --- a/Algorithmia/algorithm.py +++ b/Algorithmia/algorithm.py @@ -98,20 +98,17 @@ def info(self, algo_hash=None): # Get all versions of the algorithm, with the given filters def versions(self, limit=None, marker=None, published=None, callable=None): kwargs = {} + bools = ["True", "False"] if limit: kwargs["limit"] = limit if marker: kwargs["marker"] = marker if published: - if str(published) in ["True", "False"]: - kwargs["published"] = str(published).lower() - else: - kwargs["published"] = published + p = published + kwargs["published"] = str(p).lower() if str(p) in bools else p if callable: - if str(callable) in ["True", "False"]: - kwargs["callable"] = str(callable).lower() - else: - kwargs["callable"] = callable + c = callable + kwargs["callable"] = str(c).lower() if str(c) in bools else c try: # Get Algorithm versions api_response = self.client.manageApi.get_algorithm_versions(self.username, self.algoname, **kwargs)