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

improve macro-related documentation #557

Merged
merged 1 commit into from
Jan 11, 2022
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
26 changes: 20 additions & 6 deletions src/base/macros/change_bounds.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
"""
@_change_bounds_fn ModelType IdxType [plural] [inplace] begin ... end

A helper for creating simple bounds-changing function similar to
[`change_bounds`](@ref).
"""
macro _change_bounds_fn(model_type, idx_type, args...)
body = last(args)
typeof(body) == Expr || throw(DomainError(body, "missing function body"))
Expand Down Expand Up @@ -41,10 +47,18 @@ macro _change_bounds_fn(model_type, idx_type, args...)
```
"""

return :(@doc $docstring $fname(
model::$model_type,
$idx_var::$idx_type;
lower = $missing_default,
upper = $missing_default,
) = $body)
Expr(
:macrocall,
Symbol("@doc"),
__source__,
docstring,
:(
$fname(
model::$model_type,
$idx_var::$idx_type;
lower = $missing_default,
upper = $missing_default,
) = $body
),
)
end
15 changes: 14 additions & 1 deletion src/base/macros/remove_item.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@

"""
@ _remove_fn objname ModelType IndexType [plural] [inplace] begin ... end

A helper for creating functions that follow the `remove_objname` template, such
as [`remove_metabolites`](@ref) and [`remove_reaction`](@ref).
"""
macro _remove_fn(objname, model_type, idx_type, args...)
body = last(args)
typeof(body) == Expr || throw(DomainError(body, "missing function body"))
Expand All @@ -24,5 +31,11 @@ macro _remove_fn(objname, model_type, idx_type, args...)
$(inplace ? "in-place" : "and return the modified model").
"""

return :(@doc $docstring $fname(model::$model_type, $idx_var::$idx_type) = $body)
Expr(
:macrocall,
Symbol("@doc"),
__source__,
docstring,
:($fname(model::$model_type, $idx_var::$idx_type) = $body),
)
end
20 changes: 14 additions & 6 deletions src/base/macros/serialized.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""
_serialized_change_unwrap(fn::Symbol)
@_serialized_change_unwrap function

Creates a simple wrapper structure that calls a function transparently on the
internal precached model. Internal type is returned (because this would break
the consistency of serialization).
Creates a simple wrapper structure that calls the `function` transparently on
the internal precached model. Internal type is returned (because this would
break the consistency of serialization).
"""
macro _serialized_change_unwrap(fn::Symbol)
docstring = """
Expand All @@ -12,6 +12,14 @@ macro _serialized_change_unwrap(fn::Symbol)
Calls [`$fn`](@ref) of the internal serialized model type.
Returns the modified un-serialized model.
"""
:(@doc $docstring $fn(model::Serialized, args...; kwargs...) =
$fn(unwrap_serialized(model), args...; kwargs...))
Expr(
:macrocall,
Symbol("@doc"),
__source__,
docstring,
:(
$fn(model::Serialized, args...; kwargs...) =
$fn(unwrap_serialized(model), args...; kwargs...)
),
)
end