Skip to content

Commit 499d170

Browse files
committed
Add @compat for standard library imports
1 parent 956b34b commit 499d170

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ Currently, the `@compat` macro supports the following syntaxes:
7979
`CartesianRange` now has two type parameters, so using them as
8080
fields in other `struct`s requires manual intervention.
8181

82+
* `@compat using Test`, `@compat using SharedArrays`, `@compat using Mmap`, and `@compat
83+
using DelimitedFiles` are provided on versions older than 0.7, where these are not yet
84+
part of the standard library. ([#23931])
85+
8286
## Module Aliases
8387

8488
* In 0.6, some 0.5 iterator functions have been moved to the `Base.Iterators`
@@ -296,6 +300,7 @@ includes this fix. Find the minimum version from there.
296300
[#18977]: https://github.com/JuliaLang/julia/issues/18977
297301
[#19088]: https://github.com/JuliaLang/julia/issues/19088
298302
[#19246]: https://github.com/JuliaLang/julia/issues/19246
303+
[#19331]: https://github.com/JuliaLang/julia/issues/19331
299304
[#19449]: https://github.com/JuliaLang/julia/issues/19449
300305
[#19635]: https://github.com/JuliaLang/julia/issues/19635
301306
[#19784]: https://github.com/JuliaLang/julia/issues/19784
@@ -315,6 +320,7 @@ includes this fix. Find the minimum version from there.
315320
[#21257]: https://github.com/JuliaLang/julia/issues/21257
316321
[#21346]: https://github.com/JuliaLang/julia/issues/21346
317322
[#21378]: https://github.com/JuliaLang/julia/issues/21378
323+
[#21419]: https://github.com/JuliaLang/julia/issues/21419
318324
[#21709]: https://github.com/JuliaLang/julia/issues/21709
319325
[#22064]: https://github.com/JuliaLang/julia/issues/22064
320326
[#22182]: https://github.com/JuliaLang/julia/issues/22182
@@ -331,3 +337,4 @@ includes this fix. Find the minimum version from there.
331337
[#23427]: https://github.com/JuliaLang/julia/issues/23427
332338
[#23570]: https://github.com/JuliaLang/julia/issues/23570
333339
[#23666]: https://github.com/JuliaLang/julia/issues/23666
340+
[#23931]: https://github.com/JuliaLang/julia/issues/23931

src/Compat.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,27 @@ function _compat(ex::Expr)
8686
end
8787
end
8888
end
89+
if VERSION < v"0.7.0-DEV.2005"
90+
if ex.head [:using, :import] && length(ex.args) == 1
91+
if ex.args[1] == :Test
92+
ex = Expr(ex.head, :Base, :Test)
93+
elseif ex.args[1] == :SharedArrays
94+
ex = Expr(:toplevel,
95+
:(module SharedArrays
96+
using Base.Distributed.procs
97+
export SharedArray, SharedMatrix, SharedVector, indexpids,
98+
localindexes, sdata, procs
99+
end),
100+
Expr(ex.head, :., :SharedArrays))
101+
elseif ex.args[1] == :Mmap
102+
ex = Expr(ex.head, :Base, :Mmap)
103+
elseif ex.args[1] == :DelimitedFiles
104+
ex = Expr(:toplevel,
105+
Expr(ex.head, :Base, :DataFmt),
106+
:(const DelimitedFiles = DataFmt))
107+
end
108+
end
109+
end
89110
return Expr(ex.head, map(_compat, ex.args)...)
90111
end
91112

test/runtests.jl

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using Compat
2-
using Base.Test
2+
@compat using Test
33

44
# Issue #291
55
# 0.6
@@ -513,7 +513,7 @@ module Test18839
513513

514514
using Compat
515515
using Compat.Iterators
516-
using Base.Test
516+
@compat using Test
517517

518518
@test collect(take(countfrom(2), 3)) == [2, 3, 4]
519519
@test collect(take(cycle(5:8), 9)) == [5:8; 5:8; 5]
@@ -627,7 +627,8 @@ b = Compat.collect(a)
627627

628628
# PR 22064
629629
module Test22064
630-
using Base.Test, Compat
630+
using Compat
631+
@compat using Test
631632
@test (@__MODULE__) === Test22064
632633
end
633634

@@ -823,6 +824,19 @@ end
823824
# 0.7
824825
@test isconcrete(Int)
825826

827+
# 0.7
828+
module Test23876
829+
using Compat
830+
@compat using Test
831+
@compat import DelimitedFiles
832+
@compat using Mmap, SharedArrays
833+
@test @isdefined(DelimitedFiles)
834+
@test isdefined(SharedArrays, :SharedArray)
835+
@test @isdefined(SharedArray)
836+
@test @isdefined(procs)
837+
@test isdefined(Mmap, :mmap)
838+
end
839+
826840
if VERSION < v"0.6.0"
827841
include("deprecated.jl")
828842
end

0 commit comments

Comments
 (0)