Skip to content

Commit

Permalink
Merge branch 'master' into 1.9-ext
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Jun 22, 2023
2 parents e8b82e3 + c5935e6 commit 74d513f
Show file tree
Hide file tree
Showing 29 changed files with 687 additions and 641 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "JuMP"
uuid = "4076af6c-e467-56ae-b986-b466b2749572"
repo = "https://github.com/jump-dev/JuMP.jl.git"
version = "1.11.1"
version = "1.12.0"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand All @@ -20,7 +20,7 @@ JuMPDimensionalDataExt = "DimensionalData"

[compat]
DimensionalData = "0.24"
MathOptInterface = "1.14"
MathOptInterface = "1.17"
MutableArithmetics = "1"
OrderedCollections = "1"
SnoopPrecompile = "1"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ embedded in [Julia](https://julialang.org/). You can find out more about us by
visiting [jump.dev](https://jump.dev).


**Latest Release**: [![version](https://juliahub.com/docs/JuMP/DmXqY/1.11.1/version.svg)](https://juliahub.com/ui/Packages/JuMP/DmXqY/1.11.1) (`release-1.0` branch):
**Latest Release**: [![version](https://juliahub.com/docs/JuMP/DmXqY/1.12.0/version.svg)](https://juliahub.com/ui/Packages/JuMP/DmXqY/1.12.0) (`release-1.0` branch):
* Installation via the Julia package manager:
* `import Pkg; Pkg.add("JuMP")`
* Get help:
Expand Down
226 changes: 226 additions & 0 deletions docs/DocumenterReference.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
# Copyright 2023, Oscar Dowson and contributors
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.

module DocumenterReference

import Documenter
import Markdown
import MarkdownAST

@enum(
DocType,
DOCTYPE_ABSTRACT_TYPE,
DOCTYPE_CONSTANT,
DOCTYPE_FUNCTION,
DOCTYPE_MACRO,
DOCTYPE_MODULE,
DOCTYPE_STRUCT,
)

struct _Config
current_module::Module
root::String
subdirectory::String
modules::Dict{Module,<:Vector}
end

const CONFIG = _Config[]

abstract type APIBuilder <: Documenter.Builder.DocumentPipeline end

Documenter.Selectors.order(::Type{APIBuilder}) = 0.0

"""
automatic_reference_documentation(;
root::String,
subdirectory::String,
modules::Dict{Module,Vector{Pair{String,DocType}}},
)
Automatically creates the API reference documentation for `current_module` and
returns a `Vector` which can be used in the `pages` argument of
`Documenter.makedocs`.
## Arguments
* `current_module`: the module from which to create an API reference.
* `subdirectory`: the directory relative to the documentation root in which to
write the API files.
* `modules`: a dictionary mapping modules to a vector of non-exported
docstrings to include in the API reference. Each element is a pair which maps
the docstring signature to a [`DocumenterReference.DocType`](@ref) enum.
## Multiple instances
Each time you call this function, a new object is added to the global variable
`DocumenterReference.CONFIG`.
"""
function automatic_reference_documentation(;
root::String,
subdirectory::String,
modules::Vector,
)
_to_extras(m::Module) = m => Any[]
_to_extras(m::Pair) = m
_modules = Dict(_to_extras(m) for m in modules)
list_of_pages = Any[]
for m in modules
current_module = first(_to_extras(m))
pages = _automatic_reference_documentation(
current_module;
root,
subdirectory,
modules = _modules,
)
push!(list_of_pages, "$current_module" => pages)
end
return "API Reference" => list_of_pages
end

function _automatic_reference_documentation(
current_module::Module;
root::String,
subdirectory::String,
modules::Dict{Module,<:Vector},
)
push!(CONFIG, _Config(current_module, root, subdirectory, modules))
return "$subdirectory/$current_module.md"
end

function _exported_symbols(mod)
contents = Pair{Symbol,DocType}[]
for n in names(mod)
f = getfield(mod, n)
f_str = string(f)
if startswith(f_str, "@")
push!(contents, n => DOCTYPE_MACRO)
elseif startswith(f_str, "Abstract")
push!(contents, n => DOCTYPE_ABSTRACT_TYPE)
elseif f isa Type
push!(contents, n => DOCTYPE_STRUCT)
elseif f isa Function
if islowercase(f_str[1])
push!(contents, n => DOCTYPE_FUNCTION)
else
push!(contents, n => DOCTYPE_STRUCT)
end
elseif f isa Module
push!(contents, n => DOCTYPE_MODULE)
else
push!(contents, n => DOCTYPE_CONSTANT)
end
end
order = Dict(
DOCTYPE_MODULE => 0,
DOCTYPE_MACRO => 1,
DOCTYPE_FUNCTION => 2,
DOCTYPE_ABSTRACT_TYPE => 3,
DOCTYPE_STRUCT => 4,
DOCTYPE_CONSTANT => 5,
)
return sort(contents; by = x -> (order[x[2]], "$(x[1])"))
end

function _iterate_over_symbols(f, config)
current_module = config.current_module
modules = get(config.modules, config.current_module, Any[])
for (key, type) in vcat(_exported_symbols(current_module), modules)
if key isa Symbol
doc = Base.Docs.doc(Base.Docs.Binding(current_module, key))
if occursin("No documentation found.", string(doc))
if type == DOCTYPE_MODULE
mod = getfield(current_module, key)
if mod == current_module || !haskey(config.modules, mod)
continue
end
else
error("Documentation missing for $key")
end
end
end
f(key, type)
end
return
end

function _to_string(x::DocType)
if x == DOCTYPE_ABSTRACT_TYPE
return "abstract type"
elseif x == DOCTYPE_CONSTANT
return "constant"
elseif x == DOCTYPE_FUNCTION
return "function"
elseif x == DOCTYPE_MACRO
return "macro"
elseif x == DOCTYPE_MODULE
return "module"
elseif x == DOCTYPE_STRUCT
return "struct"
end
end

function _build_api_page(document::Documenter.Document, config::_Config)
subdir = config.subdirectory
overview_md = """
```@meta
EditURL = nothing
```
# [$(config.current_module)](@id DocumenterReference_$(config.current_module))
This page lists the public API of `$(config.current_module)`.
!!! info
This page is an unstructured list of the $(config.current_module) API. For a
more structured overview, read the Manual or Tutorial parts of this
documentation.
Load all of the public the API into the current scope with:
```julia
using $(config.current_module)
```
Alternatively, load only the module with:
```julia
import $(config.current_module)
```
and then prefix all calls with `$(config.current_module).` to create
`$(config.current_module).<NAME>`.
"""
list_of_docstrings = String[]
_iterate_over_symbols(config) do key, type
if type == DOCTYPE_MODULE
return
end
push!(
list_of_docstrings,
"## `$key`\n\n```@docs\n$(config.current_module).$key\n```\n\n",
)
return
end
md_page = Markdown.parse(overview_md * join(list_of_docstrings, "\n"))
filename = "$subdir/$(config.current_module).md"
document.blueprint.pages[filename] = Documenter.Page(
filename, # source, gets ignored because of `EditURL = nothing`.
"$(document.user.build)/$filename", # build,
"$(document.user.build)/", # workdir,
md_page.content,
Documenter.Globals(),
convert(MarkdownAST.Node, md_page),
)
return
end

function Documenter.Selectors.runner(
::Type{APIBuilder},
document::Documenter.Document,
)
@info "APIBuilder: creating API reference"
for config in CONFIG
_build_api_page(document, config)
end
return
end

end # module
6 changes: 5 additions & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
DimensionalData = "0703355e-b756-11e9-17c0-8b28908087d0"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
Dualization = "191a621a-6537-11e9-281d-650236a99e60"
GLPK = "60bf3e95-4087-53dc-ae20-288a0d20c6a6"
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
HiGHS = "87dc4568-4c63-4d18-b0c0-bb2238e4078b"
Expand All @@ -14,6 +15,8 @@ JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
JSONSchema = "7d188eb4-7ad8-530c-ae41-71a32a6d4692"
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306"
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
MarkdownAST = "d0879d2d-cac2-40c8-9cee-1863dc0c7391"
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
MultiObjectiveAlgorithms = "0327d340-17cd-11ea-3e99-2fd5d98cecda"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Expand All @@ -32,11 +35,12 @@ Clarabel = "=0.5.1"
DataFrames = "1"
DimensionalData = "0.24"
Documenter = "0.27.9, 0.28"
Dualization = "0.5"
GLPK = "=1.1.2"
HTTP = "1.5.4"
HiGHS = "=1.5.2"
Interpolations = "0.14"
Ipopt = "=1.4.0"
Ipopt = "=1.4.1"
JSON = "0.21"
JSONSchema = "1"
Literate = "2.8"
Expand Down
Loading

0 comments on commit 74d513f

Please sign in to comment.