Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/PkgAuthentication.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import Pkg
import Random
import TOML

include("helpers.jl")

const pkg_server_env_var_name = "JULIA_PKG_SERVER"

## abstract state types
Expand Down Expand Up @@ -520,8 +522,8 @@ function open_browser(url::AbstractString)
@debug "error executing browser hook" exception=(err, catch_backtrace())
return false
end
elseif Sys.iswindows()
run(`cmd /c "start $url"`; wait=false)
elseif Sys.iswindows() || detectwsl()
run(`cmd.exe /c "start $url"`; wait=false)
elseif Sys.isapple()
run(`open $url`; wait=false)
elseif Sys.islinux() || Sys.isbsd()
Expand Down
7 changes: 7 additions & 0 deletions src/helpers.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Vendored from Pluto.jl#src/notebook/path helpers.jl
# from https://github.com/JuliaLang/julia/pull/36425
function detectwsl()
Sys.islinux() &&
isfile("/proc/sys/kernel/osrelease") &&
occursin(r"Microsoft|WSL"i, read("/proc/sys/kernel/osrelease", String))
end
Copy link
Member

@mortenpi mortenpi Feb 10, 2025

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.

Copy link
Member

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?

Suggested change
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

Copy link
Member Author

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

Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems great!

Copy link
Member

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.

Loading