Guide de développement CLI mlcflow

VérifiéSûr

Apprenez à étendre l'interface CLI mlcflow en ajoutant des commandes, des branches de répartition, la validation meta.yaml et des codes d'erreur.

Spar Skills Guide Bot
DeveloppementAvancé
22/07/2026
Claude Code
#cli#python#codebase-guide#mlcommons#error-handling

Recommandé pour

Synthèse automatique

Guide de travail pour modifier et déboguer le dépôt mlcflow, le pilote CLI du framework d'automatisation MLCommons.

Points forts

  • Fournit un modèle mental explicite de la chaîne d'appel, de `mlcr <tags>` jusqu'à `ScriptAutomation.run`
  • Donne des playbooks fichier par fichier pour ajouter une commande, une branche de dispatch, une clé de schéma ou un code d'erreur
  • Inclut une procédure de diagnostic ordonnée (`--verbose`, `mlc find`, `mlc reindex`, purge du cache) pour les échecs d'exécution et d'indexation
  • Rappelle le contrat de retour `{'return': 0}` / `{'return': N, 'error': ...}` que chaque action doit respecter

Limites

  • Très spécifique à mlcflow : suppose le dépôt cloné et `mlperf-automations` enregistré dans les repos
  • Ne couvre ni les tests, ni le style de code, ni le processus de contribution (renvoie à AGENTS.md)
  • Les numéros de ligne indiqués (par ex. ~363, ~393) peuvent se périmer au fil des évolutions du fichier
Quand l'utiliser

À utiliser lorsqu'on ajoute une commande ou un branchement dans mlcflow, ou qu'on cherche pourquoi un `mlcr` ou un index échoue.

Quand l'éviter

À éviter pour écrire les scripts d'automatisation eux-mêmes ou pour toute tâche hors du dépôt mlcflow.

Analyse de sécurité

Sûr
Score qualité90/100

The skill is a development guide for the mlcflow CLI. It contains code snippets and debugging commands, but none are destructive, exfiltrating, or obfuscated. Commands like 'mlc rm cache --tags' are cache management within the tool's own ecosystem. No use of curl|sh, rm -rf /, token exfiltration, or disabling safety mechanisms.

Aucun point d'attention détecté

Comment cette analyse est faite

Exemples

Add a new mlc command
Add a new `mlc docker-build` command to mlcflow that delegates to ScriptAutomation, and register it in build_parser() so it shows up in the general command group.
Debug a failing mlcr run
`mlcr my-script --tags=resnet` keeps failing with a ScriptExecutionError. Walk me through diagnosing it: verbose output, checking the script index, and clearing stale cache entries.
New meta.yaml validation key
I want to add a new top-level `cache_timeout` key to meta.yaml and have indexing validate it. Show me where to add it in meta_schema.py and which type constant to use.

skill.md — Claude working guide for mlcflow

Compact task playbooks. Read AGENTS.md for full technical detail.


Mental model

mlcr <tags>  →  mlc_expand_short("run")  →  main()
  →  get_action("script", parent)  →  ScriptAction.run(run_args)
    →  call_script_module_function("run", run_args)
      →  find_target_folder("script")        # walks registered repos
      →  dynamic_import_module(module.py)    # loads ScriptAutomation
      →  ScriptAutomation(self, path).run(run_args)   # engine in mlperf-automations

This repo = CLI driver only. Script logic lives in mlperf-automations/automation/script/module.py, loaded at runtime.

Result dict contract — every action method must return:

  • {'return': 0} on success
  • {'return': N, 'error': 'message'} on failure (N > 0)

Task playbooks

"I need to add a new mlc command"

  1. Add method to the appropriate Action class (hyphens → underscores in name):

    # script_action.py — for a command that delegates to ScriptAutomation
    def my_action(self, run_args):
        return self.call_script_module_function("my_action", run_args)
    
    # script_action.py — for a command handled entirely in mlcflow
    def my_action(self, run_args):
        self.action_type = "script"
        res = self.search(run_args)
        # ... do work ...
        return {'return': 0}
    
  2. Register the command in build_parser() (main.py):

    # General (script/cache/repo): add to the first for-loop ~line 363
    for action in ['run', 'pull', ..., 'my-action']:
    # Script-only: add to the second for-loop ~line 393
    for action in ['docker', ..., 'my-action']:
    
  3. (Optional) Add a short command in main.py + pyproject.toml:

    def mlcx():
        mlc_expand_short("my-action")
    
    mlcx = "mlc.main:mlcx"
    

