Skip to content

fix(guard,#11962): detect_ascii_flowchart.py --json warning-flood casse la sortie JSON sur scope large #15171

Closed

Description

@jsboige

Contexte

scripts/notebook_tools/detect_ascii_flowchart.py --json MyIA.AI.Notebooks/ (scope global) produit une sortie non parseable : json.loads rate avec JSONDecodeError: Expecting value: line 1 column 1 (char 0).

Cause : warnings nbformat DuplicateCellId: Non-unique cell id '' detected. Corrected to 'XXXXX' émis sur stderr via warnings.warn. En capture pipe (... | python -c "json.loads(sys.stdin.read())"), le buffer interleaves stderr+stdout sur Windows → le { initial du JSON se retrouve précédé de lignes de warning.

Vérif first-hand (c.985 myia-po-2024, 2026-09-08T04:35Z) :

  • python scripts/notebook_tools/detect_ascii_flowchart.py --json MyIA.AI.Notebooks/Search (182 fichiers) → JSON valide, 0 findings
  • python scripts/notebook_tools/detect_ascii_flowchart.py --json MyIA.AI.Notebooks/QuantConnect (278 fichiers) → JSON valide, 1 finding sur QC-Py-01_output
  • python scripts/notebook_tools/detect_ascii_flowchart.py --json MyIA.AI.Notebooks/ (corpus global) → JSONDecodeError (les warnings DuplicateCellId s'accumulent avant que le { initial atteigne le parser)

Acceptance

  • detect_ascii_flowchart.py --json MyIA.AI.Notebooks/ rend une sortie strictement parseable (json.loads exit 0), quelque soit le volume de warnings nbformat générés sur le scope.
  • Aucun warning parasite dans stdout en mode --json.
  • Comportement inchangé en mode texte (sortie stdout verbeuse).
  • Tests : ajouter un test unitaire qui scanne un scope multi-dossier (≥3 sous-arbres) et vérifie json.loads() exit 0 sur la sortie.

Fix candidat

import io
import contextlib
import warnings

# En tête du script, autour de nbformat.validate(nb) ou de la lecture notebook :
with contextlib.redirect_stderr(io.StringIO()):
    nb = nbformat.read(path, as_version=4)
# OU
warnings.filterwarnings('ignore', category=UserWarning, module='nbformat')

Note : 13 PRs touchent déjà detect_ascii_flowchart.py (#11964, #11998, #12001, #12010, #12011, #12105, #12120, #12166, #12637, #12729, #13099, #13699, #13890, #14572, #14582). Aucune ne fix ce bug spécifique. C'est un cas de scope large non couvert par les tranches par famille.

Liens

— lane myia-po-2024:CoursIA-2 — c.985

Activity

  1. jsboige commented on Sep 8, 2026

    @jsboige
    OwnerAuthor

    [CLAIMED] #15171 — myia-po-2026:CoursIA — 2026-09-08T07:2xZ — fix(guard,#11962): redirect_stderr/filterwarnings nbformat pour que --json sur scope global rende une sortie strictement parseable (json.loads exit 0), warnings hors stdout en mode --json, comportement texte inchangé, + test unitaire multi-sous-arbres. Grain: MED/guard -- prev: MED/tooling #15092.

  2. jsboige commented on Sep 8, 2026

    @jsboige
    OwnerAuthor

    Livraison : PR #15179 (grain MED/guard, lane myia-po-2026:CoursIA, prev MED/notebook-python #15071).

    Cause racine reproduite firsthand puis fixee a la source : nbformat emet DuplicateCellId (nbformat.warnings.DuplicateCellId, classe Warning — PAS UserWarning) a la lecture des notebooks a ids de cellules non-uniques. filterwarnings('ignore', module='^nbformat') autour de nbformat.read neutralise la categorie ; la detection est inchangee, la garde par-fichier #12097 intacte. Acceptance 4/4 : --json strictement parseable (scope multi-sous-arbres + scan reel corpus 1239 fichiers), aucun warning dans stdout, mode texte inchange, test unitaire ajoute (2 tests : json.loads exit 0 via stderr=STDOUT + absence de residu). 27 passed sur la suite du module (25 preexistants + 2). Fix annexe #12811 (encoding explicite sur le subprocess du test corpus baseline). Closes #15171.

  3. added a commit that references this issue on Sep 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions