Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecation fixes #643

Merged
merged 11 commits into from
Feb 18, 2018
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
julia 0.6
Compat 0.47.0
Compat 0.54.0
DocStringExtensions 0.2
9 changes: 4 additions & 5 deletions src/CrossReferences.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import ..Documenter:
Walkers

using Compat, DocStringExtensions
import Compat.Markdown

"""
$(SIGNATURES)
Expand Down Expand Up @@ -49,7 +50,7 @@ end
xref(other, meta, page, doc) = true # Continue to `walk` through element `other`.

function basicxref(link::Markdown.Link, meta, page, doc)
if length(link.text) === 1 && isa(link.text[1], Base.Markdown.Code)
if length(link.text) === 1 && isa(link.text[1], Markdown.Code)
docsxref(link, link.text[1].code, meta, page, doc)
elseif isa(link.text, Vector)
# No `name` was provided, since given a `@ref`, so slugify the `.text` instead.
Expand All @@ -76,7 +77,7 @@ function namedxref(link::Markdown.Link, meta, page, doc)
else
if Anchors.exists(doc.internal.headers, slug)
namedxref(link, slug, meta, page, doc)
elseif length(link.text) === 1 && isa(link.text[1], Base.Markdown.Code)
elseif length(link.text) === 1 && isa(link.text[1], Markdown.Code)
docsxref(link, slug, meta, page, doc)
else
namedxref(link, slug, meta, page, doc)
Expand Down Expand Up @@ -203,7 +204,7 @@ function find_object(binding, typesig)
end
end
function find_object(λ::Union{Function, DataType}, binding, typesig)
if _method_exists(λ, typesig)
if hasmethod(λ, typesig)
signature = getsig(λ, typesig)
return Utilities.Object(binding, signature)
else
Expand All @@ -213,8 +214,6 @@ end
find_object(::Union{Function, DataType}, binding, ::Union{Union,Type{Union{}}}) = Utilities.Object(binding, Union{})
find_object(other, binding, typesig) = Utilities.Object(binding, typesig)

_method_exists(f, t) = method_exists(f, t)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently this actually made sense back when Documenter still supported 0.4. Good to get rid of this. 😆


getsig(λ::Union{Function, DataType}, typesig) = Base.tuple_type_tail(which(λ, typesig).sig)


Expand Down
31 changes: 16 additions & 15 deletions src/DocChecks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import ..Documenter:
IdDict

using Compat, DocStringExtensions
import Compat.Markdown

# Missing docstrings.
# -------------------
Expand Down Expand Up @@ -79,7 +80,7 @@ meta(m) = Docs.meta(m)
nameof(x::Function) = typeof(x).name.mt.name
nameof(b::Base.Docs.Binding) = b.var
nameof(x::DataType) = x.name.name
nameof(m::Module) = module_name(m)
nameof(m::Module) = Compat.nameof(m)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this could actually just extend the nameof in Base. But that is beyond this PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we should actually remove the nameof definitions here to avoid shadowing Base on 0.7.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did extend at first but that a bit weird. Either we leave it as is here, or upstream the other nameof methods to base. Not sure how useful the other methods are though, so I think its fine to leave this as is.


sigs(x::Base.Docs.MultiDoc) = x.order
sigs(::Any) = Type[Union{}]
Expand Down Expand Up @@ -240,7 +241,7 @@ end

# Regex used here to replace gensym'd module names could probably use improvements.
function checkresult(sandbox::Module, result::Result, meta::Dict, doc::Documents.Document)
sandbox_name = module_name(sandbox)
sandbox_name = nameof(sandbox)
mod_regex = Regex("(Main\\.)?(Symbol\\(\"$(sandbox_name)\"\\)|$(sandbox_name))[,.]")
mod_regex_nodot = Regex(("(Main\\.)?$(sandbox_name)"))
if isdefined(result, :bt) # An error was thrown and we have a backtrace.
Expand Down Expand Up @@ -311,22 +312,22 @@ function report(result::Result, str, doc::Documents.Document)
buffer = IOBuffer()
println(buffer, "=====[Test Error]", "="^30)
println(buffer)
print_with_color(:cyan, buffer, "> File: ", result.file, "\n")
print_with_color(:cyan, buffer, "\n> Code block:\n")
printstyled(buffer, "> File: ", result.file, "\n", color=:cyan)
printstyled(buffer, "\n> Code block:\n", color=:cyan)
println(buffer, "\n```jldoctest")
println(buffer, result.code)
println(buffer, "```")
if !isempty(result.input)
print_with_color(:cyan, buffer, "\n> Subexpression:\n")
printstyled(buffer, "\n> Subexpression:\n", color=:cyan)
print_indented(buffer, result.input; indent = 4)
end
warning = Base.have_color ? "" : " (REQUIRES COLOR)"
print_with_color(:cyan, buffer, "\n> Output Diff", warning, ":\n\n")
printstyled(buffer, "\n> Output Diff", warning, ":\n\n", color=:cyan)
diff = TextDiff.Diff{TextDiff.Words}(result.output, rstrip(str))
Utilities.TextDiff.showdiff(buffer, diff)
println(buffer, "\n\n", "=====[End Error]=", "="^30)
push!(doc.internal.errors, :doctest)
print_with_color(:normal, Utilities.takebuf_str(buffer))
printstyled(Utilities.takebuf_str(buffer), color=:normal)
end

function print_indented(buffer::IO, str::AbstractString; indent = 4)
Expand Down Expand Up @@ -379,7 +380,7 @@ function repl_splitter(code)
end

function savebuffer!(out, buf)
n = nb_available(seekstart(buf))
n = bytesavailable(seekstart(buf))
n > 0 ? push!(out, rstrip(Utilities.takebuf_str(buf))) : out
end

Expand Down Expand Up @@ -476,13 +477,13 @@ function linkcheck(doc::Documents.Document)
return nothing
end

function linkcheck(link::Base.Markdown.Link, doc::Documents.Document)
function linkcheck(link::Markdown.Link, doc::Documents.Document)
INDENT = " "^6

# first, make sure we're not supposed to ignore this link
for r in doc.user.linkcheck_ignore
if linkcheck_ismatch(r, link.url)
print_with_color(:normal, INDENT, "--- ", link.url, "\n")
printstyled(INDENT, "--- ", link.url, "\n", color=:normal)
return false
end
end
Expand All @@ -500,19 +501,19 @@ function linkcheck(link::Base.Markdown.Link, doc::Documents.Document)
if contains(result, STATUS_REGEX)
status = parse(Int, match(STATUS_REGEX, result).captures[1])
if status < 300
print_with_color(:green, INDENT, "$(status) ", link.url, "\n")
printstyled(INDENT, "$(status) ", link.url, "\n", color=:green)
elseif status < 400
LOCATION_REGEX = r"^Location: (.+)$"m
if contains(result, LOCATION_REGEX)
location = strip(match(LOCATION_REGEX, result).captures[1])
print_with_color(:yellow, INDENT, "$(status) ", link.url, "\n")
print_with_color(:yellow, INDENT, " -> ", location, "\n\n")
printstyled(INDENT, "$(status) ", link.url, "\n", color=:yellow)
printstyled(INDENT, " -> ", location, "\n\n", color=:yellow)
else
print_with_color(:yellow, INDENT, "$(status) ", link.url, "\n")
printstyled(INDENT, "$(status) ", link.url, "\n", color=:yellow)
end
else
push!(doc.internal.errors, :linkcheck)
print_with_color(:red, INDENT, "$(status) ", link.url, "\n")
printstyled(INDENT, "$(status) ", link.url, "\n", color=:red)
end
else
push!(doc.internal.errors, :linkcheck)
Expand Down
7 changes: 4 additions & 3 deletions src/DocSystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ docsystem in both `0.4` and `0.5`.
module DocSystem

using Compat, DocStringExtensions
import Compat.Markdown
import Base.Docs: MultiDoc, parsedoc, formatdoc, DocStr
import ..IdDict

Expand Down Expand Up @@ -32,7 +33,7 @@ binding(any::Any) = throw(ArgumentError("cannot convert `$any` to a `Binding`.")
#
binding(b::Docs.Binding) = binding(b.mod, b.var)
binding(d::DataType) = binding(d.name.module, d.name.name)
binding(m::Module) = binding(m, module_name(m))
binding(m::Module) = binding(m, nameof(m))
binding(s::Symbol) = binding(Main, s)
binding(f::Function) = binding(typeof(f).name.module, typeof(f).name.mt.name)

Expand All @@ -42,7 +43,7 @@ binding(f::Function) = binding(typeof(f).name.module, typeof(f).name.mt.name
#
# Note that `IntrinsicFunction` is exported from `Base` in `0.4`, but not in `0.5`.
#
let INTRINSICS = Dict(map(s -> getfield(Core.Intrinsics, s) => s, names(Core.Intrinsics, true)))
let INTRINSICS = Dict(map(s -> getfield(Core.Intrinsics, s) => s, Compat.names(Core.Intrinsics, all=true)))
binding(i::Core.IntrinsicFunction) = binding(Core.Intrinsics, INTRINSICS[i]::Symbol)
end

Expand All @@ -52,7 +53,7 @@ end
# This is done within the `Binding` constructor on `0.5`, but not on `0.4`.
#
function binding(m::Module, v::Symbol)
m = module_name(m) === v ? module_parent(m) : m
m = nameof(m) === v ? parentmodule(m) : m
Docs.Binding(m, v)
end

Expand Down
2 changes: 1 addition & 1 deletion src/Documenter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ using Compat, DocStringExtensions

export genkeys

import Base.LibGit2.GITHUB_REGEX
import Compat.LibGit2.GITHUB_REGEX


"""
Expand Down
9 changes: 5 additions & 4 deletions src/Documents.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import ..Documenter:
IdDict

