-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Sys.detectwsl() #36425
base: master
Are you sure you want to change the base?
Sys.detectwsl() #36425
Conversation
Should there be a fallback in case an error occurs while trying to open and/or read from |
@DilumAluthge Yes I should wrap it around try-catch |
How about this:
|
I guess the try-catch might still be good but the main thing is just checking that the file exists. |
And actually, if the file exists but we can't read it, what value should be returned? An error might be best. That's a pretty weird situation and if you can't open and read the file, how do you know if you're on WSL or not? |
Yeah. Is there ever a non-pathological situation in which |
I did just try changing the permissions on a Linux system and you can if you have root access change them, so it's possible that someone could make this file not readable to some users. But in that case what's the right answer here? One should generally assume not WSL as the norm, but if you can't read that file we don't know. |
Does |
(Could replace |
I feel like that's just deferring the error and making it harder to debug. The inevitable usage of this is to test it with a conditional so that's converting a clear "we cannot tell if this system is running WSL or not" error into an obscure " TypeError: non-boolean (Missing) used in boolean context" error. |
Hmm. Maybe then throw an error if we can't read the file? At least it will then be clear what the source of the error is. |
Yes, that's why my version just checks if the file exists and then reads it. If it can't be read it will produce a fairly clear error and TBH I anticipate this never happening because it would be a pretty odd situation (either the kernel is badly broken and can't produce the contents of |
Makes sense to me! |
So, the problem is the string |
@imciner2 systemd says its official way of detecting WSL https://github.com/systemd/systemd/pull/15325/files#diff-0e08ed2dbc97131dbf8deb9eb7af4163R465-R471 but for me (Inside WSL2) not having
I think both should work |
I guess that change hasn't trickled down yet. It looks like it was fairly recently done in the upstream WSL code, so it might not have made it into updaes yet. I would suggest adding a comment in the code referencing the ambiguity we get with the |
test/osutils.jl
Outdated
@@ -28,6 +28,9 @@ | |||
else | |||
@test Sys.windows_version() >= v"1.0.0-" | |||
end | |||
|
|||
@test !Sys.detectwsl(:Windows) | |||
@test !Sys.detectwsl(:Linux) |
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.
Won't this test fail if you run it under WSL?
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 don't know how we are going to test it. Yes these tests will fail inside WSL how are we going to test it?
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 would test that it's not true when the argument is not :Linux
since that's always correct and then add this test for the zero-argument version:
if !Sys.islinux()
@test !Sys.detectwsl()
end
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.
Should the Sys.detectwsl(:Windows) test be removed?
We could call it |
See the discussion that occurred in the linked issue about the naming (#36354). The |
Ah sorry, I didn't see it - I can see why But I still feel like Some final suggestions:
or we return a struct: struct RuntimeProperties
WSL::Bool
container::Bool
etc
end
Sys.runtimeproperties()::RuntimeProperties = ... Just wanted to give some alternatives, but feel free to ignore :) |
Another possible name would be |
Yeah somehow that sounds a lot better... I like it! |
Should it take |
It's a little weird to pass the symbol in this case since you can't really simulate being on another system with this. |
""" | ||
Sys.detectwsl([os]) | ||
|
||
Runtime Predicate for testing if Julia is running inside WSL. |
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.
How about this? (The 1.11 would have to be changed if this were to be backported to 1.10)
Runtime Predicate for testing if Julia is running inside WSL. | |
Runtime predicate for testing if Julia is running inside | |
Windows Subsystem for Linux (WSL). | |
!!! note | |
Unlike `Sys.iswindows`, `Sys.islinux` etc., this is a runtime tests, and thus | |
cannot meaningfully be used in `@static if ` constructs. | |
!!! compat "Julia 1.11" | |
This function requires at least Julia 1.11. |
This has sat here for a long time unfortunately. So I don't know if @mgautam98 still has any interest in this? If so I'd be happy to help get it over the line. If not perhaps someone would like to "adopt" it. Otherwise we'll have to close it :-( |
Tries to solve #36354
Since it will be a runtime function I did it with Julia itself.
I looked into libuv docs and there is no wrapper function to get proc-version since Its too system specific and libuv abstracts it.
Looking at microsoft/WSL#4071 and javascript/wsl seems that we can only find it from version information
If its not the correct way then please give me some pointers in the correct direction.