Route package diagnostics through the logging module#24
Open
thc1006 wants to merge 2 commits into
Open
Conversation
balloon_world.py and evaluate.py emitted diagnostics with bare print(), which cannot be silenced for scoring or CI runs. Replace them with per-module loggers: env termination messages at info level, the close() trace at debug. evaluate_scenario's result lines also become info logs, and the script entry point calls logging.basicConfig so command-line runs still show them. Add tests/test_logging.py, an AST invariant that fails if bare print() reappears in the package sources. Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Routes the package's bare print() diagnostics through the standard logging module so verbosity is controllable (quiet in scoring/CI, verbose when debugging), and adds an AST-based test to prevent regressions.
Changes:
- Add module loggers in
balloon_world.pyandevaluate.py; replaceprint()calls withlogger.info/logger.debug. - Configure
logging.basicConfig(level=INFO)inevaluate.py's__main__block to preserve CLI output. - Add
tests/test_logging.pyAST invariant that fails if any bareprint()reappears in the package.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
BalloonPoppingGymEnv/envs/balloon_world.py |
Replace three print() diagnostics with module logger calls (info/debug). |
BalloonPoppingGymEnv/evaluation/evaluate.py |
Replace two CLI prints with lazy-formatted logger.info; add basicConfig only in __main__. |
tests/test_logging.py |
New AST test enforcing no bare print() in the package. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
evaluate_scenario logged its result through logging but returned None. Library callers (the Colab example, run_env_agent.py) thus lost all visible output once the print() calls became logger calls, since the __main__ logging.basicConfig only covers the script path. Return info["popped_count"] so callers receive the result, and update the Colab notebook and run_env_agent.py to display it. The script entry point's basicConfig now targets stdout to match the old print() behaviour. Add tests/test_evaluate.py to pin the return contract. Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Route the package's bare
print()diagnostics through the standardloggingmodule so verbosity is controllable: quiet during scoring or CI, verbose when debugging. Implements the logging instrumentation thread of #14.What changed
balloon_world.pyandevaluate.pyeach get a module logger (logging.getLogger(__name__)).balloon_world.py: the two env termination messages becomelogger.info, and theclose()trace becomeslogger.debug.evaluate.py:evaluate_scenario's two result lines becomelogger.info(lazy%sformatting). The function now also returnsinfo["popped_count"], so library callers get the result, since the diagnostics are silent unless the caller configures logging. The__main__entry point callslogging.basicConfig(level=INFO, stream=sys.stdout)so runningpython evaluate.py <cfg>still prints results to stdout.doc/examples/run_env_agent.pyand the Colab notebook, now display the returned reward.tests/test_logging.py: an AST invariant that fails if a bareprint()reappears in the package.tests/test_evaluate.py: pinsevaluate_scenario's return contract.Behaviour
Reward computation and env logic are unchanged. Env diagnostics are silent by default (the consumer opts in via
logging);evaluate_scenario's result is available both as a return value and, on the script and configured-logging paths, as log output.The logger uses
getLogger(__name__), so a consumer can control the whole package withlogging.getLogger("BalloonPoppingGymEnv"). This minimal, standard setup composes with any later logging integration.About #14
#14 covered three areas: functional test coverage, logging instrumentation, and a coverage CI workflow. CI and coverage are handled by #21 (PR #23); logging is this PR.
Verified
test_logging.pystarted red (5print()offenders) and went green after the change.test_evaluate.pystarted red (evaluate_scenarioreturnedNone) and went green after.ruff checkandruff format --checkpass; the full test suite passes (11 tests).evaluate_scenarioreturns a real count and the notebook printsTotal reward.Closes #14