Skip to content

Commit

Permalink
Make suffix of proc consistent for python2 and python3.
Browse files Browse the repository at this point in the history
  • Loading branch information
pwwang committed Aug 11, 2017
1 parent cd49805 commit 0332ec7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
13 changes: 7 additions & 6 deletions pyppl/helpers/proc.py
Expand Up @@ -3,12 +3,13 @@
"""
import copy as pycopy
import os
import pickle
import sys
import threading
import json
from random import randint
from subprocess import PIPE, Popen
from time import sleep, time
from collections import OrderedDict
try:
from Queue import Queue
except ImportError:
Expand Down Expand Up @@ -393,7 +394,7 @@ def _suffix (self):
for key, val in config['input'].items():
config['input'][key] = utils.funcsig(val) if callable(val) else val

signature = pickle.dumps(str(config))
signature = json.dumps(config, sort_keys = True)
self.props['suffix'] = utils.uid(signature)
return self.suffix

Expand Down Expand Up @@ -534,7 +535,7 @@ def _saveSettings (self):
if key == 'input':
f.write('\n[input]\n')
if not isinstance(val, dict):
f.write('key: ' + str(val) + '\n')
f.write('value: ' + str(val) + '\n')
else:
for k in sorted(val.keys()):
v = val[k]
Expand All @@ -557,19 +558,19 @@ def _saveSettings (self):
f.write (k + '.type: ' + str(v['type']) + '\n')
f.write (k + '.data: \n')
for _ in v['data']:
f.write (' ' + str(_) + '\n')
f.write (' ' + json.dumps(_) + '\n')
elif key in ['lognline', 'args'] or key.endswith('Runner'):
f.write('\n['+ key +']\n')
for k in sorted(val.keys()):
v = val[k]
f.write ((k if k else "''") + ': ' + str(v) + '\n')
f.write ((k if k else "''") + ': ' + json.dumps(v, sort_keys = True) + '\n')
elif key == 'script':
f.write('\n['+ key +']\n')
f.write('value:\n')
f.write(' ' + val.replace('\n', '\n ') + '\n')
else:
f.write('\n['+ key +']\n')
f.write('value: ' + str(val) + '\n')
f.write('value: ' + json.dumps(val, sort_keys = True) + '\n')

self.log ('Settings saved to: %s' % settingsfile, 'debug')

Expand Down
14 changes: 11 additions & 3 deletions pyppl/helpers/utils.py
Expand Up @@ -173,6 +173,8 @@ def format (tpl, args):
s = tpl
m = re.findall ("{{.+?}}", s)

keys = sorted(args.keys())
nkeyPerLine = 8
for n in m:
#nneat = n.strip("{}")
nneat = n[2:-2]
Expand All @@ -181,8 +183,12 @@ def format (tpl, args):
if key.startswith('import ') or key.startswith('from '):
exec (key)
key = parts.pop(0).strip()
if not key in args:
raise KeyError ("No key '%s' found in the data!\nAvailable keys are: %s" % (key, str(args.keys())))
if not key in keys:
stderr.write('No key "%s" found in data.\n' % key)
stderr.write('Available keys are: \n')
for i in range(0, len(keys), nkeyPerLine):
stderr.write (' ' + ', '.join(keys[i:i+nkeyPerLine]) + '\n')
raise KeyError

value = args[key]
while parts:
Expand All @@ -205,7 +211,9 @@ def format (tpl, args):
stderr.write("Failed to evaluate: %s\n" % expstr)
stderr.write("- Key/Func: %s\n" % func)
stderr.write("- Expression: %s\n" % n)
stderr.write("- Avail keys: %s\n" % args.keys())
stderr.write("- Avail keys:\n")
for i in range(0, len(keys), nkeyPerLine):
stderr.write (' ' + ', '.join(keys[i:i+nkeyPerLine]) + '\n')
raise

s = s.replace (n, str(value))
Expand Down

0 comments on commit 0332ec7

Please sign in to comment.