using Compat, DocStringExtensions
import Compat.Markdown
using Compat.Unicode

# Pages.
Expand Down Expand Up @@ -50,7 +51,7 @@ struct Page
globals :: Globals
end
function Page(source::AbstractString, build::AbstractString)
elements = Base.Markdown.parse(read(source, String)).content
elements = Markdown.parse(read(source, String)).content
Page(source, build, elements, IdDict(), Globals())
end

Expand Down Expand Up @@ -124,7 +125,7 @@ struct DocsNodes
end

struct EvalNode
code :: Base.Markdown.Code
code :: Markdown.Code
result :: Any
end

Expand Down Expand Up @@ -219,7 +220,7 @@ struct Internal
objects :: IdDict # Tracks which `Utilities.Objects` are included in the `Document`.
contentsnodes :: Vector{ContentsNode}
indexnodes :: Vector{IndexNode}
locallinks :: Dict{Base.Markdown.Link, String}
locallinks :: Dict{Markdown.Link, String}
errors::Set{Symbol}
end

Expand Down Expand Up @@ -306,7 +307,7 @@ function Document(;
IdDict(),
[],
[],
Dict{Base.Markdown.Link, String}(),
Dict{Markdown.Link, String}(),
Set{Symbol}(),
)
Document(user, internal)
Expand Down
5 changes: 3 additions & 2 deletions src/Expanders.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import .Documents:
MetaNode

