-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Read and write .python-version
in the workspace root
#7815
Conversation
// TODO: If the version file already exists, but does not contain the requested version, | ||
// should we update it? (add the version, or replace the existing one) | ||
// For now, we keep the existing behavior: if the file exists, we don't update it. | ||
if !version_file.path().try_exists()? { | ||
version_file | ||
.clone() | ||
.with_versions(vec![python_request.clone()]) | ||
.write() | ||
.await?; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the version file already exists, but does not contain the requested version, should we update it? (add the version, or replace the existing one)
For now, we keep the existing behavior: if the file exists, we don't update it.
.and_then(PythonVersionFile::version) | ||
.filter(|version| *version != new.version().unwrap()) | ||
{ | ||
let new = existing.clone().with_versions(vec![request]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Behavior change: uv python pin
now updates the discovered version file, rather than always writing to .python-version
.
if existing.contains(&request) { | ||
writeln!( | ||
printer.stdout(), | ||
"`{}` is already pinned at `{}`", | ||
existing.path().user_display().cyan(), | ||
request.to_canonical_string().green(), | ||
)?; | ||
return Ok(ExitStatus::Success); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Behavior change: uv python pin
now cross-checks the requested version with all versions in the version file, not just the first one. It also avoids updating the version file if the required version already exists. The message updated to ".python-version
is already pinned at 3.12
".
.python-version
in the workspace root
Summary
This PR modifies
uv init
anduv python pin
to read and write the Python version file from the discovered workspace root, instead of the current working directory.It also includes some behavioral changes (noted in the self-review comments). The previous behavior seemed erroneous, but if it wasn't, please instruct me to revert these changes.
Resolves #7806