Skip to content

Commit

Permalink
Run CI on experimental *.md doc files (#4083)
Browse files Browse the repository at this point in the history
* Move linking of experimental docs to separate function

* Refactor `link_experimental_docs`

* Clean up

* Only delete "wrong" symlinks

* Move `walkdir` hack in another file

* Fix doctests
  • Loading branch information
joschmitt authored Sep 16, 2024
1 parent 969f929 commit 9896ed1
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 31 deletions.
8 changes: 8 additions & 0 deletions docs/documenter_helpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,11 @@ else
end
end
end

# We monkey-patch Base.walkdir to use true as default value for follow_symlinks
# (normally false is the default), in order to "trick" the Documenter code into
# following those symlinks.
# See also:
# https://github.com/JuliaDocs/Documenter.jl/pull/552
# https://github.com/JuliaLang/julia/blob/master/doc/make.jl#L19
Base.walkdir(str::String) = Base.walkdir(str; follow_symlinks=true)
34 changes: 7 additions & 27 deletions docs/make_work.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@ include("citation_style.jl")
# Remove the module prefix
Base.print(io::IO, b::Base.Docs.Binding) = print(io, b.var)

# We monkey-patch Base.walkdir to use true as default value for follow_symlinks
# (normally false is the default), in order to "trick" the Documenter code into
# following those symlinks.
# See also:
# https://github.com/JuliaDocs/Documenter.jl/pull/552
# https://github.com/JuliaLang/julia/blob/master/doc/make.jl#L19
Base.walkdir(str::String) = Base.walkdir(str; follow_symlinks=true)

# When we read a `doc.main` from an experimental package, we need to equip all
# its entries with a prefix to fit with our docs. The doc.main of an
# experimental package will contain paths relative to
Expand Down Expand Up @@ -83,22 +75,13 @@ function setup_experimental_package(Oscar::Module, package_name::String)
return []
end

# Set symlink inside docs/src/experimental
symlink_link = joinpath(Oscar.oscardir, "docs/src/Experimental", package_name)
symlink_target = joinpath(Oscar.oscardir, "experimental", package_name, "docs", "src")

if !ispath(symlink_target)
# Assumes that a symbolic link from `experimental/package_name/docs/src`
# to `docs/src/Experimental/package_name` has been created (or there is no
# documentation for this package)
if !ispath(joinpath(Oscar.oscardir, "docs/src/Experimental", package_name))
return []
end

if !ispath(symlink_link)
symlink(symlink_target, symlink_link)
elseif !islink(symlink_link) || readlink(symlink_link) != symlink_target
error("""$symlink_link already exists, but is not a symlink to $symlink_target
Please investigate the contents of $symlink_link,
optionally move them somewhere else and delete the directory once you are done.""")
end

# Read doc.main of package
exp_s = read(doc_main_path, String)
exp_doc = eval(Meta.parse(exp_s))
Expand All @@ -116,15 +99,12 @@ function doit(
doctest::Union{Bool,Symbol}=true,
)

# Remove symbolic links from earlier runs
expdocdir = joinpath(Oscar.oscardir, "docs", "src", "Experimental")
for x in readdir(expdocdir; join=true)
islink(x) && rm(x)
end

# include the list of pages, performing substitutions
s = read(joinpath(Oscar.oscardir, "docs", "doc.main"), String)
doc = eval(Meta.parse(s))

# Link experimental docs to `docs/src` and collect the documentation pages
Oscar.link_experimental_docs()
collected = Any["Experimental/intro.md"]
for pkg in Oscar.exppkgs
pkgdocs = setup_experimental_package(Oscar, pkg)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
```@meta
CurrentModule = Oscar
DocTestSetup = Oscar.doctestsetup()
```

# Abstract Varieties
Expand Down
2 changes: 1 addition & 1 deletion experimental/IntersectionTheory/docs/src/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ julia> Z = dual(tautological_bundles(PF)[1])
AbstractBundle of rank 1 on AbstractVariety of dim 8
julia> z = chern_class(Z, 1)
h
z
julia> integral((2*p + z)^8)
92
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
```@meta
CurrentModule = Oscar
DocTestSetup = Oscar.doctestsetup()
```

# Matroid Realization Spaces
Expand Down Expand Up @@ -68,8 +69,7 @@ Blowup
with domain
scheme over QQ covered with 2 patches
1a: [(s1//s0), x1, x2] scheme(-(s1//s0)*x1 + 4*(s1//s0) + x2^2 - 8) \ scheme((x1 - x2)*x2*x1*(x2 - 1)*(x1 - 1)*(x1 + x2^2 - x2)*(x1*x2 - x1 - x2^2))
2a: [(s0//s1), x2] scheme(0) \ scheme(((s0//s1)*x2^2 - 8*(s0//s1) - x2 + 4)*x2*((s0//s1)*x2^2 - 8*(s0//s1) + 4)*(x2 - 1)*((s0//s1)*x2^2 - 8*(s0//s1) + 3)*((s0//s1)*x2^2 - 8*(s0//s1) + x2^2 - x2 + 4)*((
s0//s1)*x2^3 - (s0//s1)*x2^2 - 8*(s0//s1)*x2 + 8*(s0//s1) - x2^2 + 4*x2 - 4))
2a: [(s0//s1), x2] scheme(0) \ scheme(((s0//s1)*x2^2 - 8*(s0//s1) - x2 + 4)*x2*((s0//s1)*x2^2 - 8*(s0//s1) + 4)*(x2 - 1)*((s0//s1)*x2^2 - 8*(s0//s1) + 3)*((s0//s1)*x2^2 - 8*(s0//s1) + x2^2 - x2 + 4)*((s0//s1)*x2^3 - (s0//s1)*x2^2 - 8*(s0//s1)*x2 + 8*(s0//s1) - x2^2 + 4*x2 - 4))
and exceptional divisor
effective cartier divisor defined by
sheaf of ideals with restrictions
Expand Down
40 changes: 39 additions & 1 deletion src/utils/docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@

# Oscar needs some complicated setup to get the printing right. This provides a
# helper function to set this up consistently.
doctestsetup() = :(using Oscar; Oscar.AbstractAlgebra.set_current_module(@__MODULE__))
function doctestsetup()
link_experimental_docs()
return :(using Oscar; Oscar.AbstractAlgebra.set_current_module(@__MODULE__))
end

# use tempdir by default to ensure a clean manifest (and avoid modifying the project)
function doc_init(;path=mktempdir())
Expand Down Expand Up @@ -231,3 +234,38 @@ function build_doc(; doctest::Union{Symbol, Bool} = false, warnonly = true, open
@warn versionwarn
end
end

# Create symbolic links from any documentation directory in `experimental` into
# `docs/src`
function link_experimental_docs()
# Remove symbolic links from earlier runs
expdocdir = joinpath(oscardir, "docs", "src", "Experimental")
for x in readdir(expdocdir; join=true)
!islink(x) && continue
pkg = splitpath(x)[end]
if !(pkg in exppkgs)
# We don't know this link, let's remove it
rm(x)
end
end

for pkg in exppkgs
# Set symlink inside docs/src/experimental
symlink_link = joinpath(oscardir, "docs/src/Experimental", pkg)
symlink_target = joinpath(oscardir, "experimental", pkg, "docs", "src")

if !ispath(symlink_target)
continue
end

if !ispath(symlink_link)
symlink(symlink_target, symlink_link)
elseif !islink(symlink_link) || readlink(symlink_link) != symlink_target
error("""$symlink_link already exists, but is not a symlink to $symlink_target
Please investigate the contents of $symlink_link,
optionally move them somewhere else and delete the directory once you are done.""")
end
end

return nothing
end

0 comments on commit 9896ed1

Please sign in to comment.