From d470b0df000533015054157c28e347419490d1e6 Mon Sep 17 00:00:00 2001 From: Martin Holters Date: Mon, 30 Sep 2019 19:34:21 +0200 Subject: [PATCH] Remove compat code for `Sys` from #380, #433, #552 And mark it for future deprecation --- README.md | 8 ------ src/Compat.jl | 74 ++++-------------------------------------------- test/old.jl | 22 ++++++++++++++ test/runtests.jl | 26 ----------------- 4 files changed, 27 insertions(+), 103 deletions(-) diff --git a/README.md b/README.md index 72115f278..a806d707f 100644 --- a/README.md +++ b/README.md @@ -204,8 +204,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]). @@ -227,10 +225,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})`, @@ -256,8 +250,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 diff --git a/src/Compat.jl b/src/Compat.jl index c4209cdea..f71f02bb8 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -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) diff --git a/test/old.jl b/test/old.jl index fc4776be3..514d71207 100644 --- a/test/old.jl +++ b/test/old.jl @@ -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) diff --git a/test/runtests.jl b/test/runtests.jl index 601305550..cb17ddf91 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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] @@ -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 @@ -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]