-
Notifications
You must be signed in to change notification settings - Fork 760
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
Consider using dunce
for paths on Windows (not just for display)
#5440
Comments
Hmm, the values in uv/crates/uv-virtualenv/src/virtualenv.rs Line 316 in 375a415
|
Can you test a debug build if I push a branch? |
My only guess is that we need to avoid calling the non-safe |
Happy to test.
Yeah, and I wonder if this will actually make the code simpler? (assuming that this is going to be a near-total revert of #1086. If so, win-win!) |
Can we try #5446 to start, see if the venv is any different? |
No change.
|
Can you try with the update I just pushed? Trying to understand where the prefix is coming from, confused. |
pyvenv.cfg unchanged
|
My guess is that this path is actually not safe to strip though I'm not intimately familiar with the rules: fn is_safe_to_strip_unc(path: &Path) -> bool {
let mut components = path.components();
match components.next() {
Some(Component::Prefix(p)) => match p.kind() {
Prefix::VerbatimDisk(..) => {},
_ => return false, // Other kinds of UNC paths
},
_ => return false, // relative or empty
}
for component in components {
match component {
Component::RootDir => {},
Component::Normal(file_name) => {
// it doesn't allocate in most cases,
// and checks are interested only in the ASCII subset, so lossy is fine
if !is_valid_filename(file_name) || is_reserved(file_name) {
return false;
}
}
_ => return false, // UNC paths take things like ".." literally
};
}
if windows_char_len(path.as_os_str()) > 260 { // However, if the path is going to be used as a directory it's 248
return false;
}
true
} |
Will look deeper when I can, but need to prioritize a few other things first today. Sorry! |
No worries! Judging from the log lines it must be safe to strip in at least some contexts:
|
I think that's the original, unmodified path we get from |
Naive question: do we really need to canonicalise on Windows? (we aren't following symlinks as we are on Linux) Comment in code says:
We generally know that it's real beforehand -- though perhaps not 'real' in the POSIX sense. See the Also perhaps it's something to do with the dollar sign? I am in the predicament of trying to replicate this issue in my home environment and I don't really happen to have network shares laying around :-/ so I thought I'd fake this by using this notation on my C: drive... |
Hmm. We probably don't. |
P.S. it's not the dollar sign. Turns out I can get an arbitrary
|
Yeah. I assume dunce is correct that it's not unequivocally safe to strip that (maybe leads to an ambiguity) but again mercifully I'm not an expert in Windows paths. We can experiment with not canonicalizing paths on Windows at all. |
I pushed a new version to that same branch / PR that avoids canonicalizing on Windows, if you want to try it. |
Third time's the charm! 👍
Looking at the
IMHO this is overly conservative, but I am likewise not a Windows expert -- just someone that has to live with its quirks! Also found this conversation @ someone's So... a |
## Summary If you have an executable path on a network share path (like `\\some-host\some-share\...\python.exe`), canonicalizing it adds the `\\?` prefix, but dunce cannot safely strip it. This PR changes the Windows logic to avoid canonicalizing altogether. We don't really expect symlinks on Windows, so it seems unimportant to resolve them. Closes: #5440.
Thanks a million for the quick resolution 🙌 |
As originally mentioned in #1491 (comment)
Consider the scenario where the Python interpreter is distributed via a network share path. e.g.
\\some-host\some-share\...\python.exe
. Obviously this is not very common but the same sort of path notation can be used for local disk drives, e.g.\\localhost\c$\
-- which is what I use for this reproducer:dunce
'ing the path by hand inpyvenv.cfg
fixes it for me:This issue is reproducible with 3.10.11, but not 3.11. (presumably this bad handling of UNC paths got fixed in CPython down the line?)
The text was updated successfully, but these errors were encountered: