Skip to content

Commit 6665b34

Browse files
authored
Merge branch 'master' into fix/documenter_v1
2 parents f9e430f + 93cd69a commit 6665b34

File tree

6 files changed

+99
-81
lines changed

6 files changed

+99
-81
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ on:
66
- master
77
tags:
88
- '*'
9+
schedule:
10+
- cron: '0 0 * * 1' # runs 00:00 UTC on every Monday
911
jobs:
1012
test:
1113
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }}
1214
runs-on: ${{ matrix.os }}
1315
strategy:
16+
fail-fast: false
1417
matrix:
1518
version:
1619
- '1.0'
@@ -23,13 +26,13 @@ jobs:
2326
arch:
2427
- x64
2528
steps:
26-
- uses: actions/checkout@v4
27-
- uses: julia-actions/setup-julia@v1
29+
- uses: actions/checkout@v5
30+
- uses: julia-actions/setup-julia@v2
2831
with:
2932
version: ${{ matrix.version }}
3033
arch: ${{ matrix.arch }}
3134
show-versioninfo: true
32-
- uses: actions/cache@v3
35+
- uses: actions/cache@v4
3336
env:
3437
cache-name: cache-artifacts
3538
with:
@@ -42,16 +45,16 @@ jobs:
4245
- uses: julia-actions/julia-runtest@latest
4346
continue-on-error: ${{ matrix.version == 'nightly' }}
4447
- uses: julia-actions/julia-processcoverage@v1
45-
- uses: codecov/codecov-action@v3
48+
- uses: codecov/codecov-action@v5
4649
with:
4750
file: lcov.info
4851

4952
docs:
5053
name: Documentation
5154
runs-on: ubuntu-latest
5255
steps:
53-
- uses: actions/checkout@v4
54-
- uses: julia-actions/setup-julia@v1
56+
- uses: actions/checkout@v5
57+
- uses: julia-actions/setup-julia@v2
5558
with:
5659
version: '1.6'
5760
- run: |

Project.toml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
name = "DocStringExtensions"
22
uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
3-
version = "0.9.3"
4-
5-
[deps]
6-
LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433"
3+
version = "0.9.5"
74

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: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,12 @@ $(IMPORTS)
7373
"""
7474
module DocStringExtensions
7575

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

8278
export @template, FIELDS, TYPEDFIELDS, EXPORTS, METHODLIST, IMPORTS
8379
export SIGNATURES, TYPEDSIGNATURES, TYPEDEF, DOCSTRING, FUNCTIONNAME
8480
export README, LICENSE
85-
export interpolation
81+
# export interpolation
8682

8783
# Includes.
8884

src/utilities.jl

Lines changed: 36 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -452,24 +452,28 @@ kws = keywords(f, first(methods(f)))
452452
```
453453
"""
454454
function keywords(func, m::Method)
455-
table = methods(func).mt
456-
# table is a MethodTable object. For some reason, the :kwsorter field is not always
457-
# defined. An undefined kwsorter seems to imply that there are no methods in the
458-
# MethodTable with keyword arguments.
459-
if !(Base.fieldindex(Core.MethodTable, :kwsorter, false) > 0) || isdefined(table, :kwsorter)
460-
# Fetching method keywords stolen from base/replutil.jl:572-576 (commit 3b45cdc9aab0):
461-
kwargs = VERSION < v"1.4.0-DEV.215" ? Base.kwarg_decl(m, typeof(table.kwsorter)) : Base.kwarg_decl(m)
462-
if isa(kwargs, Vector) && length(kwargs) > 0
463-
filter!(arg -> !occursin("#", string(arg)), kwargs)
464-
# Keywords *may* not be sorted correctly. We move the vararg one to the end.
465-
index = findfirst(arg -> endswith(string(arg), "..."), kwargs)
466-
if index != nothing
467-
kwargs[index], kwargs[end] = kwargs[end], kwargs[index]
468-
end
469-
return kwargs
455+
kwargs = @static if VERSION < v"1.4.0-DEV.215"
456+
table::Core.MethodTable = methods(func).mt
457+
# For some reason, the :kwsorter field is not always defined.
458+
# An undefined kwsorter seems to imply that there are no methods
459+
# in the MethodTable with keyword arguments.
460+
if Base.fieldindex(Core.MethodTable, :kwsorter, false) > 0 && !isdefined(table, :kwsorter)
461+
return Symbol[]
470462
end
463+
Base.kwarg_decl(m, typeof(table.kwsorter))
464+
else
465+
Base.kwarg_decl(m)
471466
end
472-
return Symbol[]
467+
if !isa(kwargs, Vector) || isempty(kwargs)
468+
return Symbol[]
469+
end
470+
filter!(arg -> !occursin("#", string(arg)), kwargs)
471+
# Keywords *may* not be sorted correctly. We move the vararg one to the end.
472+
index = findfirst(arg -> endswith(string(arg), "..."), kwargs)
473+
if index != nothing
474+
kwargs[index], kwargs[end] = kwargs[end], kwargs[index]
475+
end
476+
return kwargs
473477
end
474478

