From aec4f322ae56236d0b3f828ffc0e47b470c68afa Mon Sep 17 00:00:00 2001 From: nhz2 Date: Mon, 12 Aug 2024 23:36:30 -0400 Subject: [PATCH 1/3] remove LibGit2 dep and fix test --- Project.toml | 6 ++--- src/DocStringExtensions.jl | 1 - src/utilities.jl | 47 +++----------------------------------- 3 files changed, 5 insertions(+), 49 deletions(-) diff --git a/Project.toml b/Project.toml index bad33c1..3cd0b2e 100644 --- a/Project.toml +++ b/Project.toml @@ -2,16 +2,14 @@ name = "DocStringExtensions" uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" version = "0.9.3" -[deps] -LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433" - [compat] julia = "1" [extras] +LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433" Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a" Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Markdown", "Pkg", "Test"] +test = ["LibGit2", "Markdown", "Pkg", "Test"] diff --git a/src/DocStringExtensions.jl b/src/DocStringExtensions.jl index 1e1a1ce..43e4862 100644 --- a/src/DocStringExtensions.jl +++ b/src/DocStringExtensions.jl @@ -75,7 +75,6 @@ module DocStringExtensions # Imports. -import LibGit2 # Exports. diff --git a/src/utilities.jl b/src/utilities.jl index 0180699..4143f08 100644 --- a/src/utilities.jl +++ b/src/utilities.jl @@ -459,7 +459,7 @@ function keywords(func, m::Method) if !(Base.fieldindex(Core.MethodTable, :kwsorter, false) > 0) || isdefined(table, :kwsorter) # Fetching method keywords stolen from base/replutil.jl:572-576 (commit 3b45cdc9aab0): kwargs = VERSION < v"1.4.0-DEV.215" ? Base.kwarg_decl(m, typeof(table.kwsorter)) : Base.kwarg_decl(m) - if isa(kwargs, Vector) && length(kwargs) > 0 + if isa(kwargs, Vector) && length(kwargs) > 0 && kwargs != [:...] # in julia 1.10 sometimes kwargs is `[:...]`, ignore that filter!(arg -> !occursin("#", string(arg)), kwargs) # Keywords *may* not be sorted correctly. We move the vararg one to the end. index = findfirst(arg -> endswith(string(arg), "..."), kwargs) @@ -519,50 +519,9 @@ $(:SIGNATURES) Get the URL (file and line number) where a method `m` is defined. -Note that this is based on the implementation of `Base.url`, but handles URLs correctly -on TravisCI as well. +Note that this is `Base.url`. """ -url(m::Method) = url(m.module, string(m.file), m.line) - -function url(mod::Module, file::AbstractString, line::Integer) - file = Sys.iswindows() ? replace(file, '\\' => '/') : file - if Base.inbase(mod) && !isabspath(file) - local base = "https://github.com/JuliaLang/julia/tree" - if isempty(Base.GIT_VERSION_INFO.commit) - return "$base/v$VERSION/base/$file#L$line" - else - local commit = Base.GIT_VERSION_INFO.commit - return "$base/$commit/base/$file#L$line" - end - else - if isfile(file) - local d = dirname(file) - try # might not be in a git repo - LibGit2.with(LibGit2.GitRepoExt(d)) do repo - LibGit2.with(LibGit2.GitConfig(repo)) do cfg - local u = LibGit2.get(cfg, "remote.origin.url", "") - local m = match(LibGit2.GITHUB_REGEX, u) - u = m === nothing ? get(ENV, "TRAVIS_REPO_SLUG", "") : m.captures[1] - local commit = string(LibGit2.head_oid(repo)) - local root = LibGit2.path(repo) - if startswith(file, root) || startswith(realpath(file), root) - local base = "https://github.com/$u/tree" - local filename = file[(length(root) + 1):end] - return "$base/$commit/$filename#L$line" - else - return "" - end - end - end - catch err - isa(err, LibGit2.GitError) || rethrow() - return "" - end - else - return "" - end - end -end +url(m::Method) = Base.url(m) # This is compat to make sure that we have ismutabletype available pre-1.7. # Implementation borrowed from JuliaLang/julia (MIT license). From 19b8aba9c271b4fe7eb284c27ef81394562bd2b2 Mon Sep 17 00:00:00 2001 From: Morten Piibeleht Date: Tue, 13 Aug 2024 20:46:15 +1200 Subject: [PATCH 2/3] Update src/utilities.jl --- src/utilities.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utilities.jl b/src/utilities.jl index 4143f08..ace2085 100644 --- a/src/utilities.jl +++ b/src/utilities.jl @@ -459,7 +459,7 @@ function keywords(func, m::Method) if !(Base.fieldindex(Core.MethodTable, :kwsorter, false) > 0) || isdefined(table, :kwsorter) # Fetching method keywords stolen from base/replutil.jl:572-576 (commit 3b45cdc9aab0): kwargs = VERSION < v"1.4.0-DEV.215" ? Base.kwarg_decl(m, typeof(table.kwsorter)) : Base.kwarg_decl(m) - if isa(kwargs, Vector) && length(kwargs) > 0 && kwargs != [:...] # in julia 1.10 sometimes kwargs is `[:...]`, ignore that + if isa(kwargs, Vector) && length(kwargs) > 0 filter!(arg -> !occursin("#", string(arg)), kwargs) # Keywords *may* not be sorted correctly. We move the vararg one to the end. index = findfirst(arg -> endswith(string(arg), "..."), kwargs) From 245a9cfaf8ef6db82cb885a7d273557ea63e3a1f Mon Sep 17 00:00:00 2001 From: Morten Piibeleht Date: Tue, 13 Aug 2024 20:58:33 +1200 Subject: [PATCH 3/3] strip file:/// URLs --- src/utilities.jl | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/utilities.jl b/src/utilities.jl index ace2085..d99639a 100644 --- a/src/utilities.jl +++ b/src/utilities.jl @@ -517,11 +517,17 @@ end """ $(:SIGNATURES) -Get the URL (file and line number) where a method `m` is defined. +Get the URL (file and line number) where a method `m` is defined. May return an empty string +if the URL can not be determined. -Note that this is `Base.url`. +Requires the `LibGit2` to be present in the environment. """ -url(m::Method) = Base.url(m) +function url(m::Method) + # Base.url() something produces file:// URLs, but we want these to be sharable web URLs. + # So we just say we couldn't determine the URL if we get one of those. + url = Base.url(m) + return startswith(url, "file://") ? "" : url +end # This is compat to make sure that we have ismutabletype available pre-1.7. # Implementation borrowed from JuliaLang/julia (MIT license).