fix(agents): allow orchestrator.py to run as a direct script#275
Conversation
There was a problem hiding this comment.
Code Review
This pull request modifies agents/orchestrator.py to include a manual sys.path adjustment for handling imports when the script is run directly. The review feedback correctly identifies this as a maintenance anti-pattern that can lead to module shadowing and suggests using the standard python -m execution method instead.
| if __package__ in {None, ""}: | ||
| sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) |
There was a problem hiding this comment.
Manually manipulating sys.path is generally considered a maintenance anti-pattern in Python. It can lead to unexpected side effects such as module shadowing (where a local file unintentionally overrides a standard library or third-party module) and makes the code fragile if the directory structure changes. The standard and recommended way to execute a script within a package is to use the -m flag from the project root: python -m agents.orchestrator. This approach correctly sets up the module search path and handles absolute imports without requiring manual overrides in the source code.
Motivation
python agents/orchestrator.pyfrom the repository root causedModuleNotFoundError: No module named 'agents'because absolute imports failed whensys.path[0]pointed at theagents/package.Description
__package__is empty, prepend the repository root tosys.pathby insertingstr(Path(__file__).resolve().parent.parent), ensuringfrom agents.*imports resolve when the orchestrator is executed directly.Testing
python agents/orchestrator.pyand the orchestrator executed end-to-end without the import error (script completed successfully).Codex Task