Skip to content

Commit

Permalink
v2.3.6: regular improvements and bug fixes (#1337)
Browse files Browse the repository at this point in the history
- Fix type of "unknown_keys" to list to be serializable:
#1335
- Added support to print warning instead of error:  (useful for help)
  • Loading branch information
gfursin authored Oct 21, 2024
2 parents 149cfba + d8b1929 commit fae4468
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 32 deletions.
6 changes: 6 additions & 0 deletions cm/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## V3.2.6
- Fix type of "unknown_keys" to list to be serializable
https://github.com/mlcommons/ck/issues/1335
- Added support to print warning instead of error
(useful for help)

## V3.2.5
- CMX: improved logging
- CMX: improved error handling (show module path and line number)
Expand Down
2 changes: 1 addition & 1 deletion cm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ across diverse models, data sets, software and hardware.

CM is a part of [Collective Knowledge (CK)](https://github.com/mlcommons/ck) -
an educational community project to learn how to run emerging workloads
in the most efficient and cost-effictive way across diverse
in the most efficient and cost-effective way across diverse
and continuously changing systems.

CM includes a collection of portable, extensible and technology-agnostic automation recipes
Expand Down
2 changes: 1 addition & 1 deletion cm/cmind/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Written by Grigori Fursin

__version__ = "3.2.5"
__version__ = "3.2.6"

from cmind.core import access
from cmind.core import x
Expand Down
69 changes: 40 additions & 29 deletions cm/cmind/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ def error(self, r):
if self.debug:
raise Exception(r['error'])

sys.stderr.write('\n'+self.cfg['error_prefix']+' '+r['error']+'!\n')
text = self.cfg['error_prefix'] + ' ' + r['error'] + '!\n'

sys.stderr.write(f'\n{text}')

return r

Expand All @@ -159,39 +161,44 @@ def errorx(self, r):
if self.debug:
raise Exception(r['error'])

module_path = r.get('module_path', '')
lineno = r.get('lineno', '')
if 'warning' in r:
message = r.get('warning', '')
if message != '':
message = '\nCMX warning: ' + message.capitalize() + '!\n'
else:
module_path = r.get('module_path', '')
lineno = r.get('lineno', '')

message = ''
message = ''

if not self.logger == None or (module_path != '' and lineno != ''):
call_stack = self.state.get('call_stack', [])
if not self.logger == None or (module_path != '' and lineno != ''):
call_stack = self.state.get('call_stack', [])

if not self.logger == None:
if not self.logger == None:

self.log(f"x error call stack: {call_stack}", "debug")
self.log(f"x error: {r}", "debug")
self.log(f"x error call stack: {call_stack}", "debug")
self.log(f"x error: {r}", "debug")

sys.stderr.write('='*60 + '\n')
sys.stderr.write('^'*60 + '\n')

if not self.logger == None:
sys.stderr.write('CMX call stack:\n')
if not self.logger == None:
sys.stderr.write('CMX call stack:\n')

for cs in call_stack:
sys.stderr.write(f' * {cs}\n')
for cs in call_stack:
sys.stderr.write(f' * {cs}\n')

message += '\n'
else:
message += '\n'
else:
message += '\n'

message += self.cfg['error_prefix2']
message += self.cfg['error_prefix2']

if module_path != '' and lineno !='':
message += f' in {module_path} ({lineno}):\n\n'
else:
message += ': '
if module_path != '' and lineno !='':
message += f' in {module_path} ({lineno}):\n\n'
else:
message += ': '

message += r['error'] + '\n'
message += r['error'] + '\n'

sys.stderr.write(message)

Expand Down Expand Up @@ -1097,7 +1104,7 @@ def _x(self, i, control):
print ('')
print ('Check https://github.com/mlcommons/ck/tree/master/cm/docs/cmx for more details.')

return {'return':0, 'warning':'no action specified'}
return {'return':1, 'warning':'', 'error':'help requested'}

# Load info about all CM repositories (to enable search for automations and artifacts)
if self.repos == None:
Expand Down Expand Up @@ -1292,11 +1299,13 @@ def _x(self, i, control):

# Check if common automation and --help
if (use_common_automation or automation == '') and cm_help:
return print_action_help(self.common_automation,
self.common_automation,
'common',
action,
original_action)
r = print_action_help(self.common_automation,
self.common_automation,
'common',
action,
original_action)

return {'return':1, 'warning':'', 'error':'help requested'}

# If no automation was found we do not force common automation, check if should fail or continue
if not use_common_automation and len(automation_lst)==0:
Expand Down Expand Up @@ -1371,7 +1380,7 @@ def _x(self, i, control):
for d in actions:
print (' * cmx ' + d + ' ' + automation_meta.get('alias','') + ' -h')

return {'return':0, 'warning':'no automation action'}
return {'return':1, 'warning':'', 'error':'help requested'}


if not hasattr(initialized_automation, action):
Expand Down Expand Up @@ -1488,6 +1497,8 @@ def _x(self, i, control):
print ('')
print (delayed_help_api)

return {'return':1, 'warning':'', 'error':'help requested'}

return r


Expand Down
2 changes: 1 addition & 1 deletion cm/cmind/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1936,7 +1936,7 @@ def test_input(i):
r = {'return':0}

if len(i)>0:
unknown_keys = i.keys()
unknown_keys = list(i.keys())
unknown_keys_str = ', '.join(unknown_keys)

x = '' if len(unknown_keys) == 1 else 's'
Expand Down

0 comments on commit fae4468

Please sign in to comment.