Skip to content

Commit 2df82e8

Browse files
Merge pull request #172 from JuliaDocs/mh/no-libgit2
Remove `LibGit2` dependency
2 parents f65720c + 4a28d59 commit 2df82e8

File tree

6 files changed

+28
-45
lines changed

6 files changed

+28
-45
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ jobs:
1313
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }}
1414
runs-on: ${{ matrix.os }}
1515
strategy:
16+
fail-fast: false
1617
matrix:
1718
version:
1819
- '1.0'

Project.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@ name = "DocStringExtensions"
22
uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
33
version = "0.9.3"
44

5-
[deps]
6-
LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433"
7-
85
[compat]
96
julia = "1"
107

118
[extras]
9+
LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433"
1210
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
1311
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
12+
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
1413
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1514

1615
[targets]
17-
test = ["Markdown", "Pkg", "Test"]
16+
test = ["LibGit2", "Markdown", "Pkg", "REPL", "Test"]

src/DocStringExtensions.jl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,6 @@ $(IMPORTS)
7373
"""
7474
module DocStringExtensions
7575

76-
# Imports.
77-
78-
import LibGit2
79-
8076
# Exports.
8177

8278
export @template, FIELDS, TYPEDFIELDS, EXPORTS, METHODLIST, IMPORTS

src/utilities.jl

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -508,8 +508,6 @@ end
508508
#
509509
# Source URLs.
510510
#
511-
# Based on code from https://github.com/JuliaLang/julia/blob/master/base/methodshow.jl.
512-
#
513511
# Customised to handle URLs on travis since the directory is not a Git repo and we must
514512
# instead rely on `TRAVIS_REPO_SLUG` to get the remote repo.
515513
#
@@ -522,45 +520,26 @@ Get the URL (file and line number) where a method `m` is defined.
522520
Note that this is based on the implementation of `Base.url`, but handles URLs correctly
523521
on TravisCI as well.
524522
"""
525-
url(m::Method) = url(m.module, string(m.file), m.line)
523+
function url(m::Method)
524+
if haskey(ENV, "TRAVIS_REPO_SLUG")
525+
repo = ENV["TRAVIS_REPO_SLUG"]
526526

527-
function url(mod::Module, file::AbstractString, line::Integer)
528-
file = Sys.iswindows() ? replace(file, '\\' => '/') : file
529-
if Base.inbase(mod) && !isabspath(file)
530-
local base = "https://github.com/JuliaLang/julia/tree"
531-
if isempty(Base.GIT_VERSION_INFO.commit)
532-
return "$base/v$VERSION/base/$file#L$line"
533-
else
534-
local commit = Base.GIT_VERSION_INFO.commit
535-
return "$base/$commit/base/$file#L$line"
536-
end
537-
else
538-
if isfile(file)
539-
local d = dirname(file)
540-
try # might not be in a git repo
541-
LibGit2.with(LibGit2.GitRepoExt(d)) do repo
542-
LibGit2.with(LibGit2.GitConfig(repo)) do cfg
543-
local u = LibGit2.get(cfg, "remote.origin.url", "")
544-
local m = match(LibGit2.GITHUB_REGEX, u)
545-
u = m === nothing ? get(ENV, "TRAVIS_REPO_SLUG", "") : m.captures[1]
546-
local commit = string(LibGit2.head_oid(repo))
547-
local root = LibGit2.path(repo)
548-
if startswith(file, root) || startswith(realpath(file), root)
549-
local base = "https://github.com/$u/tree"
550-
local filename = file[(length(root) + 1):end]
551-
return "$base/$commit/$filename#L$line"
552-
else
553-
return ""
554-
end
555-
end
556-
end
557-
catch err
558-
isa(err, LibGit2.GitError) || rethrow()
559-
return ""
560-
end
527+
commit = get(ENV, "TRAVIS_COMMIT", nothing)
528+
commit === nothing && return ""
529+
530+
root = get(ENV, "TRAVIS_BUILD_DIR", nothing)
531+
root === nothing && return ""
532+
533+
file = realpath(string(m.file))
534+
if startswith(file, root)
535+
filename = join(split(relpath(file, root), @static Sys.iswindows() ? '\\' : '/'), '/')
536+
base = "https://github.com/$repo/tree"
537+
return "$base/$commit/$filename#L$(m.line)"
561538
else
562539
return ""
563540
end
541+
else
542+
return Base.url(m)
564543
end
565544
end
566545

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ using DocStringExtensions
22
using Test
33
import Markdown
44
import LibGit2
5+
import REPL
56

67
include("tests.jl")

test/tests.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,13 @@ end
698698
@test occursin("github.com/JuliaDocs/NonExistent", DSE.url(first(methods(M.f))))
699699
@test occursin("github.com/JuliaDocs/NonExistent", DSE.url(first(methods(M.K))))
700700
end
701+
withenv(
702+
"TRAVIS_REPO_SLUG" => "JuliaDocs/NonExistent",
703+
"TRAVIS_COMMIT" => "<commit>",
704+
"TRAVIS_BUILD_DIR" => dirname(@__DIR__)
705+
) do
706+
@test occursin("github.com/JuliaDocs/NonExistent/tree/<commit>/test/TestModule/M.jl", DSE.url(first(methods(M.f))))
707+
end
701708
end
702709
@testset "comparemethods" begin
703710
let f = first(methods(M.f)),

0 commit comments

Comments
 (0)