Skip to content

Commit 605fe6d

Browse files
John-Braggrobert-closekennydanielJohn Braggzeryx
authored
Dev 320 (#86)
* INSIGHTS-12 Initial structure of insight functionality * INSIGHTS-12 Added todo statements * INSIGHTS-12 Moved Insights out of client * INSIGHTS-12 Adjusted insight methods to reside in the client class. Removed the ability to collect insights before sending, now the every time the user invokes the collectInsights method, it will also send. This prevents any State issues with the algorithm. * INSIGHTS-12 Added a todo. Tests fail for unknown reasons at this time * INSIGHTS-12 Fixed method call. Added a todo to get url from config if necessary. * INSIGHTS-12 Fixed method call. * INSIGHTS-12 added json serialization. might not be needed * INSIGHTS-12 commented test temporarily * INSIGHTS-12 comment updates and json .encode change * INSIGHTS-12 comment update * INSIGHTS-12 changed method signatures to match documentation https://insights1.enthalpy.click/developers/clients/python#publishing-algorithmia-insights * INSIGHTS-12 Added system property for queue reader url * INSIGHTS-12 Fixed URL to not be https * INSIGHTS-12 minor version update * INSIGHTS-12 revert change * INSIGHTS-12 removed todo * INSIGHTS-12 uncommented test. May start failing again in the pipeline. * INSIGHTS-12 commented test. * INSIGHTS-12 changed version. Removed unused import. * INSIGHTS-12 changed url to include /v1/ * Allow listing of non-data:// files on cli * Allow catting non-data:// files on cli * Fix tests * Adding get build logs to CLI * changing username * changing username * changing username to env variable for unittest * adding get build logs to client * api location fix * reorganizing methods Co-authored-by: robert-close <rclose@algorithmia.io> Co-authored-by: Kenny Daniel <kenny@algorithmia.com> Co-authored-by: Kenny Daniel <3903376+kennydaniel@users.noreply.github.com> Co-authored-by: John Bragg <john.bragg@ruralsource.com> Co-authored-by: James Sutton <1892175+zeryx@users.noreply.github.com>
1 parent ea14d5a commit 605fe6d

6 files changed

Lines changed: 42 additions & 0 deletions

File tree

Algorithmia/CLI.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,13 @@ def cp(self, src, dest, client):
287287
else:
288288
print("at least one of the operands must be a path to a remote data source data://")
289289

290+
def getBuildLogs(self, user, algo, client):
291+
api_response = client.algo(user+'/'+algo).build_logs()
292+
293+
if "error" in api_response:
294+
return json.dumps(api_response)
295+
return json.dumps(api_response['results'], indent=1)
296+
290297
def getconfigfile(self):
291298
if(os.name == "posix"):
292299
#if!windows

Algorithmia/__main__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ def main():
107107
parser_cat.add_argument('path', nargs = '*', help = 'file(s) to concatenate and print')
108108
parser_cat.add_argument('--profile', action = 'store', type = str, default = 'default')
109109

110+
#sub parser for builds
111+
parser_builds = subparsers.add_parser('builds', help = 'builds <user> <algo> gets build logs for algorithm')
112+
parser_builds.add_argument('user')
113+
parser_builds.add_argument('algo',help='algorithm name')
114+
115+
#sub parser for help
110116
subparsers.add_parser('help')
111117
parser.add_argument('--profile', action = 'store', type = str, default = 'default')
112118

@@ -179,6 +185,9 @@ def main():
179185

180186
elif args.cmd == 'cat':
181187
print(CLI().cat(args.path, client))
188+
189+
elif args.cmd == 'builds':
190+
print(CLI().getBuildLogs(args.user, args.algo, client))
182191
else:
183192
parser.parse_args(['-h'])
184193

Algorithmia/algorithm.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ def get_build_logs(self, build_id):
112112
error_message = json.loads(e.body)
113113
raise raiseAlgoApiError(error_message)
114114

115+
def build_logs(self):
116+
url = '/v1/algorithms/'+self.username+'/'+self.algoname+'/builds'
117+
response = json.loads(self.client.getHelper(url).content.decode('utf-8'))
118+
return response
119+
115120

116121
def get_scm_status(self):
117122
try:

Algorithmia/client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ def invite_to_org(self,orgname,username):
114114
response = self.putHelper(url,data={})
115115
return response
116116

117+
117118
# Used to send insight data to Algorithm Queue Reader in cluster
118119
def report_insights(self, insights):
119120
return Insights(insights)

Test/CLI_test.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import unittest
77
import os
8+
import json
89
import Algorithmia
910
from Algorithmia.CLI import CLI
1011
import argparse
@@ -67,6 +68,15 @@ def test_cat(self):
6768
result = CLI().cat([file],self.client)
6869
self.assertEqual(result, fileContents)
6970

71+
def test_get_build_logs(self):
72+
user=os.environ.get('ALGO_USER_NAME')
73+
algo="Echo"
74+
75+
result = json.loads(CLI().getBuildLogs(user,algo,self.client))
76+
if "error" in result:
77+
print(result)
78+
self.assertTrue("error" not in result)
79+
7080

7181
#local to remote
7282
def test_cp_L2R(self):

Test/client_test.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ def test_get_org(self):
3838
response = self.c.get_org("a_myOrg84")
3939
self.assertEqual("a_myOrg84",response['org_name'])
4040

41+
def test_get_build_logs(self):
42+
client = Algorithmia.client(api_key=os.environ.get('ALGORITHMIA_API_KEY'))
43+
user = os.environ.get('ALGO_USER_NAME')
44+
algo = "Echo"
45+
result = client.algo(user+'/'+algo).build_logs()
46+
if "error" in result:
47+
print(result)
48+
self.assertTrue("error" not in result)
49+
50+
4151

4252
def test_edit_org(self):
4353
orgname="a_myOrg84"

0 commit comments

Comments
 (0)