Skip to content

Commit 71ad98d

Browse files
John-Braggrobert-closekennydanielJohn Bragg
authored
Dev 314 (#93)
* 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 environment method to CLI and client * CICD fixes Co-authored-by: robert-close <[email protected]> Co-authored-by: Kenny Daniel <[email protected]> Co-authored-by: Kenny Daniel <[email protected]> Co-authored-by: John Bragg <[email protected]>
1 parent 3124fe9 commit 71ad98d

File tree

5 files changed

+36
-3
lines changed

5 files changed

+36
-3
lines changed

Algorithmia/CLI.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,17 @@ 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 get_environment_by_language(self,language,client):
291+
response = client.get_environment(language)
292+
if "error" in response:
293+
return json.dumps(response)
294+
return json.dumps(response['environments'],indent=1)
295+
290296

291297
def list_languages(self, client):
292298
response = client.get_supported_languages()
293299
return response
294-
300+
295301

296302
def getBuildLogs(self, user, algo, client):
297303
api_response = client.algo(user+'/'+algo).build_logs()

Algorithmia/__main__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ 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 getting environment by language name
111+
parser_env = subparsers.add_parser('environment', help = 'environment <language> gets environment info by language')
112+
parser_env.add_argument('language', help='supported language name')
110113

111114
#sub parser for listing languages
112115
subparsers.add_parser('languages', help = 'lists supported languages')
@@ -197,8 +200,13 @@ def main():
197200
for lang in response:
198201
print("{:<25} {:<35}".format(lang['name'],lang['display_name']))
199202

203+
elif args.cmd == 'environment':
204+
response = CLI().get_environment_by_language(args.language,client)
205+
print(response)
206+
200207
elif args.cmd == 'builds':
201208
print(CLI().getBuildLogs(args.user, args.algo, client))
209+
202210
else:
203211
parser.parse_args(['-h'])
204212

Algorithmia/client.py

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

117+
def get_environment(self,language):
118+
url = "/v1/algorithm-environments/edge/languages/"+language+"/environments"
119+
response = self.getHelper(url)
120+
return response.json()
121+
117122
def get_supported_languages(self):
118123
url ="/v1/algorithm-environments/edge/languages"
119124
response = self.getHelper(url)

Test/CLI_test.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,13 @@ def test_auth_cert(self):
170170
self.assertEqual(resultK, key)
171171
self.assertEqual(resultA, address)
172172
self.assertEqual(resultC, cacert)
173+
174+
def test_get_environment(self):
175+
result = CLI().get_environment_by_language("python2",self.client)
176+
print(result)
177+
if("error" in result):
178+
print(result)
179+
self.assertTrue(result is not None and "display_name" in result)
173180

174181
def test_list_languages(self):
175182
result = CLI().list_languages(self.client)

Test/client_test.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ 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_environment(self):
42+
client =Algorithmia.client(api_key=os.environ.get('ALGORITHMIA_API_KEY'))
43+
response = client.get_environment("python2")
44+
print(response)
45+
if("error" in response):
46+
print(response)
47+
self.assertTrue(response is not None and "environments" in response)
48+
4149
def test_get_build_logs(self):
4250
client = Algorithmia.client(api_key=os.environ.get('ALGORITHMIA_API_KEY'))
4351
user = os.environ.get('ALGO_USER_NAME')
@@ -46,8 +54,7 @@ def test_get_build_logs(self):
4654
if "error" in result:
4755
print(result)
4856
self.assertTrue("error" not in result)
49-
50-
57+
5158

5259
def test_edit_org(self):
5360
orgname="a_myOrg84"

0 commit comments

Comments
 (0)