Skip to content

Warn if --project directory does not exist#17714

Merged
konstin merged 4 commits intomainfrom
konsti/warn-project-dir-does-not-exist
Mar 13, 2026
Merged

Warn if --project directory does not exist#17714
konstin merged 4 commits intomainfrom
konsti/warn-project-dir-does-not-exist

Conversation

@konstin
Copy link
Copy Markdown
Member

@konstin konstin commented Jan 27, 2026

For #17093

Errors if --project points to a file, as this already errors on Linux.

@konstin konstin added the enhancement New feature or improvement to existing functionality label Jan 27, 2026

/// Using `--project` with a file path should warn (ignoring the eventual error).
#[test]
#[cfg(unix)] // TODO(konsti): Currently this doesn't error on Windows, but the result will vanish with the hard error
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.

I'm confused

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Currently, there's different behavior in this test on Unix and on Windows (I haven't investigated the Windows case, but this is bogus --project usage already). This difference will vanish when we upgrade the warning to an error, so I kept it as a TODO 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.

I think it's important to know why this doesn't fail on Windows per #17714 (comment)


----- stderr -----
warning: Project path `not-a-directory` is not a directory. This will become an error in the future.
error: failed to open file `[TEMP_DIR]/not-a-directory/uv.toml`: Not a directory (os error 20)
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.

Why do we attempt to open uv.toml there?

Copy link
Copy Markdown
Member Author

@konstin konstin Jan 28, 2026

Choose a reason for hiding this comment

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

I think we try to discover configuration in the project. TBH I don't don't see this error as a concern, but as additional motivation to now warn and eventually error with a proper message, instead of failing like this. As in, the test is surfacing something that's broken today, and this PR is part of solving this better. It's just that IMHO it isn't worth it to build an intermediate good solution here when we know that changing the warning to error is a good solution.

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.

But doesn't that mean this is already an error today? in which case, why are we bothering with a warning?

Copy link
Copy Markdown
Member

@zanieb zanieb Jan 30, 2026

Choose a reason for hiding this comment

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

Ah we fail because, as it says, it's "not a directory" so the system cannot traverse to attempt to read the child file. I think we should just fix the error message in this case on Linux and not warn?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good point, changed it to an error.

@konstin konstin temporarily deployed to uv-test-publish January 30, 2026 10:41 — with GitHub Actions Inactive
@konstin konstin force-pushed the konsti/warn-project-dir-does-not-exist branch from dbd4489 to 62571a2 Compare February 4, 2026 17:12
@konstin konstin force-pushed the konsti/warn-project-dir-does-not-exist branch 2 times, most recently from 72f2a14 to 75526f2 Compare February 25, 2026 15:10
@konstin konstin added the preview Experimental behavior label Feb 25, 2026
@konstin konstin force-pushed the konsti/warn-project-dir-does-not-exist branch 4 times, most recently from cc64262 to 641be9a Compare March 5, 2026 09:42
@konstin konstin force-pushed the konsti/warn-project-dir-does-not-exist branch from e838cf7 to d088cb0 Compare March 13, 2026 12:17
@konstin konstin enabled auto-merge (squash) March 13, 2026 12:18
@konstin konstin merged commit 5ede703 into main Mar 13, 2026
53 checks passed
@konstin konstin deleted the konsti/warn-project-dir-does-not-exist branch March 13, 2026 12:26
zaniebot pushed a commit to zaniebot/uv that referenced this pull request Mar 16, 2026
When `--project` points to a file (e.g., `pyproject.toml`), resolve to
its parent directory with a deprecation warning instead of erroring.
This restores the pre-0.10.10 behavior that was broken by astral-sh#17714.

Closes astral-sh#18508

https://claude.ai/code/session_01NSUgyAxK5iz4VXKFW2L5ja
zaniebot pushed a commit to zaniebot/uv that referenced this pull request Mar 16, 2026
When `--project` points to a file (e.g., `pyproject.toml`), resolve to
its parent directory with a deprecation warning instead of erroring.

PR astral-sh#17714 added a hard error for this case on the assumption that it was
"already broken on Linux", but it actually worked accidentally:
`Workspace::discover` walks `.ancestors()` from the given path, so
passing `--project project/pyproject.toml` would walk up one level and
find the `pyproject.toml` in the parent directory — the correct project
root.

This restores the pre-0.10.10 behavior while adding a deprecation
warning to guide users toward passing a directory instead.

Closes astral-sh#18508

https://claude.ai/code/session_01NSUgyAxK5iz4VXKFW2L5ja
zaniebot pushed a commit to zaniebot/uv that referenced this pull request Mar 16, 2026
When `--project` points to a file, resolve to its parent directory.
Passing `--project path/to/pyproject.toml` is explicitly allowed without
warning. Other file types emit a deprecation warning.

PR astral-sh#17714 added a hard error for file paths on the assumption that it
"already errors on Linux", but it actually worked accidentally:
`Workspace::discover` walks `.ancestors()` from the given path, so
passing `--project project/pyproject.toml` would walk up one level and
find the `pyproject.toml` in the parent directory — the correct project
root.

Closes astral-sh#18508

https://claude.ai/code/session_01NSUgyAxK5iz4VXKFW2L5ja
zaniebot pushed a commit to zaniebot/uv that referenced this pull request Mar 16, 2026
Use the same `Project path ... is not a directory` phrasing and
`project_path.user_display()` as the original PR astral-sh#17714 code.

https://claude.ai/code/session_01NSUgyAxK5iz4VXKFW2L5ja
zaniebot pushed a commit to zaniebot/uv that referenced this pull request Mar 16, 2026
…-sh#18508)

Fix a regression from astral-sh#17714 where `--project pyproject.toml` stopped
working. When `--project` points to a `pyproject.toml` file, resolve to
its parent directory since downstream code expects a directory. For other
file types, emit a warning (or error with preview flag) and let
downstream code fail naturally if there is no ancestor project.

https://claude.ai/code/session_01NSUgyAxK5iz4VXKFW2L5ja
zanieb added a commit that referenced this pull request Mar 16, 2026
…to a warning on other files (#18513)

Closes #18508

This unintentionally regressed in
#17714 as it appeared that
`--project <file>` always failed but it actually succeeds if the file is
has an ancestor directory with a `pyproject.toml`.

This also removes the warning for `--project [path/]pyproject.toml` as I
think that's a fine use-case.

---------

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or improvement to existing functionality preview Experimental behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants