Skip to content
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

Closed
wants to merge 3 commits into from

Conversation

j178
Copy link
Contributor

@j178 j178 commented Sep 30, 2024

Summary

This PR modifies uv init and uv 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

Comment on lines 766 to 775
// 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?;
}
Copy link
Contributor Author

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]);
Copy link
Contributor Author

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.

Comment on lines +135 to +143
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);
}
Copy link
Contributor Author

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".

@j178 j178 marked this pull request as ready for review September 30, 2024 19:18
@j178 j178 changed the title Don't create .python-version in workspace members Read and write .python-version in the workspace root Sep 30, 2024
@zanieb zanieb self-assigned this Sep 30, 2024
@zanieb
Copy link
Member

zanieb commented Oct 2, 2024

This is going to be a bit complicated as it conflicts with #6370 and #6372

@j178 j178 marked this pull request as draft October 9, 2024 09:28
@j178 j178 closed this Nov 9, 2024
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.

Don't create .python-version in workspace subprojects
2 participants