Skip to content

Commit f80c81b

Browse files
authored
Merge pull request #2 from algorithmiaio/review
Minor reviews
2 parents ded12e2 + 25c4e3d commit f80c81b

File tree

3 files changed

+43
-44
lines changed

3 files changed

+43
-44
lines changed

adk/ADK.py

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,14 @@
99

1010

1111
class ADK(object):
12-
1312
def __init__(self, apply_func, load_func=None):
1413
"""
1514
Creates the adk object
1615
:param apply_func: A required function that can have an arity of 1-2, depending on if loading occurs
1716
:param load_func: An optional supplier function used if load time events are required, has an arity of 0.
1817
"""
1918
self.FIFO_PATH = "/tmp/algoout"
20-
apply_args, _, _, apply_defaults, _, _, _ = inspect.getfullargspec(apply_func)
21-
# apply_args, _, _, apply_defaults = inspect.getargspec(apply_func)
22-
# j = inspect.getfullargspec(apply_func)
19+
apply_args, _, _, _, _, _, _ = inspect.getfullargspec(apply_func)
2320
if load_func:
2421
load_args, _, _, _, _, _, _ = inspect.getfullargspec(load_func)
2522
if len(load_args) > 0:
@@ -38,16 +35,16 @@ def load(self):
3835
if self.is_local:
3936
print("loading complete")
4037
else:
41-
print('PIPE_INIT_COMPLETE')
38+
print("PIPE_INIT_COMPLETE")
4239
sys.stdout.flush()
4340

4441
def format_data(self, request):
45-
if request['content_type'] in ['text', 'json']:
46-
data = request['data']
47-
elif request['content_type'] == 'binary':
48-
data = self.wrap_binary_data(request['data'])
42+
if request["content_type"] in ["text", "json"]:
43+
data = request["data"]
44+
elif request["content_type"] == "binary":
45+
data = self.wrap_binary_data(request["data"])
4946
else:
50-
raise Exception("Invalid content_type: {}".format(request['content_type']))
47+
raise Exception("Invalid content_type: {}".format(request["content_type"]))
5148
return data
5249

5350
def is_binary(self, arg):
@@ -64,20 +61,20 @@ def wrap_binary_data(self, data):
6461

6562
def format_response(self, response):
6663
if self.is_binary(response):
67-
content_type = 'binary'
68-
response = base64.b64encode(response)
69-
if not isinstance(response, six.string_types):
70-
response = str(response, 'utf-8')
64+
content_type = "binary"
65+
response = str(base64.b64encode(response), "utf-8")
7166
elif isinstance(response, six.string_types) or isinstance(response, six.text_type):
72-
content_type = 'text'
67+
content_type = "text"
7368
else:
74-
content_type = 'json'
75-
response_string = json.dumps({
76-
'result': response,
77-
'metadata': {
78-
'content_type': content_type
69+
content_type = "json"
70+
response_string = json.dumps(
71+
{
72+
"result": response,
73+
"metadata": {
74+
"content_type": content_type
75+
}
7976
}
80-
})
77+
)
8178
return response_string
8279

8380
def write_to_pipe(self, payload):
@@ -88,23 +85,23 @@ def write_to_pipe(self, payload):
8885
print(payload)
8986
else:
9087
if os.name == "posix":
91-
with open(self.FIFO_PATH, 'w') as f:
88+
with open(self.FIFO_PATH, "w") as f:
9289
f.write(payload)
93-
f.write('\n')
90+
f.write("\n")
9491
sys.stdout.flush()
9592
if os.name == "nt":
9693
sys.stdin = payload
9794

9895
def create_exception(self, exception):
99-
if hasattr(exception, 'error_type'):
96+
if hasattr(exception, "error_type"):
10097
error_type = exception.error_type
10198
else:
102-
error_type = 'AlgorithmError'
99+
error_type = "AlgorithmError"
103100
response = {
104-
'error': {
105-
'message': str(exception),
106-
'stacktrace': traceback.format_exc(),
107-
'error_type': error_type
101+
"error": {
102+
"message": str(exception),
103+
"stacktrace": traceback.format_exc(),
104+
"error_type": error_type,
108105
}
109106
}
110107
return response

examples/loaded_state_hello_world/src/Algorithm.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def load():
1515
# The return object from this function can be passed directly as input to your apply function.
1616
# A great example would be any model files that need to be available to this algorithm
1717
# during runtime.
18+
1819
# Any variables returned here, will be passed as the secondary argument to your 'algorithm' function
1920
globals = {}
2021
globals['payload'] = "Loading has been completed."

setup.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
setup(
66
name='algorithmia-adk',
77
version=os.environ.get('ADK_VERSION', '0.0.0'),
8-
description='adk python ADK client',
9-
long_description='adk Development Kit code used for creating Python algorithms on adk. Built into the Algorithmia client',
8+
description='Algorithmia Python ADK client',
9+
long_description='Algorithm Development Kit code used for creating Python algorithms on Algorithmia. '
10+
'Used by the Algorithmia client',
1011
url='http://github.com/algorithmiaio/algorithmia-adk-python',
1112
license='MIT',
1213
author='Algorithmia',
@@ -17,18 +18,18 @@
1718
],
1819
include_package_data=True,
1920
classifiers=[
20-
'Development Status :: 5 - Production/Stable',
21-
'Intended Audience :: Developers',
22-
'Natural Language :: English',
23-
'License :: OSI Approved :: MIT License',
24-
'Operating System :: OS Independent',
25-
'Programming Language :: Python',
26-
'Programming Language :: Python :: 3',
27-
'Programming Language :: Python :: 3.5',
28-
'Programming Language :: Python :: 3.6',
29-
'Programming Language :: Python :: 3.7',
30-
'Programming Language :: Python :: 3.8',
31-
'Programming Language :: Python :: 3.9',
32-
'Topic :: Software Development :: Libraries :: Python Modules',
21+
"Development Status :: 5 - Production/Stable",
22+
"Intended Audience :: Developers",
23+
"Natural Language :: English",
24+
"License :: OSI Approved :: MIT License",
25+
"Operating System :: OS Independent",
26+
"Programming Language :: Python",
27+
"Programming Language :: Python :: 3",
28+
"Programming Language :: Python :: 3.5",
29+
"Programming Language :: Python :: 3.6",
30+
"Programming Language :: Python :: 3.7",
31+
"Programming Language :: Python :: 3.8",
32+
"Programming Language :: Python :: 3.9",
33+
"Topic :: Software Development :: Libraries :: Python Modules",
3334
],
3435
)

0 commit comments

Comments
 (0)