475479

@@ -508,8 +512,6 @@ end
508512
#
509513
# Source URLs.
510514
#
511-
# Based on code from https://github.com/JuliaLang/julia/blob/master/base/methodshow.jl.
512-
#
513515
# Customised to handle URLs on travis since the directory is not a Git repo and we must
514516
# instead rely on `TRAVIS_REPO_SLUG` to get the remote repo.
515517
#
@@ -522,45 +524,26 @@ Get the URL (file and line number) where a method `m` is defined.
522524
Note that this is based on the implementation of `Base.url`, but handles URLs correctly
523525
on TravisCI as well.
524526
"""
525-
url(m::Method) = url(m.module, string(m.file), m.line)
527+
function url(m::Method)
528+
if haskey(ENV, "TRAVIS_REPO_SLUG")
529+
repo = ENV["TRAVIS_REPO_SLUG"]
526530

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
531+
commit = get(ENV, "TRAVIS_COMMIT", nothing)
532+
commit === nothing && return ""
533+
534+
root = get(ENV, "TRAVIS_BUILD_DIR", nothing)
535+
root === nothing && return ""
536+
537+
file = realpath(string(m.file))
538+
if startswith(file, root)
539+
filename = join(split(relpath(file, root), @static Sys.iswindows() ? '\\' : '/'), '/')
540+
base = "https://github.com/$repo/tree"
541+
return "$base/$commit/$filename#L$(m.line)"
561542
else
562543
return ""
563544
end
545+
else
546+
return Base.url(m)
564547
end
565548
end
566549

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: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ end
4040
# Its signature is kwarg_decl(m::Method, kwtype::DataType). The second argument
4141
# should be the type of the kwsorter from the corresponding MethodTable.
4242
@test isa(methods(M.j_1), Base.MethodList)
43-
@test isdefined(methods(M.j_1), :mt)
44-
local mt = methods(M.j_1).mt
43+
get_mt(func) = VERSION v"1.13.0-DEV.647" ? Core.GlobalMethods : methods(func).mt
44+
local mt = get_mt(M.j_1)
4545
@test isa(mt, Core.MethodTable)
4646
if Base.fieldindex(Core.MethodTable, :kwsorter, false) > 0
4747
@test isdefined(mt, :kwsorter)
4848
end
4949
# .kwsorter is not always defined -- namely, it seems when none of the methods
5050
# have keyword arguments:
51-
@test isdefined(methods(M.f).mt, :kwsorter) === false
51+
@test isdefined(get_mt(M.f), :kwsorter) === false
5252
# M.j_1 has two methods. Fetch the single argument one..
5353
local m = which(M.j_1, (Any,))
5454
@test isa(m, Method)
@@ -61,7 +61,7 @@ end
6161
# that does not have any arguments
6262
m = which(M.j_1, (Any,Any)) # fetch the no-keyword method
6363
if VERSION < v"1.4.0-DEV.215"
64-
@test Base.kwarg_decl(m, typeof(methods(M.j_1).mt.kwsorter)) == Tuple{}()
64+
@test Base.kwarg_decl(m, typeof(get_mt(M.j_1).kwsorter)) == Tuple{}()
6565
else
6666
@test Base.kwarg_decl(m) == []
6767
end
@@ -83,7 +83,9 @@ end
8383
DSE.format(IMPORTS, buf, doc)
8484
str = String(take!(buf))
8585
@test occursin("\n - `Base`\n", str)
86-
@test occursin("\n - `Core`\n", str)
86+
if VERSION < v"1.13-DEV"
87+
@test occursin("\n - `Core`\n", str)
88+
end
8789

8890
# Module exports.
8991
DSE.format(EXPORTS, buf, doc)
@@ -151,8 +153,15 @@ end
151153
DSE.format(SIGNATURES, buf, doc)
152154
str = String(take!(buf))
153155
@test occursin("\n```julia\n", str)
154-
@test occursin("\ng()\n", str)
155-
@test occursin("\ng(x)\n", str)
156+
# On 1.10+, automatically generated methods have keywords in the metadata,
157+
# hence the display difference between Julia versions.
158+
if VERSION >= v"1.10"
159+
@test occursin("\ng(; ...)\n", str)
160+
@test occursin("\ng(x; ...)\n", str)
161+
else
162+
@test occursin("\ng()\n", str)
163+
@test occursin("\ng()\n", str)
164+
end
156165
@test occursin("\n```\n", str)
157166

158167
doc.data = Dict(
@@ -163,9 +172,17 @@ end
163172
DSE.format(SIGNATURES, buf, doc)
164173
str = String(take!(buf))
165174
@test occursin("\n```julia\n", str)
166-
@test occursin("\ng()\n", str)
167-
@test occursin("\ng(x)\n", str)
168-
@test occursin("\ng(x, y)\n", str)
175+
# On 1.10+, automatically generated methods have keywords in the metadata,
176+
# hence the display difference between Julia versions.
177+
if VERSION >= v"1.10"
178+
@test occursin("\ng(; ...)\n", str)
179+
@test occursin("\ng(x; ...)\n", str)
180+
@test occursin("\ng(x, y; ...)\n", str)
181+
else
182+
@test occursin("\ng()\n", str)
183+
@test occursin("\ng(x)\n", str)
184+
@test occursin("\ng(x, y)\n", str)
185+
end
169186
@test occursin("\ng(x, y, z; kwargs...)\n", str)
170187
@test occursin("\n```\n", str)
171188

@@ -245,9 +262,21 @@ end
245262
str = String(take!(buf))
246263
@test occursin("\n```julia\n", str)
247264
if typeof(1) === Int64
248-
@test occursin("\nh(x::Int64) -> Int64\n", str)
265+
# On 1.10+, automatically generated methods have keywords in the metadata,
266+
# hence the display difference between Julia versions.
267+
if VERSION >= v"1.10"
268+
@test occursin("\nh(x::Int64; ...) -> Int64\n", str)
269+
else
270+
@test occursin("\nh(x::Int64) -> Int64\n", str)
271+
end
249272
else
250-
@test occursin("\nh(x::Int32) -> Int32\n", str)
273+
# On 1.10+, automatically generated methods have keywords in the metadata,
274+
# hence the display difference between Julia versions.
275+
if VERSION >= v"1.10"
276+
@test occursin("\nh(x::Int32; ...) -> Int32\n", str)
277+
else
278+
@test occursin("\nh(x::Int32) -> Int32\n", str)
279+
end
251280
end
252281
@test occursin("\n```\n", str)
253282

@@ -671,6 +700,13 @@ end
671700
@test occursin("github.com/JuliaDocs/NonExistent", DSE.url(first(methods(M.f))))
672701
@test occursin("github.com/JuliaDocs/NonExistent", DSE.url(first(methods(M.K))))
673702
end
703+
withenv(
704+
"TRAVIS_REPO_SLUG" => "JuliaDocs/NonExistent",
705+
"TRAVIS_COMMIT" => "<commit>",
706+
"TRAVIS_BUILD_DIR" => dirname(@__DIR__)
707+
) do
708+
@test occursin("github.com/JuliaDocs/NonExistent/tree/<commit>/test/TestModule/M.jl", DSE.url(first(methods(M.f))))
709+
end
674710
end
675711
@testset "comparemethods" begin
676712
let f = first(methods(M.f)),

0 commit comments

Comments
 (0)