-
-
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
Base.url
is broken for non-base functions
#47709
Comments
This issue popped up again in fonsp/Pluto.jl#2813, where we had to limit URLs to code from Julia Base:
CC @fonsp |
The need for this pops up again in fonsp/Pluto.jl#3038. |
Note that |
Then maybe this issue should be split in two:
|
Here is some code that could potentially be used to get the URL for a package function. It uses RegistryInstances.jl to pull out the repo for a package and join that with the local path and line of the method: using RegistryInstances
function repo_and_path_to_url(repo, version, path, line)
repo = chopsuffix(repo, ".git")
# TODO: Handle more git forges
if startswith(repo, "https://github.com")
return join([repo, "blob", "v" * version, path * "#L$line"], "/")
else
error("failed to handle $repo")
end
end
function repos_package(uuid)
repos = String[]
for reg = RegistryInstances.reachable_registries()
entry = get(reg, uuid, nothing)
if entry !== nothing
info = RegistryInstances.registry_info(entry)
push!(repos, info.repo)
end
end
return repos
end
# TODO: If package is devved use local path
# TODO: If package is added by URL, use that
function url(m::Method)
M = parentmodule(m)
uuid = Base.PkgId(M).uuid
line = m.line
pkg_splitpath = splitpath(pkgdir(M))
file_splitpath = splitpath(String(m.file))
while !isempty(pkg_splitpath) && first(pkg_splitpath) == first(file_splitpath)
popfirst!(pkg_splitpath)
popfirst!(file_splitpath)
end
local_dir = join(file_splitpath, "/")
v = string(pkgversion(M))
urls = String[]
for repo in repos_package(uuid)
url = repo_and_path_to_url(repo, v, local_dir, line)
push!(urls, url)
end
return urls
end
using Plots
m = @which Plots.plot(rand(2,2))
url(m) gives: julia> using Plots
julia> m = @which Plots.plot(rand(2,2))
plot(args...; kw...)
@ Plots C:\Users\Kristoffer\.julia\packages\Plots\kLeqV\src\plot.jl:93
julia> url(m)
1-element Vector{String}:
"https://github.com/JuliaPlots/Plots.jl/blob/v1.40.8/src/plot.jl#L93" https://github.com/JuliaPlots/Plots.jl/blob/v1.40.8/src/plot.jl#L93 There are some things that probably should be improved:
|
@KristofferC thanks a lot! I'm guessing this won't make it into Base due to the dependency on RegistryInstances? |
Probably not, it is also a little bit weird of a Base function already. |
Base.url
currently only returns a valid URL when applied to Julia base methods.For functions from stdlib and external packages, a path to the local file is returned instead of a URL.
The relevant branch of
Base.url
looks like dead code to me:julia/base/methodshow.jl
Lines 374 to 396 in 04214ec
(I'm guessing repository information might have previously been pulled by Pkg.)
I've tried to work around this in BrowserMacros.jl, but haven't found out a way to obtain commit hashes to construct permalinks that aren't based on tags (which don't always exist).
Related issues: #44151, #44165
The text was updated successfully, but these errors were encountered: