Skip to content

Commit b1bd418

Browse files
authored
Merge pull request #15 from algorithmiaio/manifest-bug-fixes-1
Bug Fixes
2 parents 1e5c6b9 + 35a17a3 commit b1bd418

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

adk/ADK.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def process_local(self, local_payload, pprint):
9494

9595
def init(self, local_payload=None, pprint=print):
9696
self.load()
97-
if self.is_local and local_payload:
97+
if self.is_local and local_payload is not None:
9898
if self.loading_exception:
9999
load_error = create_exception(self.loading_exception, loading_exception=True)
100100
self.write_to_pipe(load_error, pprint=pprint)

adk/modeldata.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66

77
class ModelData(object):
88
def __init__(self, client, model_manifest_path):
9-
self.manifest_path = model_manifest_path
10-
self.manifest_freeze_path = "{}.freeze".format(self.manifest_path)
11-
self.manifest_data = get_manifest(self.manifest_freeze_path, self.manifest_path)
9+
self.manifest_reg_path = model_manifest_path
10+
self.manifest_frozen_path = "{}.freeze".format(self.manifest_reg_path)
11+
self.manifest_data = self.get_manifest()
1212
self.client = client
1313
self.models = {}
1414
self.usr_key = "__user__"
15+
self.using_frozen = True
1516

1617
def __getitem__(self, key):
1718
return getattr(self, self.usr_key + key)
@@ -78,28 +79,32 @@ def find_optional_model(self, file_name):
7879
with self.client.file(source_uri).getFile() as f:
7980
local_data_path = f.name
8081
real_hash = md5_for_file(local_data_path)
81-
if real_hash != expected_hash and fail_on_tamper:
82-
raise Exception("Model File Mismatch for " + file_name +
83-
"\nexpected hash: " + expected_hash + "\nreal hash: " + real_hash)
82+
if self.using_frozen:
83+
if real_hash != expected_hash and fail_on_tamper:
84+
raise Exception("Model File Mismatch for " + file_name +
85+
"\nexpected hash: " + expected_hash + "\nreal hash: " + real_hash)
86+
else:
87+
self.models[file_name] = FileData(real_hash, local_data_path)
8488
else:
8589
self.models[file_name] = FileData(real_hash, local_data_path)
8690

8791

88-
def get_manifest(manifest_frozen_path, manifest_reg_path):
89-
if os.path.exists(manifest_frozen_path):
90-
with open(manifest_frozen_path) as f:
91-
manifest_data = json.load(f)
92-
if check_lock(manifest_data):
92+
def get_manifest(self):
93+
if os.path.exists(self.manifest_frozen_path):
94+
with open(self.manifest_frozen_path) as f:
95+
manifest_data = json.load(f)
96+
if check_lock(manifest_data):
97+
return manifest_data
98+
else:
99+
raise Exception("Manifest FreezeFile Tamper Detected; please use the CLI and 'algo freeze' to rebuild your "
100+
"algorithm's freeze file.")
101+
elif os.path.exists(self.manifest_reg_path):
102+
with open(self.manifest_reg_path) as f:
103+
manifest_data = json.load(f)
104+
self.using_frozen = False
93105
return manifest_data
94106
else:
95-
raise Exception("Manifest FreezeFile Tamper Detected; please use the CLI and 'algo freeze' to rebuild your "
96-
"algorithm's freeze file.")
97-
elif os.path.exists(manifest_reg_path):
98-
with open(manifest_reg_path) as f:
99-
manifest_data = json.load(f)
100-
return manifest_data
101-
else:
102-
return None
107+
return None
103108

104109

105110
def check_lock(manifest_data):

0 commit comments

Comments
 (0)