Skip to content

Commit

Permalink
Remove compat code for Sys from #380, #433, #552
Browse files Browse the repository at this point in the history
And mark it for future deprecation
  • Loading branch information
martinholters committed Oct 8, 2019
1 parent 3e85b87 commit 3702883
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 103 deletions.
8 changes: 0 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,6 @@ Currently, the `@compat` macro supports the following syntaxes:

* `Compat.qr` takes `pivot` as a `Val` _instance_ ([#22475]).

* `Compat.Sys.which` and `Compat.Sys.isexecutable` ([#26559], [#27298]).

* `Compat.rmul!` provides a subset of the functionality of `LinearAlgebra.rmul!` for
use with Julia 0.6 ([#25701], [#25812]).

Expand All @@ -229,10 +227,6 @@ Currently, the `@compat` macro supports the following syntaxes:

* `reprmime(mime, x)` is now `repr(mime, x)` ([#25990]) and `mimewritable` is now `showable` ([#26089]).

* `is_apple`, `is_bsd`, `is_linux`, `is_unix`, and `is_windows` are now `Sys.isapple`, `Sys.isbsd`,
`Sys.islinux`, `Sys.isunix`, and `Sys.iswindows`, respectively. These are available in the `Compat.Sys`
submodule. ([#22182])

* `readstring` is replaced by methods of `read`. ([#22864])

`read(::IO, ::Type{String})`, `read(::AbstractString, ::Type{String})`,
Expand All @@ -258,8 +252,6 @@ Currently, the `@compat` macro supports the following syntaxes:

* `trace` is now `tr`, available as `Compat.tr` ([#26365]).

* `JULIA_HOME` is now `Sys.BINDIR`, available in the `Compat.Sys` submodule. ([#25102])

* `Associative` is now `AbstractDict` ([#25012]).

* `indices` is now `axes` ([#25057]). This function is not exported from Compat to avoid
Expand Down
74 changes: 5 additions & 69 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,79 +12,15 @@ module TypeUtils
end # module TypeUtils
import Base.invokelatest
const macros_have_sourceloc = true

include("compatmacro.jl")

# https://github.com/JuliaLang/julia/pull/22182
module Sys
const KERNEL = Base.Sys.KERNEL
@static if VERSION < v"0.7.0-DEV.914"
isapple(k::Symbol=KERNEL) = k in (:Darwin, :Apple)
isbsd(k::Symbol=KERNEL) = isapple(k) || k in (:FreeBSD, :OpenBSD, :NetBSD, :DragonFly)
islinux(k::Symbol=KERNEL) = k == :Linux
isunix(k::Symbol=KERNEL) = isbsd(k) || islinux(k)
iswindows(k::Symbol=KERNEL) = k in (:Windows, :NT)
else
import Base.Sys: isapple, isbsd, islinux, isunix, iswindows
end

@static if VERSION < v"0.7.0-DEV.5171"
using ..Compat: pushfirst!

function isexecutable(path::AbstractString)
if iswindows()
isfile(path)
else
ccall(:access, Cint, (Ptr{UInt8}, Cint), path, 0x01) == 0
end
end
import Base.Sys: isapple, isbsd, islinux, isunix, iswindows
import Base.Sys: which, isexecutable
BINDIR = Base.Sys.BINDIR
end

function which(program::AbstractString)
progs = String[]
base = basename(program)
if iswindows()
isempty(last(splitext(base))) || push!(progs, base)
for p = [".exe", ".com"]
push!(progs, base * p)
end
else
push!(progs, base)
end
dirs = String[]
dir = dirname(program)
if isempty(dir)
pathsep = iswindows() ? ';' : ':'
append!(dirs, map(abspath, split(get(ENV, "PATH", ""), pathsep)))
iswindows() && pushfirst!(dirs, pwd())
else
push!(dirs, abspath(dir))
end
for d in dirs, p in progs
path = joinpath(d, p)
isexecutable(path) && return realpath(path)
end
nothing
end
elseif VERSION < v"0.7.0-alpha.6"
import Base.Sys: isexecutable

which(program::AbstractString) = try
Base.Sys.which(program)
catch err
err isa ErrorException || rethrow(err)
nothing
end
else
import Base.Sys: which, isexecutable
end

# https://github.com/JuliaLang/julia/pull/25102
# NOTE: This needs to be in an __init__ because JULIA_HOME is not
# defined when building system images.
function __init__()
global BINDIR = VERSION < v"0.7.0-DEV.3073" ? JULIA_HOME : Base.Sys.BINDIR
end
end
include("compatmacro.jl")

@static if VERSION < v"0.7.0-DEV.892"
fieldcount(t) = nfields(t)
Expand Down
22 changes: 22 additions & 0 deletions test/old.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,28 @@ let foo() = begin
@test foo() == 2
end

for os in [:apple, :bsd, :linux, :unix, :windows]
from_base = if VERSION >= v"0.7.0-DEV.914"
Expr(:., Expr(:., :Base, Base.Meta.quot(:Sys)), Base.Meta.quot(Symbol("is", os)))
else
Expr(:., :Base, Base.Meta.quot(Symbol("is_", os)))
end
@eval @test Compat.Sys.$(Symbol("is", os))() == $from_base()
end

# 0.7.0-DEV.3073
@test Compat.Sys.BINDIR == Sys.BINDIR

# 0.7.0-DEV.5171
let sep = Compat.Sys.iswindows() ? ';' : ':'
withenv("PATH" => string(Compat.Sys.BINDIR, sep, get(ENV, "PATH", ""))) do
jl = joinpath(Compat.Sys.BINDIR, "julia") * (Compat.Sys.iswindows() ? ".exe" : "")
@test Compat.Sys.which("julia") == realpath(jl)
@test Compat.Sys.isexecutable(jl)
@test Compat.Sys.which("reallyseriouslynotathingyoushouldhave") === nothing
end
end


# tests of removed functionality (i.e. justs tests Base)

Expand Down
26 changes: 0 additions & 26 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,6 @@ using Compat.SparseArrays

const struct_sym = VERSION < v"0.7.0-DEV.1263" ? :type : :struct

for os in [:apple, :bsd, :linux, :unix, :windows]
from_base = if VERSION >= v"0.7.0-DEV.914"
Expr(:., Expr(:., :Base, Base.Meta.quot(:Sys)), Base.Meta.quot(Symbol("is", os)))
else
Expr(:., :Base, Base.Meta.quot(Symbol("is_", os)))
end
@eval @test Compat.Sys.$(Symbol("is", os))() == $from_base()
end

let s = "Koala test: 🐨"
@test transcode(UInt16, s) == UInt16[75,111,97,108,97,32,116,101,115,116,58,32,55357,56360]
@test transcode(UInt32, s) == UInt32[75,111,97,108,97,32,116,101,115,116,58,32,128040]
Expand Down Expand Up @@ -320,13 +311,6 @@ end
@test ComplexF32 === Complex{Float32}
@test ComplexF64 === Complex{Float64}

# 0.7.0-DEV.3073
if VERSION < v"0.7.0-DEV.3073"
@test Compat.Sys.BINDIR == JULIA_HOME
else
@test Compat.Sys.BINDIR == Sys.BINDIR
end

# 0.7.0-DEV.2915
module Test25021
using Compat
Expand Down Expand Up @@ -1175,16 +1159,6 @@ let s = "∀α>β:α+1>β"
end
end

# 0.7.0-DEV.5171
let sep = Compat.Sys.iswindows() ? ';' : ':'
withenv("PATH" => string(Compat.Sys.BINDIR, sep, get(ENV, "PATH", ""))) do
jl = joinpath(Compat.Sys.BINDIR, "julia") * (Compat.Sys.iswindows() ? ".exe" : "")
@test Compat.Sys.which("julia") == realpath(jl)
@test Compat.Sys.isexecutable(jl)
@test Compat.Sys.which("reallyseriouslynotathingyoushouldhave") === nothing
end
end

# julia#24839
@test permutedims([1 2; 3 4]) == [1 3; 2 4]
@test permutedims([1,2,3]) == [1 2 3]
Expand Down

0 comments on commit 3702883

Please sign in to comment.