using Compat
import Compat.Markdown


function expand(doc::Documents.Document)
Expand Down Expand Up @@ -291,7 +292,7 @@ function Selectors.runner(::Type{DocsBlocks}, x, page, doc)
end

# Concatenate found docstrings into a single `MD` object.
docstr = Base.Markdown.MD(map(Documenter.DocSystem.parsedoc, docs))
docstr = Markdown.MD(map(Documenter.DocSystem.parsedoc, docs))
docstr.meta[:results] = docs

# Generate a unique name to be used in anchors and links for the docstring.
Expand Down Expand Up @@ -518,7 +519,7 @@ function Selectors.runner(::Type{REPLBlocks}, x, page, doc)
println(out, output, "\n")
end
end
page.mapping[x] = Base.Markdown.Code("julia-repl", rstrip(Utilities.takebuf_str(out)))
page.mapping[x] = Markdown.Code("julia-repl", rstrip(Utilities.takebuf_str(out)))
end

# @setup
Expand Down
2 changes: 1 addition & 1 deletion src/Utilities/MDFlatten.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import ..Utilities

using Compat

import Base.Markdown:
import Compat.Markdown:
MD, BlockQuote, Bold, Code, Header, HorizontalRule,
Image, Italic, LaTeX, LineBreak, Link, List, Paragraph, Table,
Footnote, Admonition
Expand Down
6 changes: 3 additions & 3 deletions src/Utilities/TextDiff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function splitby(reg::Regex, text::AbstractString)
out = SubString{String}[]
token_first = 1
for each in eachmatch(reg, text)
token_last = each.offset + endof(each.match) - 1
token_last = each.offset + lastindex(each.match) - 1
push!(out, SubString(text, token_first, token_last))
token_first = nextind(text, token_last)
end
Expand Down Expand Up @@ -90,12 +90,12 @@ prefix(::Diff{Words}, ::Symbol) = ""

function showdiff(io::IO, diff::Diff)
for (color, text) in diff.diff
print_with_color(color, io, prefix(diff, color), text)
printstyled(io, prefix(diff, color), text, color=color)
end
end

function Base.show(io::IO, diff::Diff)
print_with_color(:normal, io) # Reset colors.
printstyled(io, color=:normal) # Reset colors.
showdiff(io, diff)
end

Expand Down
Loading