fix(ext): cross-platform IS_UV_VENV check without grep subprocess - #8221
Open
Vimal Sahani (VimalN2005) wants to merge 1 commit into
Open
fix(ext): cross-platform IS_UV_VENV check without grep subprocess#8221Vimal Sahani (VimalN2005) wants to merge 1 commit into
Vimal Sahani (VimalN2005) wants to merge 1 commit into
Conversation
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.
Summary
Fixes pytest test collection failure on Windows by replacing the Unix grep subprocess call in IS_UV_VENV with cross-platform Python file inspection.
Problem
In packages/autogen-ext/tests/code_executors/test_commandline_code_executor.py, IS_UV_VENV was defined as:
python subprocess.run( ["grep", "-q", "^uv = ", os.path.join(venv_path, "pyvenv.cfg")], check=False, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, ).returncode == 0On Windows environments where grep is not natively installed in PATH, running pytest fails immediately during collection at import time:
ext packages\autogen-ext\tests\code_executors\test_commandline_code_executor.py:38: in <lambda> subprocess.run( ... FileNotFoundError: [WinError 2] The system cannot find the file specifiedSolution
Replaced the external grep invocation with native Python file reading via Path.read_text():
`python
def _check_is_uv_venv() -> bool:
venv_path = os.environ.get("VIRTUAL_ENV")
if not venv_path:
return False
cfg_path = Path(venv_path) / "pyvenv.cfg"
if not cfg_path.is_file():
return False
try:
content = cfg_path.read_text(encoding="utf-8", errors="ignore")
return any(line.startswith("uv = ") for line in content.splitlines())
except OSError:
return False
IS_UV_VENV: bool = _check_is_uv_venv()
`
Benefits
Testing