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

allow running doctests with Revise #38258

Merged
merged 1 commit into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ debug release : % : julia-%
docs: julia-sysimg-$(JULIA_BUILD_MODE)
@$(MAKE) $(QUIET_MAKE) -C $(BUILDROOT)/doc JULIA_EXECUTABLE='$(call spawn,$(JULIA_EXECUTABLE_$(JULIA_BUILD_MODE))) --startup-file=no'

docs-revise:
@$(MAKE) $(QUIET_MAKE) -C $(BUILDROOT)/doc JULIA_EXECUTABLE='$(call spawn,$(JULIA_EXECUTABLE_$(JULIA_BUILD_MODE))) --startup-file=no' revise=true

check-whitespace:
ifneq ($(NO_GIT), 1)
@$(JULIAHOME)/contrib/check-whitespace.sh
Expand Down
3 changes: 2 additions & 1 deletion doc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ help:
@echo "To run linkcheck, use 'make <target> linkcheck=true'"
@echo "To run doctests, use 'make <target> doctest=true'"
@echo "To fix outdated doctests, use 'make <target> doctest=fix'"
@echo "To run doctests using Revise (to test changes without rebuilding the sysimage), use 'make <target> doctest=true revise=true'"


DOCUMENTER_OPTIONS := linkcheck=$(linkcheck) doctest=$(doctest) buildroot=$(call cygpath_w,$(BUILDROOT)) \
texplatform=$(texplatform)
texplatform=$(texplatform) revise=$(revise)

UNICODE_DATA_VERSION=13.0.0
$(SRCCACHE)/UnicodeData-$(UNICODE_DATA_VERSION).txt:
Expand Down
77 changes: 71 additions & 6 deletions doc/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -178,18 +178,83 @@ const PAGES = [
]
end

const use_revise = "revise=true" in ARGS
if use_revise
let revise_env = joinpath(@__DIR__, "deps", "revise")
Pkg.activate(revise_env)
Pkg.add("Revise"; preserve=Pkg.PRESERVE_NONE)
Base.ACTIVE_PROJECT[] = nothing
pushfirst!(LOAD_PATH, revise_env)
end
end
function maybe_revise(ex)
use_revise || return ex
STDLIB_DIR = Sys.STDLIB
STDLIBS = filter!(x -> isfile(joinpath(STDLIB_DIR, x, "src", "$(x).jl")), readdir(STDLIB_DIR))
return quote
$ex
using Revise
const STDLIBS = $STDLIBS
union!(Revise.stdlib_names, Symbol.(STDLIBS))
Revise.track(Core.Compiler)
Revise.track(Base)
for (id, mod) in Base.loaded_modules
if id.name in STDLIBS
Revise.track(mod)
end
end
timholy marked this conversation as resolved.
Show resolved Hide resolved
Revise.revise()
end
end

for stdlib in STDLIB_DOCS
@eval using $(stdlib.stdlib)
# All standard library modules get `using $STDLIB` as their global
DocMeta.setdocmeta!(Base.root_module(Base, stdlib.stdlib), :DocTestSetup, :(using $(stdlib.stdlib)), recursive=true)
DocMeta.setdocmeta!(
Base.root_module(Base, stdlib.stdlib),
:DocTestSetup,
maybe_revise(:(using $(stdlib.stdlib)));
recursive=true,
)
end
# A few standard libraries need more than just the module itself in the DocTestSetup.
# This overwrites the existing ones from above though, hence the warn=false.
DocMeta.setdocmeta!(SparseArrays, :DocTestSetup, :(using SparseArrays, LinearAlgebra), recursive=true, warn=false)
DocMeta.setdocmeta!(SuiteSparse, :DocTestSetup, :(using SparseArrays, LinearAlgebra, SuiteSparse), recursive=true, warn=false)
DocMeta.setdocmeta!(UUIDs, :DocTestSetup, :(using UUIDs, Random), recursive=true, warn=false)
DocMeta.setdocmeta!(Pkg, :DocTestSetup, :(using Pkg, Pkg.Artifacts), recursive=true, warn=false)
DocMeta.setdocmeta!(Base.BinaryPlatforms, :DocTestSetup, :(using Base.BinaryPlatforms), recursive=true, warn=false)
DocMeta.setdocmeta!(
SparseArrays,
:DocTestSetup,
maybe_revise(:(using SparseArrays, LinearAlgebra));
recursive=true, warn=false,
)
DocMeta.setdocmeta!(
SuiteSparse,
:DocTestSetup,
maybe_revise(:(using SparseArrays, LinearAlgebra, SuiteSparse));
recursive=true, warn=false,
)
DocMeta.setdocmeta!(
UUIDs,
:DocTestSetup,
maybe_revise(:(using UUIDs, Random));
recursive=true, warn=false,
)
DocMeta.setdocmeta!(
Pkg,
:DocTestSetup,
maybe_revise(:(using Pkg, Pkg.Artifacts));
recursive=true, warn=false,
)
DocMeta.setdocmeta!(
Base,
:DocTestSetup,
maybe_revise(:(;;));
recursive=true,
)
DocMeta.setdocmeta!(
Base.BinaryPlatforms,
:DocTestSetup,
maybe_revise(:(using Base.BinaryPlatforms));
recursive=true, warn=false,
)

let r = r"buildroot=(.+)", i = findfirst(x -> occursin(r, x), ARGS)
global const buildroot = i === nothing ? (@__DIR__) : first(match(r, ARGS[i]).captures)
Expand Down