-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
feat(wsl): detect wsl #36
Conversation
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.
This LGTM. I tested this on my Windows machine, and I can both repro the original problem and confirm that this seems to fix it.
src/helpers.jl
Outdated
function detectwsl() | ||
Sys.islinux() && | ||
isfile("/proc/sys/kernel/osrelease") && | ||
occursin(r"Microsoft|WSL"i, read("/proc/sys/kernel/osrelease", String)) | ||
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.
This does a bunch of filesystem operations. In general, it would probably better to memoize this into a global I think. But in this case, we don't really call detectwsl
that many times, so this seems fine to me as-is too.
Note: CI failure is persistent, but unrelated -- it looks like some weird linking issue with Julia 1.4 and MacOS. We should maybe just stop testing for some older Julia versions? |
src/helpers.jl
Outdated
function detectwsl() | ||
Sys.islinux() && | ||
isfile("/proc/sys/kernel/osrelease") && | ||
occursin(r"Microsoft|WSL"i, read("/proc/sys/kernel/osrelease", String)) | ||
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.
I'd be more comfortable with some error handling. Thoughts on this?
function detectwsl() | |
Sys.islinux() && | |
isfile("/proc/sys/kernel/osrelease") && | |
occursin(r"Microsoft|WSL"i, read("/proc/sys/kernel/osrelease", String)) | |
end | |
function detectwsl() | |
Sys.islinux() || return false | |
try | |
return occursin(r"Microsoft|WSL"i, read("/proc/sys/kernel/osrelease", String)) | |
catch err | |
@debug "Could not read /proc/sys/kernel/osrelease." exception=(err, catch_backtrace()) | |
end | |
return false | |
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.
Sure. I also just found out that there is a new way to do this: https://github.com/JuliaLang/julia/pull/57069/files
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.
Yeah, that's neat.
@static if isdefined(Sys, :detectwsl)
const detectwsl = Sys.detectwsl
else
# attribution
function detectwsl()
# We use the same approach as canonical/snapd do to detect WSL
islinux() && (
isfile("/proc/sys/fs/binfmt_misc/WSLInterop")
|| isdir("/run/WSL")
)
end
end
then?
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.
seems great!
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 took the liberty up updating the PR with this.
Allows opening links in Windows' browser from wsl