"I need to add a new dispatch branch for ScriptAutomation"

In call_script_module_function() (script_action.py), add an elif branch:

elif function_name == "my_action":
    result = automation_instance.my_action(run_args)

"I need to add validation for a new meta.yaml key"

In meta_schema.py:

# Add to TOP_LEVEL_SCHEMA (top-level keys):
"my_new_key": DICT,   # or STR, LIST, BOOL, etc.

# Add to DEP_ENTRY_SCHEMA if it goes inside a dep entry
# Add to VARIATION_ENTRY_SCHEMA if it goes inside a variation

Types are sets like STR = {"str"}, LIST = {"list"}, etc. validate_meta() is called during indexing — errors halt the index build.

"I need to add a new error code or improve error messages"

In error_codes.py:

class ErrorCode(Enum):
    MY_ERROR = (2008, "Description of the error")

To show actionable suggestions to the user, add a branch in get_error_guidance():

elif "my error pattern" in message:
    guidance["error_message"] = "Likely cause"
    guidance["suggestions"] = ["Do X to fix it."]

Error codes 2000–2007 are used; warning codes 1000–1006 are used. Pick the next available number in each range.

"I need to understand why mlcr <tags> fails"

mlcr <tags> --verbose                    # full debug output including ScriptAutomation logs
mlc find script --tags=<tags>            # verify script is indexed
mlc reindex                              # rebuild index if stale
mlc list repo                            # verify mlperf-automations is registered
mlc find cache --tags=<failing-dep>      # check if a dep is stale
mlc rm cache --tags=<failing-dep>        # clear dep cache

Check for ScriptExecutionError in the output — it prints a rerun command, the error code, likely cause, suggestions, and version info file path.

"I need to debug why the index is not picking up a script"

  1. Check meta.yaml has all four required keys: alias, uid, automation_alias, automation_uid
  2. Run mlc reindex to force a full rebuild
  3. Check ~/MLC/repos/index_script.json directly if needed
  4. Run mlcr <tags> --verbose — validation errors are logged during indexing

"I need to understand how args reach the automation engine"

convert_args_to_dictionary() in utils.py parses sys.argv extras:

  • --key=val → {"key": "val"}
  • --flag → {"flag": True}
  • --adr.compiler.tags=gcc → {"adr": {"compiler": {"tags": "gcc"}}}
  • -v → {"v": True} (unless it matches log_flag_aliases)

The resulting run_args dict is passed directly to ScriptAutomation.run().

"I need to call mlcflow from Python"

from mlc.action import access

result = access({
    'action': 'run',
    'target': 'script',
    'tags': 'detect,os'
})
if result['return'] > 0:
    print(result['error'])

Or use the instance method on an Action object:

from mlc.action import Action
a = Action()
result = a.access({'action': 'find', 'target': 'script', 'tags': 'detect,os'})

"I need to write a test"

Look at existing tests for patterns:

tests/test_cache_mark_tmp.py
tests/test_action_invalid_meta_entries.py

Run tests with:

pip install -e .
python -m pytest tests/

Quick reference: key classes and where they live

| Class / function | File | What it does | |---|---|---| | main() | main.py | CLI entry point; parses args, dispatches to action | | mlcr(), mlcd(), … | main.py | Short-form entry points registered in pyproject.toml | | get_action(target, parent) | action_factory.py | Maps "script"/"cache"/"repo" → Action class | | Action | action.py | Base: repo loading, index, CRUD (add/rm/cp/mv/search) | | Action.access(i) | action.py | Python API: call any action programmatically | | ScriptAction | script_action.py | Script actions; delegates to ScriptAutomation via call_script_module_function | | ScriptExecutionError | script_action.py | Exception with script context; formatted by _report_error() | | RepoAction | repo_action.py | pull/add/rm/find for repos | | CacheAction | cache_action.py | find/rm/show/prune/list/mark-tmp for caches | | Index | index.py | Incremental tag-based index; file-locked JSON | | validate_meta() | meta_schema.py | Validates script meta.yaml; called during indexing | | get_error_guidance() | error_codes.py | Pattern-matches error text → actionable suggestions | | get_new_uid() | utils.py | Generates a 16-hex UID |


