-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* DocStrings test code * Add PARS and METHODS to Reaction docstrings Uses PALEOboxes.DocStrings, which extends `DocStringExtensions` package * Julia 1.6 compatibility fix (replace(...) only takes one pattern) * another replace 1.6 compatibility fix Co-authored-by: Stuart Daines <sd336@um-serve>
- Loading branch information
Showing
14 changed files
with
290 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
name = "PALEOboxes" | ||
uuid = "804b410e-d900-4b2a-9ecd-f5a06d4c1fd4" | ||
authors = ["Stuart Daines <[email protected]>"] | ||
version = "0.16.0" | ||
version = "0.17.0" | ||
|
||
[deps] | ||
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf" | ||
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" | ||
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" | ||
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6" | ||
Infiltrator = "5903a43b-9cc3-4c30-8d17-598619ec4e9b" | ||
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240" | ||
|
@@ -27,6 +28,7 @@ YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6" | |
[compat] | ||
BenchmarkTools = "1.0" | ||
DataFrames = "1.1" | ||
DocStringExtensions = "0.8" | ||
Documenter = "0.27" | ||
Graphs = "1.4" | ||
Infiltrator = "1.0" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
""" | ||
DocStrings | ||
Extends Julia `DocStringExtensions` package to provide PALEO-specific "Abbreviations" to list | ||
Reaction Parameters and Variables in docstrings. | ||
exports PARS, METHODS_SETUP, METHODS_INITIALIZE, METHODS_DO | ||
`\$(PARS)` expands to a list of Reaction Parameters | ||
`\$(METHODS_SETUP)`, `\$(METHODS_INITIALIZE)`, `\$(METHODS_DO)` expand to a list of ReactionMethods and Variables | ||
NB: a Reaction is created with `create_reaction`. In addition, `\$(METHODS_DO)` etc call `register_methods(rj::AbstractReaction)`, | ||
so may fail if this call fails with default parameters. | ||
""" | ||
module DocStrings | ||
import DocStringExtensions as DSE | ||
import PALEOboxes as PB | ||
|
||
struct Pars <: DSE.Abbreviation end | ||
|
||
const PARS = Pars() | ||
|
||
function DSE.format(::Pars, buf, doc) | ||
local docs = get(doc.data, :fields, Dict()) | ||
local binding = doc.data[:binding] | ||
local object = Docs.resolve(binding) | ||
|
||
# println(buf, "PARS binding $binding object $object") | ||
|
||
try | ||
rj = PB.create_reaction(object, PB.ReactionBase(name="test", classname="test", external_parameters=Dict{String, Any}())) | ||
if hasproperty(rj, :pars) | ||
PB.add_par(rj, rj.pars) | ||
end | ||
# println(buf, "$object $(length(PB.get_parameters(rj))) Parameters" ) | ||
for p in PB.get_parameters(rj) | ||
md = "- `$(p.name)[$(typeof(p.v))]`=" | ||
md *= md_value(p.v) | ||
md *= isempty(p.units) ? "," : " ($(p.units))," | ||
md *= " `default_value`="*md_value(p.default_value)*"," | ||
md *= isempty(p.allowed_values) ? "" : " `allowed_values`=$(p.allowed_values)," | ||
md *= " `description`=\"$(escape_md(p.description))\"" | ||
println(buf, md) | ||
end | ||
catch e | ||
println(buf, escape_md("PARS exception: $e")) | ||
end | ||
return nothing | ||
end | ||
|
||
struct Methods <: DSE.Abbreviation | ||
field::Symbol | ||
end | ||
|
||
const METHODS_SETUP = Methods(:methods_setup) | ||
const METHODS_INITIALIZE = Methods(:methods_initialize) | ||
const METHODS_DO = Methods(:methods_do) | ||
|
||
function DSE.format(methods::Methods, buf, doc) | ||
local docs = get(doc.data, :fields, Dict()) | ||
local binding = doc.data[:binding] | ||
local object = Docs.resolve(binding) | ||
|
||
try | ||
# println(buf, "PARS binding $binding object $object") | ||
|
||
rj = PB.create_reaction(object, PB.ReactionBase(name="test", classname="test", external_parameters=Dict{String, Any}())) | ||
if hasproperty(rj, :pars) | ||
PB.add_par(rj, rj.pars) | ||
end | ||
|
||
d = PB.Domain(name="test", ID=1, parameters=Dict{String, Any}()) | ||
rj.base.domain = d | ||
PB.register_methods!(rj) | ||
|
||
for m in getproperty(rj.base, methods.field) | ||
println(buf, "- `$(m.name)`") | ||
for v in PB.get_variables(m) | ||
md = " - " | ||
md *= v.link_optional ? "\\[" : "" | ||
md *= "`$(v.localname)`" | ||
md *= v.link_optional ? "\\]" : "" | ||
ln = PB.combine_link_name(v) | ||
md *= (ln == v.localname) ? "" : " --> $(escape_md(ln))" | ||
units = PB.get_attribute(v, :units) | ||
md *= " ($(units))," | ||
md *= " `$(PB.get_var_type(v))`," | ||
vfunction = PB.get_attribute(v, :vfunction) | ||
md *= (ismissing(vfunction) || vfunction == PB.VF_Undefined) ? "" : " `$vfunction`," | ||
description = PB.get_attribute(v, :description) | ||
md *= " `description`=\"$(escape_md(description))\"" | ||
|
||
println(buf, md) | ||
end | ||
end | ||
catch e | ||
println(buf, escape_md("METHODS $methods exception: $e")) | ||
end | ||
|
||
return nothing | ||
end | ||
|
||
|
||
|
||
function escape_md(str::AbstractString) | ||
str = replace(str, "_"=>"\\_") | ||
str = replace(str, "\$"=>"\\\$") | ||
str = replace(str, "*"=>"\\*") | ||
return str | ||
end | ||
|
||
md_value(v) = "$v" | ||
md_value(v::AbstractString) = "\"$(escape_md(v))\"" | ||
function md_value(vv::Vector{<:AbstractString}) | ||
evv = [escape_md(v) for v in vv] | ||
return "$evv" | ||
end | ||
function md_value(vv::Vector) | ||
str = "$vv" | ||
str = replace(str, "["=>"\\[") | ||
str = replace(str, "]"=>"\\]") | ||
return str | ||
end | ||
|
||
export PARS, METHODS_SETUP, METHODS_INITIALIZE, METHODS_DO | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
9de81e1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register()
9de81e1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/59328
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: