Skip to content

JuliaPluto/MethodURL.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MethodURL

Stable Dev Build Status Coverage Aqua

This package gives a URL to github/gitlab/etc where a method from a package is defined.

Example

julia> import MethodURL, Example

julia> MethodURL.url(
          methods(Example.hello)[1]
       )
1-element Vector{String}:
 "https://github.com/JuliaLang/Example.jl/blob/v0.5.5/src/Example.jl#L9"

URLs are constructed according to the origin of the method:

  • Methods from Base, Core and stdlibs link to the matching release in the JuliaLang/julia repository. Stdlibs that are vendored from their own repository (e.g. Pkg.jl, LinearAlgebra.jl on Julia ≥ 1.12) link to the exact vendored commit in that repository.
  • Methods from packages tracked by a local path (e.g. via Pkg.develop) link to the local file via a file:// URL.
  • Methods from packages added by URL link to that repository at the tracked revision.
  • Methods from registered packages link to the repository listed in the registry at the version tag of the loaded package, including packages in monorepo subdirectories and package extensions. One URL is returned per registry the package is found in.

Supported git forges: GitHub, GitLab (including self-hosted instances), sourcehut, Bitbucket and Codeberg.

If no URL can be constructed, url throws a MethodURLError. Its reason field identifies the cause of the failure, e.g. :no_package_dir for methods that do not belong to a package, such as methods defined in the REPL. The non-throwing variant tryurl returns the MethodURLError instead of throwing it. In the following example, the queried method is that of an anonymous function defined in the REPL, which belongs to the module Main rather than any package, so there is no source repository to link to:

julia> MethodURL.tryurl(methods(x -> x^2)[1])
MethodURLError(:no_package_dir, "Failed to find package directory of module Main.")

Note that a constructed URL can still point to a non-existent page, e.g. if a package release was never tagged in its repository.

Context

Julia has a function Base.url(::Method), but this function only works for methods from Base. It worked on non-Base methods in previous Julia versions, but this functionality disappeared (see JuliaLang/julia#47709). This package aims to reimplement that functionality for modern Julia versions.

Work in progress

This package is still being worked on. When it is finished, we want to use it in Pluto.jl stack frames, see JuliaPluto/Pluto.jl#2813

About

Return the remote repository URL of any Julia method

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages