python pin now finds workspace root folder when called in subfolder#5035
python pin now finds workspace root folder when called in subfolder#5035silvanocerza wants to merge 6 commits intoastral-sh:mainfrom
python pin now finds workspace root folder when called in subfolder#5035Conversation
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.
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. |
|
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 pinbehaviour when called in a workspace subfolder. Previously it would only read or create a.python-versionfile in the current working directory, now instead it will first search for the workspace root folder and read or create the.python-versionfile in that folder.We assume the root folder contains a valid
pyproject.tomlfile.If we're not in a workspace use the previous behaviour and creates or reads
.python-versionin the current working directory.Test Plan
I added a new test to verify this new behaviour, and run all tests locally.