Don'ts

  • Don't raise exceptions for recoverable errors in action methods — return {'return': 1, 'error': '...'}
  • Don't call print() for user-facing messages — use logger.info/warning/error
  • Don't add . in flat arg key names — . triggers nested dict parsing in convert_args_to_dictionary()
  • Don't push directly to main — open a PR; use dev only for urgent merges without approval
  • Don't hard-code ~/MLC/repos — use self.repos_path (which reads MLC_REPOS env var)
  • Don't edit index_script.json or modified_times.json by hand — use mlc reindex
  • Don't call ScriptAutomation directly — always go through call_script_module_function()

Du fichier au premier essai

Le téléchargement contient exactement le contenu affiché sur cette fiche. Cette copie peut différer de la dernière version du dépôt source.

Consulter la source et ses fichiers annexes

Ce téléchargement contient uniquement SKILL.md. Les scripts, références, modèles et dépendances éventuels ne sont pas inclus. Récupérez les fichiers nécessaires depuis la source en conservant leur arborescence avant de poursuivre.

1. Télécharger le fichier

Télécharger SKILL.md

Depuis la racine d’un projet de test, enregistrez le fichier sous .skill-downloads/mlcflow-cli-development-guide-mrwakda7/SKILL.md, ou utilisez la commande suivante. Ce dossier sert à examiner la skill avant son installation.

Commande pour macOS/Linux ou WSL : un shell POSIX et curl sont nécessaires. Sous Windows sans WSL, utilisez le bouton de téléchargement et créez le dossier manuellement.

mkdir -p '.skill-downloads/mlcflow-cli-development-guide-mrwakda7' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/mlcflow-cli-development-guide-mrwakda7/download' --output '.skill-downloads/mlcflow-cli-development-guide-mrwakda7/SKILL.md.part' && mv '.skill-downloads/mlcflow-cli-development-guide-mrwakda7/SKILL.md.part' '.skill-downloads/mlcflow-cli-development-guide-mrwakda7/SKILL.md'

2. Vérifier les prérequis

Lisez SKILL.md avant de l’utiliser. Si le fichier cite des scripts ou services externes, examinez-les et préparez les accès nécessaires dans votre environnement de test.

Extrait original : Quick reference: key classes and where they live
Class / functionFileWhat it does
main()main.pyCLI entry point; parses args, dispatches to action
mlcr(), mlcd(), …main.pyShort-form entry points registered in pyproject.toml
get_action(target, parent)action_factory.pyMaps "script"/"cache"/"repo" → Action class
Actionaction.pyBase: repo loading, index, CRUD (add/rm/cp/mv/search)
Action.access(i)action.pyPython API: call any action programmatically
ScriptActionscript_action.pyScript actions; delegates to ScriptAutomation via call_script_module_function
ScriptExecutionErrorscript_action.pyException with script context; formatted by _report_error()
RepoActionrepo_action.pypull/add/rm/find for repos
CacheActioncache_action.pyfind/rm/show/prune/list/mark-tmp for caches
Indexindex.pyIncremental tag-based index; file-locked JSON
validate_meta()meta_schema.pyValidates script meta.yaml; called during indexing
get_error_guidance()error_codes.pyPattern-matches error text → actionable suggestions
get_new_uid()utils.pyGenerates a 16-hex UID

Les plateformes de la fiche sont des indications du catalogue. Les chemins ci-dessous suivent la documentation des outils ; ils ne prouvent pas que cette skill y a été exécutée. Aucune version minimale de ces outils n’est attestée pour cette fiche.

3. Charger la skill

Le fichier ne fournit pas un en-tête name/description exploitable pour cette procédure native. Le téléchargement reste disponible pour lecture ; utilisez le mode manuel ci-dessous.

Mode manuel ou autre outil : joignez SKILL.md à une conversation, ou ouvrez-le dans un agent capable de lire les fichiers. Ajoutez les ressources annexes nécessaires. Il n’existe pas de dossier universel reconnu par tous les outils.

4. Faire un premier essai

Utilisez une entrée courte et fictive : un endpoint d’API, un petit document ou un brief d’interface. Dans une nouvelle conversation, joignez le fichier ou donnez son chemin à l’agent, puis adaptez cette demande :

Lis .skill-downloads/mlcflow-cli-development-guide-mrwakda7/SKILL.md et applique ses instructions à cet exemple : [décrire une entrée de test]. Indique les fichiers, dépendances ou accès qui manquent. Produis le résultat demandé par la skill sans inventer de données ni exécuter de script non examiné.

Résultat attendu : une sortie correspondant aux instructions de la skill, ou une liste précise des prérequis manquants. Une simple confirmation de lecture ne valide pas le premier usage. Si une ressource externe est indisponible, ce parcours reste à tester.

Skills similaires