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

allow printing some TOML dictionaries inline by marking them with an IdSet #53233

Merged
merged 2 commits into from
Feb 8, 2024

Conversation

KristofferC
Copy link
Member

This was one way I came up with to "mark" what dictionaries one wants to print inline. I am not sure IdSet is even considered public but it seemed the most reasonable for this? I want to use this in Pkg to write some TOML files more terse.

cc @StefanKarpinski

@KristofferC
Copy link
Member Author

This is not correct:

d = Dict("deps" => Dict(
        "LocalPkg" => "fcf55292-0d03-4e8a-9e0b-701580031fc3", 
        "Example" => "7876af07-990d-54b4-ab0e-23690620f79a"),
   "sources" => Dict(
        "LocalPkg" => Dict("path" => "LocalPkg"),
        "Example" => Dict("url" => "https://github.com/JuliaLang/Example.jl")))

inline_tables = Base.IdSet{Dict}()
if haskey(d, "sources")
    for source in values(d["sources"])
        push!(inline_tables, source)
    end
end

TOML.print(d; sorted=true, inline_tables)

prints (loses the [sources]):

[deps]
Example = "7876af07-990d-54b4-ab0e-23690620f79a"
LocalPkg = "fcf55292-0d03-4e8a-9e0b-701580031fc3"
Example = {url = "https://github.com/JuliaLang/Example.jl"}
LocalPkg = {path = "LocalPkg"}

Copy link
Member

@vtjnash vtjnash left a comment

Choose a reason for hiding this comment

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

LGTM

@KristofferC KristofferC merged commit e68e432 into master Feb 8, 2024
5 of 7 checks passed
@KristofferC KristofferC deleted the kc/toml_inline_dict branch February 8, 2024 11:56
@KristofferC KristofferC added feature Indicates new feature / enhancement requests TOML labels Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Indicates new feature / enhancement requests TOML
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants