Skip to content

Commit

Permalink
Merge pull request #109 from SymbolicML/pretty-print
Browse files Browse the repository at this point in the history
feat: deprecate `raw` for `pretty`
  • Loading branch information
MilesCranmer authored Nov 2, 2024
2 parents dbc82a5 + fef28bf commit d5fab73
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "DynamicExpressions"
uuid = "a40a106e-89c9-4ca8-8020-a735e8728b6b"
authors = ["MilesCranmer <[email protected]>"]
version = "1.4.1"
version = "1.5.0"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Expand Down
4 changes: 3 additions & 1 deletion src/Interfaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ function _check_set_constants!(ex::AbstractExpression)
return first(get_scalar_constants(ex)) x2
end
function _check_string_tree(ex::AbstractExpression)
return string_tree(ex) isa AbstractString
return string_tree(ex) isa AbstractString &&
string_tree(ex; pretty=false) isa AbstractString &&
string_tree(ex; pretty=true) isa AbstractString
end
function _check_default_node(ex::AbstractExpression{T}) where {T}
ET = typeof(ex)
Expand Down
1 change: 0 additions & 1 deletion src/ParametricExpression.jl
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,6 @@ function string_tree(
display_variable_names=nothing,
X_sym_units=nothing,
y_sym_units=nothing,
raw=false,
kws...,
)
# TODO: HACK we ignore display_variable_names and others
Expand Down
15 changes: 14 additions & 1 deletion src/Strings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,14 @@ function string_tree(
f_variable::F1=string_variable,
f_constant::F2=string_constant,
variable_names::Union{AbstractVector{<:AbstractString},Nothing}=nothing,
pretty::Union{Bool,Nothing}=nothing, # Not used, but can be used by other types
# Deprecated
raw::Union{Bool,Nothing}=nothing,
varMap=nothing,
)::String where {T,F1<:Function,F2<:Function}
!isnothing(raw) &&
Base.depwarn("`raw` is deprecated; use `pretty` instead", :string_tree)
pretty = @something(pretty, _not(raw), false)
variable_names = deprecate_varmap(variable_names, varMap, :string_tree)
raw_output = tree_mapreduce(
let f_constant = f_constant,
Expand Down Expand Up @@ -186,14 +191,22 @@ for io in ((), (:(io::IO),))
f_variable::F1=string_variable,
f_constant::F2=string_constant,
variable_names::Union{AbstractVector{<:AbstractString},Nothing}=nothing,
pretty::Union{Bool,Nothing}=nothing, # Not used, but can be used by other types
# Deprecated
raw::Union{Bool,Nothing}=nothing,
varMap=nothing,
) where {F1<:Function,F2<:Function}
!isnothing(raw) &&
Base.depwarn("`raw` is deprecated; use `pretty` instead", :print_tree)
pretty = @something(pretty, _not(raw), false)
variable_names = deprecate_varmap(variable_names, varMap, :print_tree)
return println(
$(io...), string_tree(tree, operators; f_variable, f_constant, variable_names)
$(io...),
string_tree(tree, operators; f_variable, f_constant, variable_names, pretty),
)
end
end
_not(::Nothing) = nothing
_not(x) = !x

end

2 comments on commit d5fab73

@MilesCranmer
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

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/118586

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

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:

git tag -a v1.5.0 -m "<description of version>" d5fab73cebf3a1bdf2d94a11e4da6660cf707764
git push origin v1.5.0

Please sign in to comment.