Skip to content

Commit

Permalink
Add @compat for standard library imports
Browse files Browse the repository at this point in the history
  • Loading branch information
TotalVerb committed Oct 2, 2017
1 parent 956b34b commit 499d170
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
7 changes: 7 additions & 0 deletions README.md
Expand Up @@ -79,6 +79,10 @@ Currently, the `@compat` macro supports the following syntaxes:
`CartesianRange` now has two type parameters, so using them as
fields in other `struct`s requires manual intervention.

* `@compat using Test`, `@compat using SharedArrays`, `@compat using Mmap`, and `@compat
using DelimitedFiles` are provided on versions older than 0.7, where these are not yet
part of the standard library. ([#23931])

## Module Aliases

* In 0.6, some 0.5 iterator functions have been moved to the `Base.Iterators`
Expand Down Expand Up @@ -296,6 +300,7 @@ includes this fix. Find the minimum version from there.
[#18977]: https://github.com/JuliaLang/julia/issues/18977
[#19088]: https://github.com/JuliaLang/julia/issues/19088
[#19246]: https://github.com/JuliaLang/julia/issues/19246
[#19331]: https://github.com/JuliaLang/julia/issues/19331
[#19449]: https://github.com/JuliaLang/julia/issues/19449
[#19635]: https://github.com/JuliaLang/julia/issues/19635
[#19784]: https://github.com/JuliaLang/julia/issues/19784
Expand All @@ -315,6 +320,7 @@ includes this fix. Find the minimum version from there.
[#21257]: https://github.com/JuliaLang/julia/issues/21257
[#21346]: https://github.com/JuliaLang/julia/issues/21346
[#21378]: https://github.com/JuliaLang/julia/issues/21378
[#21419]: https://github.com/JuliaLang/julia/issues/21419
[#21709]: https://github.com/JuliaLang/julia/issues/21709
[#22064]: https://github.com/JuliaLang/julia/issues/22064
[#22182]: https://github.com/JuliaLang/julia/issues/22182
Expand All @@ -331,3 +337,4 @@ includes this fix. Find the minimum version from there.
[#23427]: https://github.com/JuliaLang/julia/issues/23427
[#23570]: https://github.com/JuliaLang/julia/issues/23570
[#23666]: https://github.com/JuliaLang/julia/issues/23666
[#23931]: https://github.com/JuliaLang/julia/issues/23931
21 changes: 21 additions & 0 deletions src/Compat.jl
Expand Up @@ -86,6 +86,27 @@ function _compat(ex::Expr)
end
end
end
if VERSION < v"0.7.0-DEV.2005"
if ex.head [:using, :import] && length(ex.args) == 1
if ex.args[1] == :Test
ex = Expr(ex.head, :Base, :Test)
elseif ex.args[1] == :SharedArrays
ex = Expr(:toplevel,
:(module SharedArrays
using Base.Distributed.procs
export SharedArray, SharedMatrix, SharedVector, indexpids,
localindexes, sdata, procs
end),
Expr(ex.head, :., :SharedArrays))
elseif ex.args[1] == :Mmap
ex = Expr(ex.head, :Base, :Mmap)
elseif ex.args[1] == :DelimitedFiles
ex = Expr(:toplevel,
Expr(ex.head, :Base, :DataFmt),
:(const DelimitedFiles = DataFmt))
end
end
end
return Expr(ex.head, map(_compat, ex.args)...)
end

Expand Down
20 changes: 17 additions & 3 deletions test/runtests.jl
@@ -1,5 +1,5 @@
using Compat
using Base.Test
@compat using Test

# Issue #291
# 0.6
Expand Down Expand Up @@ -513,7 +513,7 @@ module Test18839

using Compat
using Compat.Iterators
using Base.Test
@compat using Test

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

# PR 22064
module Test22064
using Base.Test, Compat
using Compat
@compat using Test
@test (@__MODULE__) === Test22064
end

Expand Down Expand Up @@ -823,6 +824,19 @@ end
# 0.7
@test isconcrete(Int)

# 0.7
module Test23876
using Compat
@compat using Test
@compat import DelimitedFiles
@compat using Mmap, SharedArrays
@test @isdefined(DelimitedFiles)
@test isdefined(SharedArrays, :SharedArray)
@test @isdefined(SharedArray)
@test @isdefined(procs)
@test isdefined(Mmap, :mmap)
end

if VERSION < v"0.6.0"
include("deprecated.jl")
end
Expand Down

0 comments on commit 499d170

Please sign in to comment.