Skip to content

Commit

Permalink
fixed action help and flag -h to work with all automations (#1326)
Browse files Browse the repository at this point in the history
## V3.2.2
   - fixed action `help` and flag `-h` to work with all automations:
     #1325
  • Loading branch information
ctuning-admin authored Oct 14, 2024
2 parents b7b811d + 086a698 commit 93ad617
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 21 deletions.
4 changes: 4 additions & 0 deletions cm/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## V3.2.2
- fixed action `help` and flag `-h` to work with all automations:
https://github.com/mlcommons/ck/issues/1325

## V3.2.1
- added `-f` to the CMX core to be backwards compatible
with CM commands like `cm rm cache -f`
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.1"
__version__ = "3.2.2"

from cmind.core import access
from cmind.core import x
Expand Down
46 changes: 26 additions & 20 deletions cm/cmind/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1187,21 +1187,6 @@ def _x(self, i, control):
print_automation = automation_meta.get('alias','') + ',' + automation_meta.get('uid','')
initialized_automation.artifact = print_automation

if not hasattr(initialized_automation, action):
return {'return':4, 'error':f'action "{action}" not found in automation "{print_automation}"'}
else:
# Check if has _cmx extension
if loaded_common_automation:
# By default don't use CMX in the common automation unless has _cmx extension
# (checked later)
automation_use_x = False

if not automation_use_x and hasattr(initialized_automation, action + '_cmx'):
action_addr = getattr(initialized_automation, action + '_cmx')
automation_use_x = True
else:
action_addr = getattr(initialized_automation, action)

# Check action in a class when importing
if use_any_action:
action = 'any'
Expand Down Expand Up @@ -1231,11 +1216,26 @@ def _x(self, i, control):
print ('')

for d in actions:
print (' * cmx ' + d + ' ' + automation_meta.get('alias',''))
print (' * cmx ' + d + ' ' + automation_meta.get('alias','') + ' -h')

return {'return':0, 'warning':'no automation action'}


if not hasattr(initialized_automation, action):
return {'return':4, 'error':f'action "{action}" not found in automation "{print_automation}"'}
else:
# Check if has _cmx extension
if loaded_common_automation:
# By default don't use CMX in the common automation unless has _cmx extension
# (checked later)
automation_use_x = False

if not automation_use_x and hasattr(initialized_automation, action + '_cmx'):
action_addr = getattr(initialized_automation, action + '_cmx')
automation_use_x = True
else:
action_addr = getattr(initialized_automation, action)


# Check if help for a given automation action
delayed_help = False
Expand Down Expand Up @@ -1398,9 +1398,14 @@ def print_db_actions(automation, equivalent_actions, automation_name, cmx = Fals

x = ' ' + automation_name if automation_name!='' else ''

postfix = 'x' if cmx else ''
if cmx:
postfix = 'x'
extra = ' -h'
else:
postfix = ''
extra = ''

print (f' * cm{postfix} ' + s + x)
print (f' * cm{postfix} ' + s + x + extra)

return {'return':0, 'db_actions':db_actions}

Expand All @@ -1409,13 +1414,14 @@ def print_action_help(automation, common_automation, print_automation, action, o

# 20240202:
# Check if already have full path to automation and if not, try to detect it

import inspect

delayed_help = False

try:
path_to_automation = automation.full_path
except:
import inspect

automation_module = inspect.getmodule(automation)
path_to_automation = inspect.getfile(automation_module)

Expand Down

0 comments on commit 93ad617

Please sign in to comment.