From 7979503a4ebdcb0f1aeb01d05d54de9b403e905a Mon Sep 17 00:00:00 2001 From: odow Date: Wed, 6 Nov 2024 13:08:16 +1300 Subject: [PATCH 1/2] Simplify how we copy docstrings for MOI enums --- src/JuMP.jl | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/src/JuMP.jl b/src/JuMP.jl index b26532e9c8e..0f1c97f47c9 100644 --- a/src/JuMP.jl +++ b/src/JuMP.jl @@ -1313,20 +1313,9 @@ function _eval_instances_in_jump(moi_enum) # `eval` the instance as `const name = MOI.name`. eval(Expr(:const, Expr(:(=), name, enum))) # Documentation is not copied for a `const` expression of an object, so - # we need to manually set the docstring in this `@__MODULE__`. + # we need to manually set the docstring. docstr = Docs.docstr(Docs.Binding(MOI, name)) - d = Docs.DocStr( - docstr.text, - nothing, - Dict{Symbol,Any}( - :typesig => Union{}, - :module => @__MODULE__, - :linenumber => @__LINE__, - :binding => getfield(@__MODULE__, name), - :path => @__FILE__, - ), - ) - Docs.doc!(@__MODULE__, Docs.Binding(@__MODULE__, name), d, Union{}) + Docs.doc!(@__MODULE__, Docs.Binding(@__MODULE__, name), docstr) end return end From 687d46d8e03ac0726a49a0005c49cd6741b5de5c Mon Sep 17 00:00:00 2001 From: odow Date: Wed, 6 Nov 2024 13:43:13 +1300 Subject: [PATCH 2/2] Update --- src/JuMP.jl | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/src/JuMP.jl b/src/JuMP.jl index 0f1c97f47c9..94f7a17f0cf 100644 --- a/src/JuMP.jl +++ b/src/JuMP.jl @@ -1307,28 +1307,15 @@ include("print.jl") # `MOI.OPTIMAL`. This piece of code re-exports them from JuMP so that users can # use: `MOI.OPTIMAL`, `JuMP.OPTIMAL`, or `using JuMP; OPTIMAL`. -function _eval_instances_in_jump(moi_enum) - for enum in instances(moi_enum) - name = Symbol(enum) - # `eval` the instance as `const name = MOI.name`. - eval(Expr(:const, Expr(:(=), name, enum))) - # Documentation is not copied for a `const` expression of an object, so - # we need to manually set the docstring. - docstr = Docs.docstr(Docs.Binding(MOI, name)) - Docs.doc!(@__MODULE__, Docs.Binding(@__MODULE__, name), docstr) +for sym in [:ResultStatusCode, :TerminationStatusCode, :OptimizationSense] + @eval const $sym = MOI.$sym + for enum in instances(getfield(MOI, sym)) + @eval const $(Symbol(enum)) = $enum + docstr = Docs.docstr(Docs.Binding(MOI, Symbol(enum))) + Docs.doc!(@__MODULE__, Docs.Binding(@__MODULE__, Symbol(enum)), docstr) end - return end -const ResultStatusCode = MOI.ResultStatusCode -_eval_instances_in_jump(MOI.ResultStatusCode) - -const TerminationStatusCode = MOI.TerminationStatusCode -_eval_instances_in_jump(MOI.TerminationStatusCode) - -const OptimizationSense = MOI.OptimizationSense -_eval_instances_in_jump(MOI.OptimizationSense) - # JuMP exports everything except internal symbols, which are defined as those # whose name starts with an underscore. Macros whose names start with # underscores are internal as well. If you don't want all of these symbols