astral-sh/ruff · error · anyhow::Error
could not find `pyproject.toml` in any ancestor of `{file}`
Error message
could not find `pyproject.toml` in any ancestor of `{file}` What it means
ty_completion_bench requires each benchmarked file to live inside a project: `discover_project_directory` walks the canonicalized ancestors looking for a `pyproject.toml` and bails when none exists. The file's own name never counts — discovery only inspects directories above it.
Source
Thrown at crates/ty_completion_bench/src/main.rs:162
CompletionCapabilities::default(),
db.program_file(file),
offset,
))
}
fn discover_project_directory(file: &SystemPath) -> anyhow::Result<SystemPathBuf> {
for ancestor in file.as_std_path().canonicalize()?.ancestors() {
if ancestor.join("pyproject.toml").exists() {
return SystemPathBuf::from_path_buf(ancestor.to_path_buf()).map_err(|path| {
anyhow!(
"Detected project directory `{path}` contains non-Unicode characters. \
ty only supports Unicode paths.",
path = path.display()
)
});
}
}
anyhow::bail!("could not find `pyproject.toml` in any ancestor of `{file}`")
}
View on GitHub (pinned to 672bb4edf0)
Solutions
- Create a minimal `pyproject.toml` at the scratch project root and benchmark files under it
- Move the file into an existing project that already has a `pyproject.toml`
- For ad-hoc completion behavior checks, write an mdtest instead of using the bench harness
Example fix
# before cargo run -p ty_completion_bench -- /tmp/scratch/snippet.py # after printf '[project]\nname = "scratch"\nversion = "0"\n' > /tmp/scratch/pyproject.toml cargo run -p ty_completion_bench -- /tmp/scratch/snippet.py
Defensive patterns
Strategy: validation
Validate before calling
d=$(dirname "$(realpath "$FILE")")
while [ "$d" != "/" ]; do
[ -f "$d/pyproject.toml" ] && break
d=$(dirname "$d")
done
[ -f "$d/pyproject.toml" ] || { echo "no pyproject.toml above $FILE" >&2; exit 2; } Prevention
- Benchmark only files inside a project with a `pyproject.toml`
- Keep a minimal `pyproject.toml` template for scratch benchmark projects
- Remember the bench harness requires a project root; it is not a single-file tool
When it happens
Trigger: Passing a standalone scratch file (e.g. under /tmp) with no `pyproject.toml` in any parent directory; benchmarking a file from a pre-PEP-621 project that only has `setup.py`/`requirements.txt`.
Common situations: Quick completion experiments on snippets outside any repo; vendored code dropped into a directory without a project manifest.
Related errors
- Unknown option: {key}
- Git fetch of commit {} failed: {}
- Git checkout of commit {} failed: {}
- Git clone failed: {}
- uv is not installed or not found in PATH. If you need to ins
AI-assisted analysis of astral-sh/ruff@672bb4edf0 (2026-08-16).
Data as JSON: /api/errors/899ff20f6b911002.
Report an issue: GitHub.