Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Mirek Kratochvil <[email protected]>
  • Loading branch information
oxinabox and exaexa authored Oct 8, 2024
1 parent f516db2 commit 64177fa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion docs/src/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ A.accessors()

@test length(A.accessors()) == 35 #src

@test length(A.required_functions()) == 11
@test length(A.required_accessors()) == 11 #src

# You do not need to overload all of them (e.g., if you model does not have any
# genes you can completely omit all gene-related functions). The main required
Expand Down
23 changes: 12 additions & 11 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import SHA: sha256
import InteractiveUtils: methodswith


const REQUIRED_FUNCTIONS = Function[]
const REQUIRED_ACCESSORS = Function[]
macro required(sig)
call_ex = sig.head == :(::) ? sig.args[1] : sig
call_ex.head == :call || error("malformed signature definition")
Expand All @@ -18,7 +18,7 @@ macro required(sig)

return esc(quote
Base.@__doc__ $call_ex = $unimplemented(typeof($model_arg), $(Meta.quot(name)))
push!(REQUIRED_FUNCTIONS, $name)
push!(REQUIRED_ACCESSORS, $name)
$name
end)
end
Expand All @@ -36,7 +36,7 @@ For typesystem reasons, the list **will not contain** methods for
[`save`](@ref) and [`filename_extensions`](@ref) that dispatch on type objects.
You should implement these as well.
See also [`required_functions`](@ref) for the minimal list that must be implemented.
See also [`required_accessors`](@ref) for the minimal list that must be implemented.
"""
function accessors()
ms = Method[]
Expand All @@ -54,17 +54,18 @@ $(TYPEDSIGNATURES)
Provide a `methodswith`-style listing of functions that the model implementors
must implement to have a functional `AbstractFBCModel`.
constrast this to the longer list of items that are returned by [`accessors`](@ref).
The extra elements have sensible defaults based on these required functions.
Where-as not defining these methods will result in errors.
Though depending on your models capability relying on those defaults may mean some
functionality is hidden.
(e.g. default [`coupling`](@ref) if you don't implement that is to assume none)
The output listing is a subset of the longer list returned by
[`accessors`](@ref). Some of the accessors may have sensible defaults -- e.g.,
it is safe to assume an empty default [`coupling`](@ref) if the functions are
not defined. The accessors which do not possess a natural default and thus
*must be defined* (and trying to use a model without them will almost certainly
cause runtime errors) are exactly the ones listed by this function.
"""
function required_functions()
function required_accessors()
ms = Method[]
for f = REQUIRED_FUNCTIONS
for f = REQUIRED_ACCESSORS
methodswith(AbstractFBCModels.AbstractFBCModel, f, ms)
end
return ms
Expand Down

0 comments on commit 64177fa

Please sign in to comment.