From 415fb139e5a8b05b1d1ca65827e5ed3b428e7399 Mon Sep 17 00:00:00 2001 From: Alexander Plavin Date: Sat, 11 Jan 2025 22:27:34 -0500 Subject: [PATCH] only support Julia 1.10+ (lts and newer) --- .github/workflows/ci.yml | 1 - Project.toml | 14 +------------- README.md | 2 +- ext/StaticArraysExt.jl | 2 +- src/Accessors.jl | 13 +------------ src/functionlenses.jl | 8 ++------ src/optics.jl | 9 --------- test/Project.toml | 5 ----- test/perf.jl | 10 ++-------- test/runtests.jl | 2 +- test/test_core.jl | 18 ++++-------------- test/test_extensions.jl | 26 ++++++++++---------------- test/test_functionlenses.jl | 33 ++++++++++++--------------------- test/test_getsetall.jl | 14 ++------------ 14 files changed, 37 insertions(+), 120 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 688da089..429ad0d1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,7 +10,6 @@ jobs: fail-fast: false matrix: version: - - '1.6' - 'lts' - '1' - 'pre' diff --git a/Project.toml b/Project.toml index 1fc0f1e5..271dd07d 100644 --- a/Project.toml +++ b/Project.toml @@ -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" @@ -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" diff --git a/README.md b/README.md index 0cf6a140..8d015ef2 100644 --- a/README.md +++ b/README.md @@ -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`. diff --git a/ext/StaticArraysExt.jl b/ext/StaticArraysExt.jl index 1896f4c2..ca3913ad 100644 --- a/ext/StaticArraysExt.jl +++ b/ext/StaticArraysExt.jl @@ -1,5 +1,5 @@ module StaticArraysExt -isdefined(Base, :get_extension) ? (using StaticArrays) : (using ..StaticArrays) +using StaticArrays using Accessors import Accessors: setindex, delete, insert diff --git a/src/Accessors.jl b/src/Accessors.jl index 53019aaf..7dfbc41b 100644 --- a/src/Accessors.jl +++ b/src/Accessors.jl @@ -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") @@ -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 @@ -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 diff --git a/src/functionlenses.jl b/src/functionlenses.jl index 58ea5a00..f963aa0a 100644 --- a/src/functionlenses.jl +++ b/src/functionlenses.jl @@ -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 diff --git a/src/optics.jl b/src/optics.jl index e3a85c2d..81236fc8 100644 --- a/src/optics.jl +++ b/src/optics.jl @@ -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 diff --git a/test/Project.toml b/test/Project.toml index 9011bb3a..99173d99 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -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" @@ -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" diff --git a/test/perf.jl b/test/perf.jl index 158d213d..468e42fd 100644 --- a/test/perf.jl +++ b/test/perf.jl @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index 40a62e2a..14c86919 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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") diff --git a/test/test_core.jl b/test/test_core.jl index e8a42761..07341d7a 100644 --- a/test/test_core.jl +++ b/test/test_core.jl @@ -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 @@ -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') diff --git a/test/test_extensions.jl b/test/test_extensions.jl index 31b7d0fe..c8e7e055 100644 --- a/test/test_extensions.jl +++ b/test/test_extensions.jl @@ -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 ( @@ -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 @@ -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] @@ -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) @@ -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 @@ -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 diff --git a/test/test_functionlenses.jl b/test/test_functionlenses.jl index f63733cb..2ec966e9 100644 --- a/test/test_functionlenses.jl +++ b/test/test_functionlenses.jl @@ -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π @@ -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" @@ -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"], []) diff --git a/test/test_getsetall.jl b/test/test_getsetall.jl index aeef5931..ab080e18 100644 --- a/test/test_getsetall.jl +++ b/test/test_getsetall.jl @@ -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) @@ -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,))