From 94b8da830003ebeb703af833ca5187610fe0dfbf Mon Sep 17 00:00:00 2001 From: MichaelHatherly Date: Tue, 25 Mar 2025 08:37:53 +0000 Subject: [PATCH 1/6] Remove `LibGit2` dependency --- Project.toml | 6 ++--- src/DocStringExtensions.jl | 4 --- src/utilities.jl | 52 +++++++++++--------------------------- test/tests.jl | 7 +++++ 4 files changed, 24 insertions(+), 45 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..42626dc 100644 --- a/src/DocStringExtensions.jl +++ b/src/DocStringExtensions.jl @@ -73,10 +73,6 @@ $(IMPORTS) """ module DocStringExtensions -# Imports. - -import LibGit2 - # Exports. export @template, FIELDS, TYPEDFIELDS, EXPORTS, METHODLIST, IMPORTS diff --git a/src/utilities.jl b/src/utilities.jl index 0180699..2069e7d 100644 --- a/src/utilities.jl +++ b/src/utilities.jl @@ -508,8 +508,6 @@ end # # Source URLs. # -# Based on code from https://github.com/JuliaLang/julia/blob/master/base/methodshow.jl. -# # Customised to handle URLs on travis since the directory is not a Git repo and we must # instead rely on `TRAVIS_REPO_SLUG` to get the remote repo. # @@ -522,45 +520,25 @@ 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. """ -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" +function url(m::Method) + if haskey(ENV, "TRAVIS_REPO_SLUG") + repo = ENV["TRAVIS_REPO_SLUG"] + commit = get(ENV, "TRAVIS_COMMIT", nothing) + root = get(ENV, "TRAVIS_BUILD_DIR", nothing) + if any(isnothing, (commit, root)) + return "" 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() + file = string(m.file) + if startswith(file, root) || startswith(realpath(file), root) + base = "https://github.com/$repo/tree" + filename = lstrip(file[(length(root)+1):end], '/') + return "$base/$commit/$filename#L$(m.line)" + else return "" end - else - return "" end + else + return Base.url(m) end end diff --git a/test/tests.jl b/test/tests.jl index 560613c..fead702 100644 --- a/test/tests.jl +++ b/test/tests.jl @@ -698,6 +698,13 @@ end @test occursin("github.com/JuliaDocs/NonExistent", DSE.url(first(methods(M.f)))) @test occursin("github.com/JuliaDocs/NonExistent", DSE.url(first(methods(M.K)))) end + withenv( + "TRAVIS_REPO_SLUG" => "JuliaDocs/NonExistent", + "TRAVIS_COMMIT" => "", + "TRAVIS_BUILD_DIR" => dirname(@__DIR__) + ) do + @test occursin("github.com/JuliaDocs/NonExistent/tree//test/TestModule/M.jl", DSE.url(first(methods(M.f)))) + end end @testset "comparemethods" begin let f = first(methods(M.f)), From 1b76daf7dfbbade53ecb73c338722b282d2fcf8e Mon Sep 17 00:00:00 2001 From: MichaelHatherly Date: Tue, 25 Mar 2025 09:12:48 +0000 Subject: [PATCH 2/6] CI debug --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8009908..2163be0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,6 +13,7 @@ jobs: name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} runs-on: ${{ matrix.os }} strategy: + fail-fast: false matrix: version: - '1.0' From 9019829d8f3da415991952d68297f769a7f9532e Mon Sep 17 00:00:00 2001 From: MichaelHatherly Date: Tue, 25 Mar 2025 09:34:30 +0000 Subject: [PATCH 3/6] Fixups for Julia 1.0 --- src/utilities.jl | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/utilities.jl b/src/utilities.jl index 2069e7d..643364b 100644 --- a/src/utilities.jl +++ b/src/utilities.jl @@ -523,19 +523,20 @@ on TravisCI as well. function url(m::Method) if haskey(ENV, "TRAVIS_REPO_SLUG") repo = ENV["TRAVIS_REPO_SLUG"] + commit = get(ENV, "TRAVIS_COMMIT", nothing) + commit === nothing && return "" + root = get(ENV, "TRAVIS_BUILD_DIR", nothing) - if any(isnothing, (commit, root)) - return "" + root === nothing && return "" + + file = string(m.file) + if startswith(file, root) || startswith(realpath(file), root) + base = "https://github.com/$repo/tree" + filename = lstrip(file[(length(root)+1):end], '/') + return "$base/$commit/$filename#L$(m.line)" else - file = string(m.file) - if startswith(file, root) || startswith(realpath(file), root) - base = "https://github.com/$repo/tree" - filename = lstrip(file[(length(root)+1):end], '/') - return "$base/$commit/$filename#L$(m.line)" - else - return "" - end + return "" end else return Base.url(m) From 2e954fc533d22a8f5147197f117160d830765ed9 Mon Sep 17 00:00:00 2001 From: MichaelHatherly Date: Tue, 25 Mar 2025 10:01:34 +0000 Subject: [PATCH 4/6] Normalize paths on Windows --- src/utilities.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utilities.jl b/src/utilities.jl index 643364b..ca55d1c 100644 --- a/src/utilities.jl +++ b/src/utilities.jl @@ -533,7 +533,7 @@ function url(m::Method) file = string(m.file) if startswith(file, root) || startswith(realpath(file), root) base = "https://github.com/$repo/tree" - filename = lstrip(file[(length(root)+1):end], '/') + filename = join(splitpath(lstrip(file[(length(root)+1):end], '/')), '/') return "$base/$commit/$filename#L$(m.line)" else return "" From 553fe8fb2ab6849a14e153534064c2d2ecf98554 Mon Sep 17 00:00:00 2001 From: MichaelHatherly Date: Tue, 25 Mar 2025 11:29:17 +0000 Subject: [PATCH 5/6] Require `REPL` during tests Due to some migration of code from base to `REPL` for docs rendering one of the rendering tests was failing on 1.11. Paper over this issue by just requiring the package in the tests for now. It needs a better long-term solution though. --- Project.toml | 3 ++- test/runtests.jl | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 3cd0b2e..4c78d20 100644 --- a/Project.toml +++ b/Project.toml @@ -9,7 +9,8 @@ julia = "1" LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433" Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a" Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" +REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["LibGit2", "Markdown", "Pkg", "Test"] +test = ["LibGit2", "Markdown", "Pkg", "REPL", "Test"] diff --git a/test/runtests.jl b/test/runtests.jl index 79ec958..aa3c87e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -2,5 +2,6 @@ using DocStringExtensions using Test import Markdown import LibGit2 +import REPL include("tests.jl") From 4a28d59ab7329188c8f4afc15a538a4aa66f351e Mon Sep 17 00:00:00 2001 From: MichaelHatherly Date: Tue, 25 Mar 2025 11:50:38 +0000 Subject: [PATCH 6/6] Avoid needing to use `splitpath` for path separator rewrites --- src/utilities.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utilities.jl b/src/utilities.jl index ca55d1c..7506ffd 100644 --- a/src/utilities.jl +++ b/src/utilities.jl @@ -530,10 +530,10 @@ function url(m::Method) root = get(ENV, "TRAVIS_BUILD_DIR", nothing) root === nothing && return "" - file = string(m.file) - if startswith(file, root) || startswith(realpath(file), root) + file = realpath(string(m.file)) + if startswith(file, root) + filename = join(split(relpath(file, root), @static Sys.iswindows() ? '\\' : '/'), '/') base = "https://github.com/$repo/tree" - filename = join(splitpath(lstrip(file[(length(root)+1):end], '/')), '/') return "$base/$commit/$filename#L$(m.line)" else return ""