fix: fix package path error.#15
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adjusts import/path handling in the prejudge LLM judging components to address a “package path” import error when executing the tools.
Changes:
- Update
judge_llm.pyto addsrc/prejudgetosys.pathand importJudgeAgentviafrom judge_agent import JudgeAgent. - Update
judge_agent.pyto addsrc/prejudgetosys.pathand switch imports tofrom judge_tools .../from judge_prompt ....
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/prejudge/judge_llm.py |
Changes path setup and imports to load JudgeAgent as a top-level module. |
src/prejudge/judge_agent.py |
Adds import-time sys.path mutation and switches to top-level sibling imports for internal modules. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # Add the directory containing judge_agent to path | ||
| _prejudge_path = Path(__file__).parent | ||
| if str(_prejudge_path) not in sys.path: | ||
| sys.path.insert(0, str(_prejudge_path)) | ||
|
|
||
| from prejudge.judge_agent import JudgeAgent | ||
| from judge_agent import JudgeAgent |
There was a problem hiding this comment.
Importing sibling modules by mutating sys.path and then using top-level imports (e.g., from judge_agent import JudgeAgent) makes prejudge behave differently depending on execution context, and can shadow/override unrelated modules named judge_agent. Since src/prejudge is a real package (has __init__.py), prefer package-relative imports (e.g., from .judge_agent import JudgeAgent) and avoid modifying sys.path here; if direct CLI execution is needed, prefer python -m prejudge.judge_llm / setting PYTHONPATH=src at the entrypoint instead of per-function path hacks.
| # Add current directory to path for imports | ||
| _prejudge_path = Path(__file__).parent | ||
| _src_path = Path(__file__).parent.parent | ||
| if str(_prejudge_path) not in sys.path: | ||
| sys.path.insert(0, str(_prejudge_path)) | ||
| if str(_src_path) not in sys.path: | ||
| sys.path.insert(0, str(_src_path)) | ||
|
|
||
| from prejudge.judge_tools import create_locate_symbol_tool, create_view_code_tool | ||
| from prejudge.judge_prompt import JUDGE_SYSTEM_PROMPT, JUDGE_USER_PROMPT | ||
| from judge_tools import create_locate_symbol_tool, create_view_code_tool | ||
| from judge_prompt import JUDGE_SYSTEM_PROMPT, JUDGE_USER_PROMPT |
There was a problem hiding this comment.
This adds src/prejudge (and src/) to sys.path at import time and switches to top-level imports (from judge_tools ..., from judge_prompt ...). Import-time sys.path mutation is a global side effect that can cause hard-to-debug module shadowing and makes the package’s import behavior depend on runtime order. Since prejudge is a package (see src/prejudge/__init__.py), prefer package-relative imports (e.g., from .judge_tools ..., from .judge_prompt ...) and remove the sys.path manipulation (or confine any path tweaks to the __main__ CLI path only).
No description provided.