-
Notifications
You must be signed in to change notification settings - Fork 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
python pin
now finds workspace root folder when called in subfolder
#5035
python pin
now finds workspace root folder when called in subfolder
#5035
Conversation
cd1a763
to
a8452f1
Compare
We might want to make this asymmetric per #4971 (comment) and read from the workspace root by default but, when writing, require an opt-in via |
IMO this is more correct to me, since pinned python version is usually used for venv creation/recreation and venv is in workspace root. |
I would agree with @T-256 here, it makes sense to me using the |
a8452f1
to
7c09387
Compare
Rebased to bring in CI fix from #5034 and remove some commented out code that I missed. |
Sure let's just make |
Ready for review again. 👍 |
if exists { | ||
writeln!(printer.stdout(), "Replaced existing pin with `{output}`")?; | ||
let mut message = if exists { | ||
format!("Replaced existing pin with `{output}`") | ||
} else { | ||
writeln!(printer.stdout(), "Pinned to `{output}`")?; | ||
} | ||
format!("Pinned to `{output}`") | ||
}; | ||
|
||
if target_dir != std::env::current_dir()? { | ||
// Print the version file use to pin only | ||
// if it's not in the current working directory | ||
message = format!("{message} in `{}`", version_file.display()); | ||
}; | ||
|
||
writeln!(printer.stdout(), "{message}")?; |
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.
I'm not sure about this part, would something like this be better? 🤔
let message = if exists {
format!("Replaced existing pin with `{output}`")
} else {
format!("Pinned to `{output}`")
};
let message = if target_dir != std::env::current_dir()? {
// Print the version file use to pin only
// if it's not in the current working directory
format!("{message} in `{}`", version_file.display())
} else {
message
};
writeln!(printer.stdout(), "{message}")?;
Okay I resolved the conflicts but then realized we need to make a lot of other changes here, e.g. every other command needs to respect pins in the workspace. Kind of complicated, I need to think about it before moving forward. |
Here's where I left off https://github.com/astral-sh/uv/compare/zb/pin-find |
If you can give me a list of the commands that actually needs to respect the pin I should be able to handle that, I'm just unsure about all the commands. Also probably we need to isolate the logic that finds the pin location, it would simplify implementing it for the other commands. |
I think we need to walk up the directory tree looking for a version file like we do with We may or may not want to stop searching at a boundary where we find a It seems simplest to do something like:
How does that sound? Kind of figuring this out as I go :) |
I'm taking this on in #6370 |
Summary
Fixes #4971.
This PR changes
python pin
behaviour when called in a workspace subfolder. Previously it would only read or create a.python-version
file in the current working directory, now instead it will first search for the workspace root folder and read or create the.python-version
file in that folder.We assume the root folder contains a valid
pyproject.toml
file.If we're not in a workspace use the previous behaviour and creates or reads
.python-version
in the current working directory.Test Plan
I added a new test to verify this new behaviour, and run all tests locally.