Skip to content

feat: make Ruff discovery cwd-aware - #1

Merged
grouville merged 2 commits into
dagger:mainfrom
grouville:feat/cwd-aware-discovery
Jul 21, 2026
Merged

grouville merged 2 commits into
dagger:mainfrom
grouville:feat/cwd-aware-discovery

Conversation

@grouville

@grouville grouville commented Jul 21, 2026 •

Copy link
Copy Markdown
Member

Context

Ruff currently exposes one automatic @check over the constructor's sourcePath, whose default is the workspace root. In a workspace containing several Python projects, that means the check is not scoped by the caller's current working directory and there is no shared definition of which Ruff projects belong to the invocation.

This PR adopts the cwd-aware project-discovery convention from dagger/dagger#13688.

Behavior after this change

projects(ws) delegates discovery to polyfill.findConfigDirs for:

  • pyproject.toml;
  • ruff.toml;
  • .ruff.toml.

The returned paths are relative to the caller cwd. Discovery includes projects at or below the cwd and, for context, the nearest enclosing project as a ..-prefixed path.

checkAll(ws) becomes the automatic @check. It runs Ruff only for paths in the caller's cone: the cwd and descendants. A strict ancestor is discoverable but excluded from the automatic check.

For example, the checked-in fixture is:

ancestor/
├── pyproject.toml                  # enclosing Ruff project
└── work/                           # caller cwd; no config
    └── app/
        └── ruff.toml               # descendant Ruff project

From work, projects returns:

..
app

checkAll checks app and does not reach upward into ...

Scope

  • Adds cwd-relative project discovery and a bulk automatic check.
  • Removes @check from the explicit single-source check method; the method itself remains available and unchanged.
  • Leaves lint, fix, format, custom containers, and argument forwarding unchanged.
  • Excludes .venv, site-packages, and node_modules from discovery.
  • Registers Ruff explicitly in dagger.toml, so dagger check no longer depends on module inference.

Reviewer guide

The production change is intentionally small:

  • projects defines what is discoverable;
  • checkAll defines what automatic checking may act on;
  • path.hasPrefix("..") == false is the cone boundary.

cwdScopeCheck exercises behavior rather than only asserting path strings. It overlays invalid Python onto the ancestor and verifies the check still passes, then overlays invalid Python onto work/app and verifies Ruff fails.

Reproduce locally

Run the behavioral integration test:

dagger call ruff cwd-scope-check

Inspect discovery directly:

cd tests/discovery/ancestor/work
dagger call ruff projects

Expected output:

..
app

Run the complete module checks:

dagger check

All 5 checks pass against a locally rebuilt engine.

Known polyfill dependency

A deeper mixed-filename lookup still reproduces dagger/polyfill#2. If the caller is below work/app, polyfill can select the farther ancestor/pyproject.toml before the nearer work/app/ruff.toml because pyproject.toml appears first in the filename list.

This PR keeps the adapter on the shared discovery API. The distance comparison should be fixed once in polyfill and then consumed here by updating the pin.

@TomChv TomChv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved, I fixed dagger/polyfill#2 so just update your polyfill dep and merge the PR.

Polyfill previously selected the first config filename found while walking
up, allowing a farther pyproject.toml to shadow a nearer ruff.toml.

Pin the merged dagger/polyfill#4 revision so Ruff discovery consistently uses
the nearest enclosing project. Keep the distance logic in the shared
discovery implementation instead of duplicating it in this adapter.

Signed-off-by: Guillaume de Rouville <[email protected]>
@grouville
grouville force-pushed the feat/cwd-aware-discovery branch from 86a19ad to 1747ddc Compare July 21, 2026 21:56
@grouville

Copy link
Copy Markdown
Member Author

Pinned the merged dagger/polyfill#4 fix and added consumer regression coverage in follow-up commit 1747ddc.

I manually re-ran the original filename-order edge case in a disposable Git workspace:

ancestor/
├── pyproject.toml                 # farther; searched first
└── work/app/
    ├── ruff.toml                  # nearer
    └── nested/deeper/             # deepest cwd

Observed ruff projects:

cwd result
ancestor/work .., app
ancestor/work/app .
ancestor/work/app/nested/deeper ../..

This covers both prior symptoms: the nearer later-filename config wins, and standing at that project does not also return the farther ancestor.

Manual traces: above project, at project, two levels below.

dagger --x-release=v1.0.0-beta.7 check also passes all 5 checks.

@grouville
grouville merged commit b3b1b00 into dagger:main Jul 21, 2026
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.

2 participants