-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move ConstructionBase dependency to an extension on 1.9+
The dependency on ConstructionBase serves to provide a few convenience methods for users of packages like Accessors; it doesn't provide any functionality used directly by Legolas. This makes it a perfect candidate for a package extension. Package extensions are new in Julia 1.9, and Legolas currently supports Julia 1.6. That means that we can't fully remove ConstructionBase as a direct dependency yet, but we can restructure things to make that as easy as possible once we drop support for earlier Julia versions.
- Loading branch information
Showing
4 changed files
with
45 additions
and
23 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
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,32 @@ | ||
module LegolasConstructionBaseExt | ||
|
||
using ConstructionBase | ||
using Legolas | ||
|
||
using Legolas: AbstractRecord | ||
|
||
# We need a bit of extra work to integrate with ConstructionBase for pre-1.7 due | ||
# to the overload of `propertynames(::Tables.AbstractRow)`. We could overload | ||
# `check_properties_are_fields` but that's not part of the public API, so this | ||
# is safer. | ||
if VERSION < v"1.7" | ||
ConstructionBase.getproperties(r::AbstractRecord) = NamedTuple(r) | ||
|
||
# This is largely copy-paste from `ConstructionBase.setproperties_object`: | ||
# https://github.com/JuliaObjects/ConstructionBase.jl/blob/cd24e541fd90ab54d2ee12ddd6ccd229be9a5f1e/src/ConstructionBase.jl#L211-L218 | ||
function ConstructionBase.setproperties(r::R, patch::NamedTuple) where {R<:AbstractRecord} | ||
nt = getproperties(r) | ||
nt_new = merge(nt, patch) | ||
check_patch_properties_exist(nt_new, nt, r, patch) | ||
args = Tuple(nt_new) # old Julia inference prefers if we wrap in `Tuple` | ||
return constructorof(R)(args...) | ||
end | ||
end | ||
|
||
function ConstructionBase.constructorof(::Type{<:R}) where {R<:AbstractRecord} | ||
nt = NamedTuple{fieldnames(R)} | ||
T = Base.typename(R).wrapper | ||
return (args...) -> T(nt(args)) | ||
end | ||
|
||
end # module |
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