{"record":{"id":"899ff20f6b911002","repo":"astral-sh/ruff","slug":"could-not-find-pyproject-toml-in-any-ancestor-of","errorCode":null,"errorMessage":"could not find `pyproject.toml` in any ancestor of `{file}`","messagePattern":"could not find `pyproject\\.toml` in any ancestor of `(.+?)`","errorType":"console","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/ty_completion_bench/src/main.rs","lineNumber":162,"sourceCode":"        CompletionCapabilities::default(),\n        db.program_file(file),\n        offset,\n    ))\n}\n\nfn discover_project_directory(file: &SystemPath) -> anyhow::Result<SystemPathBuf> {\n    for ancestor in file.as_std_path().canonicalize()?.ancestors() {\n        if ancestor.join(\"pyproject.toml\").exists() {\n            return SystemPathBuf::from_path_buf(ancestor.to_path_buf()).map_err(|path| {\n                anyhow!(\n                    \"Detected project directory `{path}` contains non-Unicode characters. \\\n                     ty only supports Unicode paths.\",\n                    path = path.display()\n                )\n            });\n        }\n    }\n    anyhow::bail!(\"could not find `pyproject.toml` in any ancestor of `{file}`\")\n}\n","sourceCodeStart":144,"sourceCodeEnd":164,"githubUrl":"https://github.com/astral-sh/ruff/blob/672bb4edf04c84f8b0753346359daee4057158f2/crates/ty_completion_bench/src/main.rs#L144-L164","documentation":"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.","triggerScenarios":"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`.","commonSituations":"Quick completion experiments on snippets outside any repo; vendored code dropped into a directory without a project manifest.","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"],"exampleFix":"# before\ncargo run -p ty_completion_bench -- /tmp/scratch/snippet.py\n# after\nprintf '[project]\\nname = \"scratch\"\\nversion = \"0\"\\n' > /tmp/scratch/pyproject.toml\ncargo run -p ty_completion_bench -- /tmp/scratch/snippet.py","handlingStrategy":"validation","validationCode":"d=$(dirname \"$(realpath \"$FILE\")\")\nwhile [ \"$d\" != \"/\" ]; do\n  [ -f \"$d/pyproject.toml\" ] && break\n  d=$(dirname \"$d\")\ndone\n[ -f \"$d/pyproject.toml\" ] || { echo \"no pyproject.toml above $FILE\" >&2; exit 2; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["benchmark","project-discovery","pyproject","configuration"],"backgroundTag":null,"analyzedSha":"672bb4edf04c84f8b0753346359daee4057158f2","analyzedAt":"2026-08-16T08:54:05.464Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}