Skip to content

Commit

Permalink
Use Base.TOML.Parser{Dates} for TOML parsing w/ Dates support (#3938)
Browse files Browse the repository at this point in the history
* Use `Base.TOML.Parser{Dates}` for TOML parsing w/ Dates support

This will allow us to delete the `.Dates` field upstream.

* Use `Base.TOMLCache(p::TOML.Parser)` constructor

These were relying on implicit `convert()` behavior in the previous
constructor, which is harmless in this case but best not to depend upon.

---------

Co-authored-by: Ian Butterworth <[email protected]>
(cherry picked from commit e4a6723)
  • Loading branch information
topolarity authored and KristofferC committed Sep 12, 2024
1 parent 0df656e commit 6993828
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
9 changes: 3 additions & 6 deletions src/Registry/registry_instance.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Base: UUID, SHA1
using TOML
using Dates
using Tar
using ..Versions: VersionSpec, VersionRange

Expand All @@ -15,19 +16,15 @@ function to_tar_path_format(file::AbstractString)
end

# See loading.jl
const TOML_CACHE = let parser = Base.TOML.Parser()
parser.Dates = Dates
Base.TOMLCache(parser, Dict{String, Dict{String, Any}}())
end
const TOML_CACHE = Base.TOMLCache(Base.TOML.Parser{Dates}())
const TOML_LOCK = ReentrantLock()
_parsefile(toml_file::AbstractString) = Base.parsed_toml(toml_file, TOML_CACHE, TOML_LOCK)
function parsefile(in_memory_registry::Union{Dict, Nothing}, folder::AbstractString, file::AbstractString)
if in_memory_registry === nothing
return _parsefile(joinpath(folder, file))
else
content = in_memory_registry[to_tar_path_format(file)]
parser = Base.TOML.Parser(content; filepath=file)
parser.Dates = Dates
parser = Base.TOML.Parser{Dates}(content; filepath=file)
return Base.TOML.parse(parser)
end
end
Expand Down
5 changes: 1 addition & 4 deletions src/Types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ function deepcopy_toml(x::Dict{String, Any})
end

# See loading.jl
const TOML_CACHE = let parser = Base.TOML.Parser()
parser.Dates = Dates
Base.TOMLCache(parser, Dict{String, Dict{String, Any}}())
end
const TOML_CACHE = Base.TOMLCache(Base.TOML.Parser{Dates}())
const TOML_LOCK = ReentrantLock()
# Some functions mutate the returning Dict so return a copy of the cached value here
parse_toml(toml_file::AbstractString) =
Expand Down

0 comments on commit 6993828

Please sign in to comment.