Skip to content

fix: Windows compatibility - use shutil.which for ripgrep, add UTF-8 encoding#23

Open
RudyCity wants to merge 2 commits into
microsoft:mainfrom
RudyCity:main
Open

fix: Windows compatibility - use shutil.which for ripgrep, add UTF-8 encoding#23
RudyCity wants to merge 2 commits into
microsoft:mainfrom
RudyCity:main

Conversation

@RudyCity

Copy link
Copy Markdown

Problem

FastContext tools fail on Windows with two errors:

Issue Error Root Cause
Grep fails [WinError 2] The system cannot find the file specified _rg_path = "/usr/bin/rg" is hardcoded to a Linux path
Read fails 'charmap' codec can't decode byte 0x81 aiofiles.open() has no encoding specified; Windows defaults to cp1252

Fix

grep.py

  • Replace hardcoded _rg_path = "/usr/bin/rg" with shutil.which("rg") or "rg" (cross-platform)
  • Add encoding="utf-8", errors="replace" to subprocess.run()

glob.py

  • Replace bare "rg" with shutil.which("rg") or "rg" (explicit resolution)
  • Add encoding="utf-8", errors="replace" to subprocess.run()

read.py

  • Add encoding="utf-8", errors="replace" to aiofiles.open()

Testing

  • Verified shutil.which("rg") resolves correctly on Windows
  • Confirmed old /usr/bin/rg path does not exist on Windows (root cause of WinError 2)
  • Verified charmap crash occurs without encoding fix on non-ASCII content
  • Verified encoding="utf-8", errors="replace" reads all content without crash
  • All three tool modules import successfully after changes

Test added 2 commits June 21, 2026 15:22
…encoding

- grep.py: replace hardcoded '/usr/bin/rg' with shutil.which('rg')
- glob.py: replace bare 'rg' with shutil.which('rg')
- read.py: add encoding='utf-8' and errors='replace' to aiofiles.open()
- grep.py/glob.py: add encoding='utf-8' to subprocess.run() calls

Fixes [WinError 2] (rg binary not found) and 'charmap' codec errors
(non-ASCII file content) on Windows.
…shell detection

Core (src/):
- grep.py/glob.py: replace Path.as_posix() with str() for native Windows paths
- grep.py/glob.py: add friendly error message when ripgrep is not installed
- grep.py/glob.py: add FileNotFoundError safety net around subprocess.run
- utils.py: detect Windows shell via COMSPEC instead of defaulting to bash

Benchmark:
- bench_fastcontext.py: add encoding='utf-8' to subprocess.run in _start_container
- run_score.py: add encoding='utf-8' to open()
- query_gen.py: add encoding='utf-8' to open()
- bench_mini_swe_agent.py: add encoding='utf-8' to open(), read_text(), write_text()
@RudyCity

Copy link
Copy Markdown
Author

Pushed additional commits with more Windows compatibility fixes:

  • Replace Path.as_posix() with str() for native Windows paths in subprocess cwd
  • Add friendly error message when ripgrep (rg) is not installed instead of cryptic FileNotFoundError
  • Detect Windows shell via COMSPEC env var instead of defaulting to bash in system prompt
  • Add encoding='utf-8' to all open(), read_text(), write_text(), and subprocess.run() calls in benchmark scripts

@RudyCity

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant