Skip to content

Commit

Permalink
only support Julia 1.10+ (lts and newer)
Browse files Browse the repository at this point in the history
  • Loading branch information
aplavin committed Jan 12, 2025
1 parent 0f4d3b2 commit 415fb13
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 120 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ jobs:
fail-fast: false
matrix:
version:
- '1.6'
- 'lts'
- '1'
- 'pre'
Expand Down
14 changes: 1 addition & 13 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,12 @@ CompositionsBase = "a33af91c-f02d-484b-be07-31d278c5ca2b"
ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
InverseFunctions = "3587e190-3f89-42d0-90ee-14403ec27112"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[weakdeps]
AxisKeys = "94b1ba4f-4ee9-5380-92f1-94cde586c3c5"
IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
StructArrays = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand All @@ -41,16 +37,8 @@ IntervalSets = "0.7"
InverseFunctions = "0.1.5"
LinearAlgebra = "1"
MacroTools = "0.5"
Requires = "0.5, 1.0"
StaticArrays = "1"
StructArrays = "0.6, 0.7"
Test = "1"
Unitful = "1"
julia = "1.6"

[extras]
AxisKeys = "94b1ba4f-4ee9-5380-92f1-94cde586c3c5"
IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
StructArrays = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
julia = "1.10"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ For more detail, see [this tutorial](https://juliaobjects.github.io/Accessors.jl

# Featured extensions

- [AccessorsExtra.jl](https://github.com/JuliaAPlavin/AccessorsExtra.jl) [[docs](https://aplavin.github.io/AccessorsExtra.jl/test/notebook.html)] introduces additional optics and related functions, that are considered too experimental for inclusion in `Accessors`. For Julia 1.8 and older, `AccessorsExtra` also provides integrations with other packages; for Julia 1.9+, these are mostly included in `Accessors` itself.
- [AccessorsExtra.jl](https://github.com/JuliaAPlavin/AccessorsExtra.jl) [[docs](https://aplavin.github.io/AccessorsExtra.jl/test/notebook.html)] introduces additional optics and related functions that are considered too opinionated or too experimental for inclusion in `Accessors`.
2 changes: 1 addition & 1 deletion ext/StaticArraysExt.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module StaticArraysExt
isdefined(Base, :get_extension) ? (using StaticArrays) : (using ..StaticArrays)
using StaticArrays
using Accessors
import Accessors: setindex, delete, insert

Expand Down
13 changes: 1 addition & 12 deletions src/Accessors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ using MacroTools
using MacroTools: isstructdef, splitstructdef, postwalk
using InverseFunctions

if !isdefined(Base, :get_extension)
using Requires
end


include("setindex.jl")
include("optics.jl")
Expand All @@ -17,15 +13,8 @@ include("testing.jl")

# always include for now; see https://github.com/JuliaObjects/Accessors.jl/issues/192
include("../ext/DatesExt.jl")
if !isdefined(Base, :get_extension)
include("../ext/LinearAlgebraExt.jl")
include("../ext/TestExt.jl")
end

function __init__()
@static if !isdefined(Base, :get_extension)
@require StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" include("../ext/StaticArraysExt.jl")
end
if isdefined(Base.Experimental, :register_error_hint)
Base.Experimental.register_error_hint(MethodError) do io, exc, argtypes, kwargs
if exc.f === insert && argtypes[2] <: Accessors.DynamicIndexLens
Expand All @@ -48,7 +37,7 @@ function __init__()
(0, 1, 2, 3, 4)
```
""")
elseif (exc.f === test_getset_laws || exc.f === test_modify_law || exc.f === test_getsetall_laws || exc.f === test_insertdelete_laws) && isdefined(Base, :get_extension) && Base.get_extension(Accessors, :AccessorsTestExt) === nothing
elseif (exc.f === test_getset_laws || exc.f === test_modify_law || exc.f === test_getsetall_laws || exc.f === test_insertdelete_laws) && Base.get_extension(Accessors, :AccessorsTestExt) === nothing
print(io, "\nDid you forget to load Test?")
end
end
Expand Down
8 changes: 2 additions & 6 deletions src/functionlenses.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,8 @@ delete(s::AbstractString, o::Base.Fix2{typeof(first)}) = chop(s; head=o.x, tail=
delete(s::AbstractString, o::Base.Fix2{typeof(last)}) = chop(s; head=0, tail=o.x)

set(s::AbstractString, o::typeof(chomp), v) = endswith(s, '\n') ? v * '\n' : v
if VERSION >= v"1.8"
set(s::AbstractString, o::Base.Fix2{typeof(chopsuffix), <:AbstractString}, v) =
endswith(s, o.x) ? v * o.x : v
set(s::AbstractString, o::Base.Fix2{typeof(chopprefix), <:AbstractString}, v) =
startswith(s, o.x) ? o.x * v : v
end
set(s::AbstractString, o::Base.Fix2{typeof(chopsuffix), <:AbstractString}, v) = endswith(s, o.x) ? v * o.x : v
set(s::AbstractString, o::Base.Fix2{typeof(chopprefix), <:AbstractString}, v) = startswith(s, o.x) ? o.x * v : v

set(s::AbstractString, ::typeof(strip), v) = @set lstrip(rstrip(s)) = v
set(s::AbstractString, ::typeof(lstrip), v) = @set s |> lstrip(isspace, _) = v
Expand Down
9 changes: 0 additions & 9 deletions src/optics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,6 @@ function _set(obj, optic, val, ::SetBased)
""")
end

if VERSION < v"1.7"
struct Returns{V}
value::V
end
(o::Returns)(x) = o.value
else
using Base: Returns
end

@inline function _set(obj, optic, val, ::ModifyBased)
modify(Returns(val), obj, optic)
end
Expand Down
5 changes: 0 additions & 5 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
AxisKeys = "94b1ba4f-4ee9-5380-92f1-94cde586c3c5"
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
ConstructionBaseExtras = "914cd950-b775-4282-9f32-54fc4544c321"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953"
Expand All @@ -19,15 +18,11 @@ StructArrays = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"

[weakdeps]
ConstructionBaseExtras = "914cd950-b775-4282-9f32-54fc4544c321"

[compat]
Aqua = "0.8"
AxisKeys = "0.2"
BenchmarkTools = "1.3"
ConstructionBase = "1.5"
ConstructionBaseExtras = "0.1"
IntervalSets = "0.7"
InverseFunctions = "0.1.5"
MacroTools = "0.4.4, 0.5"
Expand Down
10 changes: 2 additions & 8 deletions test/perf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,8 @@ end
println("Right associative composition: $b_right")

@test b_default.allocs == 0
if VERSION >= v"1.10-"
@test_broken b_right.allocs == 0
elseif VERSION >= v"1.7"
@test b_right.allocs == 0
else
@test_broken right.allocs == 0
@test b_right.time > 2b_default.time
end
@test_broken b_right.allocs == 0
@test b_right.time b_default.time rtol=0.8
@test b_left.allocs == 0
@test b_left.time b_default.time rtol=0.8
end
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module TestAccessors
import PerformanceTestTools
import Accessors
import Aqua
VERSION v"1.9-" && Aqua.test_all(Accessors)
Aqua.test_all(Accessors)
PerformanceTestTools.@include("perf.jl")

include("test_examples.jl")
Expand Down
18 changes: 4 additions & 14 deletions test/test_core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -224,19 +224,9 @@ end
((@optic _.b.a.b[end]), 4.0),
((@optic _.b.a.b[end÷2+1]), 4.0),
]
if VERSION < v"1.7" || VERSION >= v"1.10-"
@inferred lens(obj)
@inferred set(obj, lens, val)
@inferred modify(identity, obj, lens)
else
@inferred lens(obj)
@inferred set(obj, lens, val)
@test_broken begin
# https://github.com/JuliaLang/julia/issues/43296
@inferred modify(identity, obj, lens)
true
end
end
@inferred lens(obj)
@inferred set(obj, lens, val)
@inferred modify(identity, obj, lens)
end
end

Expand Down Expand Up @@ -278,7 +268,7 @@ end
nt = (a=1, b=2, c=3)
l = @optic _[(:a, :c)]
@test l isa IndexLens
VERSION >= v"1.7" && @test l(nt) === (a=1, c=3)
@test l(nt) === (a=1, c=3)
@test set(nt, l, ('1', '2')) === (a='1', b=2, c='2')
@test set(nt, l, (c='2', a='1')) === (a='1', b=2, c='2')

Expand Down
26 changes: 10 additions & 16 deletions test/test_extensions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ using StructArrays
using Unitful


# most of the tests run on Julia 1.9 and later because of package extensions support
# StaticArrays is the exception: it's supported on earlier Julia versions with Requires


VERSION >= v"1.9-" && @testset "AxisKeys" begin
@testset "AxisKeys" begin
A = KeyedArray([1 2 3; 4 5 6], x=[:a, :b], y=11:13)

for B in (
Expand Down Expand Up @@ -48,7 +44,7 @@ VERSION >= v"1.9-" && @testset "AxisKeys" begin
@test_throws ArgumentError @set named_axiskeys(A) = (;)
end

VERSION >= v"1.9-" && @testset "IntervalSets" begin
@testset "IntervalSets" begin
int = Interval{:open, :closed}(1, 5)

@test Interval{:open, :closed}(1, 10) === @set int.right = 10
Expand Down Expand Up @@ -90,7 +86,7 @@ end
@test (@set v[1] = 10) === @SVector [10.,2,3]
@test (@set v[1] = π) === @SVector [π,2,3]
# requires ConstructionBase extension:
VERSION >= v"1.9-" && @test (@set v.x = 10) === @SVector [10.,2,3]
@test (@set v.x = 10) === @SVector [10.,2,3]

v = @MVector [1.,2,3]
@test (@set v[1] = 10)::MVector == @MVector [10.,2,3]
Expand Down Expand Up @@ -122,13 +118,11 @@ end
cmp(a::NamedTuple, b::NamedTuple) = Set(keys(a)) == Set(keys(b)) && NamedTuple{keys(b)}(a) === b
cmp(a::T, b::T) where {T} = a == b

if VERSION >= v"1.9-"
# require ConstructionBase extension
test_getset_laws(Tuple, SVector(0, 1), ('x', 'y'), (1, 2); cmp=cmp)
test_getset_laws(Tuple, MVector(0, 1), ('x', 'y'), (1, 2); cmp=cmp)
test_getset_laws(NamedTuple{(:x, :y)}, SVector(0, 1), (x='x', y='y'), (x=1, y=2); cmp=cmp)
test_getset_laws(NamedTuple{(:x, :y)}, SVector(0, 1), (y='x', x='y'), (x=1, y=2); cmp=cmp)
end
test_getset_laws(Tuple, SVector(0, 1), ('x', 'y'), (1, 2); cmp=cmp)
test_getset_laws(Tuple, MVector(0, 1), ('x', 'y'), (1, 2); cmp=cmp)
test_getset_laws(NamedTuple{(:x, :y)}, SVector(0, 1), (x='x', y='y'), (x=1, y=2); cmp=cmp)
test_getset_laws(NamedTuple{(:x, :y)}, SVector(0, 1), (y='x', x='y'), (x=1, y=2); cmp=cmp)

test_getset_laws(SVector, (0, 1), SVector('x', 'y'), SVector(1, 2); cmp=cmp)
test_getset_laws(MVector, (0, 1), MVector('x', 'y'), MVector(1, 2); cmp=cmp)

Expand All @@ -142,7 +136,7 @@ struct S{TA, TB}
b::TB
end

VERSION >= v"1.9-" && @testset "StructArrays" begin
@testset "StructArrays" begin
s = StructArray(([1, 2, 3],))
ss = @set s.:1 = 10:12
@test ss.:1 === 10:12
Expand Down Expand Up @@ -186,7 +180,7 @@ VERSION >= v"1.9-" && @testset "StructArrays" begin
test_getset_laws(propertynames, s, (1, 2), (:u, :v))
end

VERSION v"1.9-" && @testset "Unitful" begin
@testset "Unitful" begin
test_getset_laws(ustrip, 1u"m", 2., 3)
test_getset_laws(ustrip, 1u"m/mm", 2., 3)
end
Expand Down
33 changes: 12 additions & 21 deletions test/test_functionlenses.jl
Original file line number Diff line number Diff line change
Expand Up @@ -294,17 +294,11 @@ end
@test o(2) 0.8807970779778823
@test @inferred(set(2, o, 0.999)) 6.906754778648465

# parse-related
if VERSION >= v"1.8"
# on earlier versions,
# @optic(parse(Int, _)) isa Base.Fix1{typeof(parse), Type{T}} where {T}
# doesn't hold
@test @inferred(modify(x -> -2x, "3", @optic parse(Int, _))) == "-6"
@test_throws ErrorException modify(log10, "100", @optic parse(Int, _))
@test modify(log10, "100", @optic parse(Float64, _)) == "2.0"
test_getset_laws(@optic(parse(Int, _)), "3", -10, 123)
test_getset_laws(@optic(parse(Float64, _)), "3.0", -10., 123.)
end
@test @inferred(modify(x -> -2x, "3", @optic parse(Int, _))) == "-6"
@test_throws ErrorException modify(log10, "100", @optic parse(Int, _))
@test modify(log10, "100", @optic parse(Float64, _)) == "2.0"
test_getset_laws(@optic(parse(Int, _)), "3", -10, 123)
test_getset_laws(@optic(parse(Float64, _)), "3.0", -10., 123.)

# setting inverse
myasin(x) = asin(x)+2π
Expand Down Expand Up @@ -364,10 +358,9 @@ end
end

@testset "strings" begin
if VERSION >= v"1.8"
@test @inferred(modify(x -> x+1, " abc def", @optic(_ |> chopsuffix(_, "def") |> strip |> Elements()))) == " bcd def"
@test @inferred(modify(x -> x+1, " abc xyz", @optic(_ |> chopsuffix(_, "def") |> strip |> Elements()))) == " bcd!yz{"
end
@test @inferred(modify(x -> x+1, " abc def", @optic(_ |> chopsuffix(_, "def") |> strip |> Elements()))) == " bcd def"
@test @inferred(modify(x -> x+1, " abc xyz", @optic(_ |> chopsuffix(_, "def") |> strip |> Elements()))) == " bcd!yz{"

@test @inferred(modify(x -> x^2, "abc xyz", @optic(split(_, ' ') |> Elements()))) == "abcabc xyzxyz"
@test @inferred(modify(x -> x^2, " abc xyz", @optic(split(_, ' ') |> Elements()))) == " abcabc xyzxyz"

Expand All @@ -384,12 +377,10 @@ end
test_getset_laws(chomp, "abc\n", "def", "")
test_getset_laws(chomp, "abc\n\n", "def\n", "")

if VERSION >= v"1.8"
test_getset_laws(@optic(chopprefix(_, "def")), "def abc", "xyz", "")
test_getset_laws(@optic(chopsuffix(_, "def")), "abc def", "xyz", "")
test_getset_laws(@optic(chopprefix(_, "abc")), "def abc", "xyz", "")
test_getset_laws(@optic(chopsuffix(_, "abc")), "abc def", "xyz", "")
end
test_getset_laws(@optic(chopprefix(_, "def")), "def abc", "xyz", "")
test_getset_laws(@optic(chopsuffix(_, "def")), "abc def", "xyz", "")
test_getset_laws(@optic(chopprefix(_, "abc")), "def abc", "xyz", "")
test_getset_laws(@optic(chopsuffix(_, "abc")), "abc def", "xyz", "")

test_getset_laws(@optic(split(_, ' ')), " abc def ", ["z"], [])
test_getset_laws(@optic(split(_, ' ')), " abc def ", ["", "z"], [])
Expand Down
14 changes: 2 additions & 12 deletions test/test_getsetall.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ using Accessors: test_getsetall_laws, test_modify_law
using StaticNumbers
using StaticArrays

@static if VERSION < v"1.9-"
# for StaticArrays constructorof: ConstructionBase itself only supports it through 1.9 extension
using ConstructionBaseExtras
end

@testset "getall" begin
obj = (a=1, b=2.0, c='3')
@test (1,) === @inferred getall(obj, @optic _.a)
Expand Down Expand Up @@ -133,13 +128,8 @@ end
) |> enumerate
@test (@inferred setall(obj, o, getall(obj, o))) === obj
@test setall(obj, o, collect(getall(obj, o))) === obj
if VERSION v"1.10" || i == 2
@test (@inferred setall(obj, o, Vector{Float64}(collect(getall(obj, o))))) == obj
@test (@inferred setall(obj, o, SVector(getall(obj, o)))) == obj
else
@test setall(obj, o, Vector{Float64}(collect(getall(obj, o)))) == obj
@test setall(obj, o, SVector(getall(obj, o))) == obj
end
@test (@inferred setall(obj, o, Vector{Float64}(collect(getall(obj, o))))) == obj
@test (@inferred setall(obj, o, SVector(getall(obj, o)))) == obj
end

obj = ([1, 2], 3:5, (6,))
Expand Down

0 comments on commit 415fb13

Please sign in to comment.