Skip to content

feat: silence non-Colab setup_colab() message on plain CLI runs #156

Closed

Description

@Jammy2211

Overview

Every workspace start_here.py calls setup_colab.for_<project>(...) unconditionally, so outside Colab the except ImportError branch of _colab_setup prints a five-line "You are not running in a Google Colab environment" reassurance on every single CLI run, forever. In a notebook the message earns its place (the user just ran a setup cell that was a no-op); on the command line it is pure noise. This task makes the message context-aware: silent on the plain-interpreter path, still surfaced on the notebook-facing path.

Plan

  • Detect the execution context inside _colab_setup's non-Colab branch: an active IPython interactive shell (Jupyter notebook / IPython kernel) means the message still prints; a plain interpreter run means it does not.
  • On the plain-interpreter path, demote the message to logger.debug so it stays retrievable on request instead of vanishing entirely.
  • The change lands wholly in autonerves/setup_colab.py — no workspace start_here.py bootstrap block is touched, so the fix applies uniformly to all six _PROJECTS entries and every workspace repo without per-repo edits.
  • Assert the Witness in test_autonerves/test_setup_colab.py: the CLI path prints nothing on stdout; the notebook path still prints the block.

Design choice, with reason: the prompt's Witness requires both a silent CLI run and a notebook path that still surfaces the message — only execution-context detection satisfies both. Print-once dedup, a persisted marker, or a bare log-demotion would either silence the notebook path too or leave first-run noise on the CLI; an env-var opt-out leaves the default noisy. Log-demotion is kept as the complement on the silent path so the text remains available (logging.DEBUG).

Detailed implementation plan

Affected Repositories

  • PyAutoNerves (primary, only)

Branch Survey

Repository Current Branch Dirty?
./PyAutoNerves main clean

(web-github session: fresh clone, no local worktrees.)

Suggested branch: feature/silence-colab-cli-message

Implementation Steps

  1. autonerves/setup_colab.py: add import sys at module top and a module-level helper _running_in_ipython() -> bool that returns True only when IPython is already in sys.modules and IPython.get_ipython() returns a live shell. Checking sys.modules first means a plain CLI run pays no import cost and a merely-installed-but-inactive IPython does not count.
  2. In _colab_setup's except ImportError branch, build the existing message once, then: print(message) when _running_in_ipython() is True, else logger.debug(message); return as before.
  3. test_autonerves/test_setup_colab.py (TestOutsideColab):
    • Update test_setup_is_a_noop → the Witness test: with no active IPython (delete IPython from sys.modules via monkeypatch), setup_colab.setup(...) installs/clones nothing and prints nothing on stdout.
    • New test: with a stub IPython module in sys.modules whose get_ipython() returns a shell object, the message still prints (notebook-facing path).
    • New test: with a stub IPython whose get_ipython() returns None (IPython installed/imported but not driving the session), stdout stays silent.
    • New test: the silent path emits the message at DEBUG level on the autonerves.setup_colab logger (caplog).

Key Files

  • autonerves/setup_colab.py — _colab_setup non-Colab branch; new _running_in_ipython helper
  • test_autonerves/test_setup_colab.py — Witness + context tests

Interactions checked

  • autonerves/workspace.py::_warn_once is a different emitter (warnings.warn, version staleness) and is untouched; no conflict with its dedup pattern.
  • The message is shared by all six _PROJECTS entries, so the change applies uniformly.

Work Classification

Library

Worktree root

n/a (web-github session — no local worktree; work happens on the session clone)

Original Prompt

Click to expand starting prompt

Silence the non-Colab setup_colab() message on CLI runs

Type: feature
Target: PyAutoNerves
Difficulty: small
Autonomy: safe
Priority: normal
Witness: a plain CLI run of a workspace start_here.py prints no "You are not running in a Google Colab environment" block on stdout, while the notebook-facing path still surfaces it; asserted by a test in PyAutoNerves/test_autonerves/test_setup_colab.py.

Every workspace start_here.py calls setup_colab.for_<project>(...) unconditionally at the top of the script, before any imports. Outside Colab that call falls into the except ImportError branch of _colab_setup in PyAutoNerves/autonerves/setup_colab.py and print()s a five-line reassurance:

You are not running in a Google Colab environment so cannot use the setup_colab() function.

You should therefore have &lt;project&gt; installed locally in your environment already (e.g. via pip or
conda) and can run the rest of your script normally.

You may now continue running your script or Notebook.

For a command-line user this is noise on every single run, forever. In a Jupyter notebook it earns its place: a user who has just executed the Colab setup cell locally does need to be told the cell was a no-op and that they can carry on.

The design question this task exists to answer is: how does a user who genuinely needs this message still get it, without it printing on every run? Weigh at least these, and pick one with a stated reason rather than silently defaulting:

  • Detect execution context (notebook / IPython kernel vs plain interpreter) and stay silent on the command-line path.
  • Print once per process or per session, deduped the way autonerves/workspace.py::_warn_once already dedupes the workspace version warning.
  • Suppress after a persisted marker shows the user has seen it once.
  • Demote to logger.debug / logger.info, so it is available when asked for and invisible otherwise.
  • An explicit opt-out environment variable / config key, as a fallback or in combination.

Notes for whoever picks this up:

  • The message is a print(), not a warning — it cannot be silenced with warnings.filterwarnings.
  • The warnings.warn(message) line that appeared directly above this block in the reported terminal output is a different emitter: autonerves/workspace.py::_warn_once, the workspace-staleness version check. It is not part of this task, though it is worth confirming the chosen approach here does not conflict with the dedup pattern already used there.
  • The change lands wholly in autonerves/setup_colab.py. The workspace start_here.py bootstrap blocks should not need editing, and preferably should not be — the same block is duplicated across every topic folder of every workspace repo, so a fix that requires touching them does not scale.
  • The message is shared by all six registered projects in the _PROJECTS table, so whatever is chosen applies uniformly, not per project.

Activity

  1. Jammy2211 commented on Aug 31, 2026

    @Jammy2211
    CollaboratorAuthor

    Library PR created

    Workspace-impact recommendation (--auto — run ends at PR-open, no merge): (iii) no workspace work needed.

    Data: the API-changes block has no Removed/Renamed/Changed-Signature entries — the only change is that setup_colab stops printing its non-Colab reassurance on plain CLI runs (still printed in notebooks, logged at DEBUG otherwise). Every workspace start_here.py keeps calling setup_colab.for_<project>(...) unchanged, so no script migration or new demos arise. The captured copies of the message in autolens_workspace/autogalaxy_workspace markdown/**/start_here.md are nbconvert kernel renders (the notebook path), so markdown regeneration still contains it — no doc drift. Expected visible effect, already noted in the batch record's expected-effects at dispatch: workspace smoke logs become quieter. Smoke itself was n/a in this web container (no workspace checkouts); the changed surface is asserted directly by the Witness test and a live CLI run.

    Next human step: validate the checklist on the PR and merge (or amend/reject), then /prm closes the task out.


    Generated by Claude Code

  2. added a commit that references this issue on Sep 1, 2026
    94f9fb7
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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions