Fix broken logging integration in __init__.py and __main__.py#3
Fix broken logging integration in __init__.py and __main__.py#3Theblackdragon5 merged 2 commits intomainfrom
Conversation
Agent-Logs-Url: https://github.com/administer-org/aos/sessions/c3c1a37f-bfcd-4c27-9749-295b1bc9002c Co-authored-by: Theblackdragon5 <130586375+Theblackdragon5@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Restores AOS startup/CLI usability by fixing syntax/runtime issues introduced by recent logging changes (indentation errors preventing import and a conditionally-defined logger causing runtime failures).
Changes:
- Fixes indentation issues that caused
IndentationErrorinAOS/__init__.pyandAOS/__main__.py. - Removes accidental shadowing of stdlib
loggingand ensuresloggeris defined at module scope inAOS/__main__.py. - Cleans up redundant
loggingimports and makes logging configuration/logger initialization consistent inAOS/__init__.py.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
AOS/__main__.py |
Fixes logging import/shadowing, ensures logger is always defined, and repairs indentation in the --nobox block. |
AOS/__init__.py |
Removes redundant imports and fixes indentation in exception fallback while centralizing logging setup. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| logging.basicConfig(level=logging.INFO) | ||
| logger = logging.getLogger(__name__) | ||
|
|
||
| from sys import argv | ||
| from pathlib import Path | ||
| from typing import Optional |
There was a problem hiding this comment.
logging.basicConfig(...) and logger = ... are executed before several remaining imports (from sys import argv, from pathlib import Path, etc.), which will trigger flake8/ruff E402 (“module level import not at top of file”). Consider moving these remaining imports above the logging configuration, or moving the logging configuration below all imports so the import block stays contiguous.
| import logging | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
| console = Console() |
There was a problem hiding this comment.
pyproject.toml defines the console script entrypoint as AOS.__main__:main, but this module currently has no main() function, and it executes CLI logic at import time. This will make aos fail with AttributeError: module 'AOS.__main__' has no attribute 'main'. Add a main() function and move the module-level CLI logic into it (optionally calling it under if __name__ == "__main__":).
The logging additions introduced two
IndentationErrors (preventing import entirely) and aNameErrorat runtime from a conditionally-definedloggerused at module scope.AOS/__init__.pyimport loggingstatements (was imported 3×)except Exception as c_exception:block —il.cprint()andlogger.warning()had 20/16 spaces instead of 12, causing anIndentationErrorAOS/__main__.pyfrom AOS.utils import logging as logging— this shadowed stdlibloggingwith the AOS utility module (which only exposesprocess_command, notgetLogger)logger = logging.getLogger(__name__)to module level — it was scoped insideif var.logging_location is None:, sologger.*calls outside that branch raisedNameErrorimport logging as Pythonloggingalias with plainimport logging; updated the one call site accordinglyif "--nobox" not in argv:body —il.box()andlogger.info()were not indented into the block, causingIndentationErrorOriginal prompt
📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.