From 3a3f0e4ebc3a9ab81bfb655003759ffa9c6bd1bb Mon Sep 17 00:00:00 2001 From: Vedant Puri Date: Mon, 19 Jun 2023 09:47:40 -0400 Subject: [PATCH] put chainrules core in a requires block, rm it from deps (#107) * put chainrules core in a requires block, rm it from deps * test conditional loading of CRC --- Project.toml | 14 +++++++------- src/AbstractFFTs.jl | 12 ++++++++++-- test/runtests.jl | 14 +++++++++++++- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/Project.toml b/Project.toml index 8e7206c1..111b84f2 100644 --- a/Project.toml +++ b/Project.toml @@ -3,19 +3,16 @@ uuid = "621f4979-c628-5d54-868e-fcf4e3e8185c" version = "1.3.1" [deps] -ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" - -[weakdeps] -ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" - -[extensions] -AbstractFFTsChainRulesCoreExt = "ChainRulesCore" +Requires = "ae029012-a4dd-5104-9daa-d747884805df" [compat] ChainRulesCore = "1" julia = "^1.0" +[extensions] +AbstractFFTsChainRulesCoreExt = "ChainRulesCore" + [extras] ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" ChainRulesTestUtils = "cdddcdb0-9152-4a09-a978-84456f9df70a" @@ -25,3 +22,6 @@ Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d" [targets] test = ["ChainRulesCore", "ChainRulesTestUtils", "Random", "Test", "Unitful"] + +[weakdeps] +ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" diff --git a/src/AbstractFFTs.jl b/src/AbstractFFTs.jl index 00f6dc27..77e194b0 100644 --- a/src/AbstractFFTs.jl +++ b/src/AbstractFFTs.jl @@ -7,8 +7,16 @@ export fft, ifft, bfft, fft!, ifft!, bfft!, include("definitions.jl") -if !isdefined(Base, :get_extension) - include("../ext/AbstractFFTsChainRulesCoreExt.jl") +@static if !isdefined(Base, :get_extension) + import Requires +end + +@static if !isdefined(Base, :get_extension) + function __init__() + Requires.@require ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" begin + include("../ext/AbstractFFTsChainRulesCoreExt.jl") + end + end end end # module diff --git a/test/runtests.jl b/test/runtests.jl index 9cb528ac..c41debe6 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -2,7 +2,6 @@ using AbstractFFTs using AbstractFFTs: Plan -using ChainRulesTestUtils using LinearAlgebra using Random @@ -241,6 +240,19 @@ end end @testset "ChainRules" begin + + if isdefined(Base, :get_extension) + CRCEXT = Base.get_extension(AbstractFFTs, :AbstractFFTsChainRulesCoreExt) + @test isnothing(CRCEXT) + end + + using ChainRulesTestUtils + + if isdefined(Base, :get_extension) + CRCEXT = Base.get_extension(AbstractFFTs, :AbstractFFTsChainRulesCoreExt) + @test !isnothing(CRCEXT) + end + @testset "shift functions" begin for x in (randn(3), randn(3, 4), randn(3, 4, 5)) for dims in ((), 1, 2, (1,2), 1:2)