astral-sh/ruff · error · anyhow::Error

Provided project path `{project}` is not a directory

Error message

Provided project path `{project}` is not a directory

What it means

`--project` selects the directory ty treats as the project root for configuration and metadata discovery, so ty validates `project.as_std_path().is_dir()` and fails fast otherwise. Any non-directory — a regular file, a broken symlink, or a nonexistent path — fails `is_dir()` and triggers this error. Common confusion: `--project` takes the directory that contains `pyproject.toml`, not the TOML file itself.

Source

Thrown at crates/ty/src/lib.rs:123

    let cwd = {
        let cwd = std::env::current_dir().context("Failed to get the current working directory")?;
        SystemPathBuf::from_path_buf(cwd).map_err(|path| {
            anyhow!(
                "The current working directory `{}` contains non-Unicode characters. \
                ty only supports Unicode paths.",
                path.display()
            )
        })?
    };

    let project_path = args
        .project
        .as_ref()
        .map(|project| {
            if project.as_std_path().is_dir() {
                Ok(SystemPath::absolute(project, &cwd))
            } else {
                Err(anyhow!(
                    "Provided project path `{project}` is not a directory"
                ))
            }
        })
        .transpose()?
        .unwrap_or_else(|| cwd.clone());

    let check_paths: Vec<_> = args
        .paths
        .iter()
        .map(|path| SystemPath::absolute(path, &cwd))
        .collect();

    let mode = if args.fix {
        MainLoopMode::Fix(FixMode::ApplyFixes)
    } else if args.add_ignore {
        MainLoopMode::Fix(FixMode::AddIgnore)
    } else {

View on GitHub (pinned to 672bb4edf0)

Solutions

  1. Point `--project` at the directory containing your `pyproject.toml` (usually just `.`)
  2. To check a single file, pass it as a positional check path (`ty check script.py`) instead of `--project`
  3. Verify before running: `test -d "$PROJECT" || echo "--project must be an existing directory"`

Example fix

# before
ty check --project ./pyproject.toml src/
# after
ty check --project . src/
Defensive patterns

Strategy: validation

Validate before calling

test -d "$PROJECT_DIR" || { echo "--project must be an existing directory" >&2; exit 2; }

Prevention

When it happens

Trigger: `ty check --project ./pyproject.toml src/` (file passed instead of directory), `--project` pointing at a Python script you meant to type-check, a typo'd or nonexistent directory, or a CI job where the project dir is conditional and absent on some runners.

Common situations: Migrating from tools whose flag takes a config-file path; single-file projects where the `.py` file is passed to `--project` by mistake; monorepo pipelines computing `--project` from variables that can be empty.

Related errors


AI-assisted analysis of astral-sh/ruff@672bb4edf0 (2026-08-16). Data as JSON: /api/errors/a05df51ee49295b6. Report an issue: GitHub.