Skip to content

Commit 8260c13

Browse files
committed
Deprecate is_<os> functions in favor of Sys.is<os>
This makes them consistent with the vast majority of Base predicates, which simply prefix with `is` rather than `is_`. It also moves to requiring the `Sys.` prefix, which helps explain the intent behind the function names.
1 parent 2c85595 commit 8260c13

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+342
-332
lines changed

NEWS.md

+5
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ Deprecated or removed
120120
* The `corrected` positional argument to `cov` has been deprecated in favor of
121121
a keyword argument with the same name (#21709).
122122

123+
* The operation identification functions: `is_linux`, `is_bsd`, `is_apple`, `is_unix`, and
124+
`is_windows`, have been deprecated in favor of `Sys.islinux`, `Sys.isbsd`, `Sys.isapple`,
125+
`Sys.isunix`, and `Sys.iswindows`, respectively ([#22182]).
126+
123127

124128
Julia v0.6.0 Release Notes
125129
==========================
@@ -913,6 +917,7 @@ Command-line option changes
913917
[#22038]: https://github.com/JuliaLang/julia/issues/22038
914918
[#22062]: https://github.com/JuliaLang/julia/issues/22062
915919
[#22064]: https://github.com/JuliaLang/julia/issues/22064
920+
[#22182]: https://github.com/JuliaLang/julia/issues/22182
916921
[#22187]: https://github.com/JuliaLang/julia/issues/22187
917922
[#22188]: https://github.com/JuliaLang/julia/issues/22188
918923
[#22224]: https://github.com/JuliaLang/julia/issues/22224

base/c.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Equivalent to the native `char` c-type.
1818
"""
1919
Cchar
2020

21-
if is_windows()
21+
if Sys.iswindows()
2222
const Clong = Int32
2323
const Culong = UInt32
2424
const Cwchar_t = UInt16
@@ -49,7 +49,7 @@ Equivalent to the native `wchar_t` c-type ([`Int32`](@ref)).
4949
"""
5050
Cwchar_t
5151

52-
if !is_windows()
52+
if !Sys.iswindows()
5353
const sizeof_mode_t = ccall(:jl_sizeof_mode_t, Cint, ())
5454
if sizeof_mode_t == 2
5555
const Cmode_t = Int16
@@ -118,7 +118,7 @@ end
118118
# symbols are guaranteed not to contain embedded NUL
119119
convert(::Type{Cstring}, s::Symbol) = Cstring(unsafe_convert(Ptr{Cchar}, s))
120120

121-
if is_windows()
121+
if Sys.iswindows()
122122
"""
123123
Base.cwstring(s)
124124

base/client.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,15 @@ function repl_cmd(cmd, out)
102102
end
103103
cd(ENV["OLDPWD"])
104104
else
105-
cd(@static is_windows() ? dir : readchomp(`$shell -c "echo $(shell_escape(dir))"`))
105+
cd(@static Sys.iswindows() ? dir : readchomp(`$shell -c "echo $(shell_escape(dir))"`))
106106
end
107107
else
108108
cd()
109109
end
110110
ENV["OLDPWD"] = new_oldpwd
111111
println(out, pwd())
112112
else
113-
run(ignorestatus(@static is_windows() ? cmd : (isa(STDIN, TTY) ? `$shell -i -c "$(shell_wrap_true(shell_name, cmd))"` : `$shell -c "$(shell_wrap_true(shell_name, cmd))"`)))
113+
run(ignorestatus(@static Sys.iswindows() ? cmd : (isa(STDIN, TTY) ? `$shell -i -c "$(shell_wrap_true(shell_name, cmd))"` : `$shell -c "$(shell_wrap_true(shell_name, cmd))"`)))
114114
end
115115
nothing
116116
end
@@ -385,7 +385,7 @@ function _start()
385385
global is_interactive |= !isa(STDIN, Union{File, IOStream})
386386
color_set || (global have_color = false)
387387
else
388-
term = Terminals.TTYTerminal(get(ENV, "TERM", @static is_windows() ? "" : "dumb"), STDIN, STDOUT, STDERR)
388+
term = Terminals.TTYTerminal(get(ENV, "TERM", @static Sys.iswindows() ? "" : "dumb"), STDIN, STDOUT, STDERR)
389389
global is_interactive = true
390390
color_set || (global have_color = Terminals.hascolor(term))
391391
quiet || REPL.banner(term,term)

base/dSFMT.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ end
163163

164164
## Windows entropy
165165

166-
if is_windows()
166+
if Sys.iswindows()
167167
function win32_SystemFunction036!(a::Array)
168168
ccall((:SystemFunction036, :Advapi32), stdcall, UInt8, (Ptr{Void}, UInt32), a, sizeof(a))
169169
end

base/datafmt.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ readdlm_auto(input::IO, dlm::Char, T::Type, eol::Char, auto::Bool; opts...) =
120120
readdlm_string(readstring(input), dlm, T, eol, auto, val_opts(opts))
121121
function readdlm_auto(input::AbstractString, dlm::Char, T::Type, eol::Char, auto::Bool; opts...)
122122
optsd = val_opts(opts)
123-
use_mmap = get(optsd, :use_mmap, is_windows() ? false : true)
123+
use_mmap = get(optsd, :use_mmap, Sys.iswindows() ? false : true)
124124
fsz = filesize(input)
125125
if use_mmap && fsz > 0 && fsz < typemax(Int)
126126
a = open(input, "r") do f

base/deprecated.jl

+7
Original file line numberDiff line numberDiff line change
@@ -1491,6 +1491,13 @@ export conv, conv2, deconv, filt, filt!, xcorr
14911491
@deprecate cov(X::AbstractVector, Y::AbstractVector, corrected::Bool) cov(X, Y, corrected=corrected)
14921492
@deprecate cov(X::AbstractVecOrMat, Y::AbstractVecOrMat, vardim::Int, corrected::Bool) cov(X, Y, vardim, corrected=corrected)
14931493

1494+
# PR #22182
1495+
@deprecate is_apple Sys.isapple
1496+
@deprecate is_bsd Sys.isbsd
1497+
@deprecate is_linux Sys.islinux
1498+
@deprecate is_unix Sys.isunix
1499+
@deprecate is_windows Sys.iswindows
1500+
14941501
# END 0.7 deprecations
14951502

14961503
# BEGIN 1.0 deprecations

base/distributed/cluster.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ end
960960
function disable_nagle(sock)
961961
# disable nagle on all OSes
962962
ccall(:uv_tcp_nodelay, Cint, (Ptr{Void}, Cint), sock.handle, 1)
963-
@static if is_linux()
963+
@static if Sys.islinux()
964964
# tcp_quickack is a linux only option
965965
if ccall(:jl_tcp_quickack, Cint, (Ptr{Void}, Cint), sock.handle, 1) < 0
966966
warn_once("Networking unoptimized ( Error enabling TCP_QUICKACK : ", Libc.strerror(Libc.errno()), " )")

base/distributed/managers.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ function socket_reuse_port()
459459
s = TCPSocket(delay = false)
460460

461461
# Some systems (e.g. Linux) require the port to be bound before setting REUSEPORT
462-
bind_early = is_linux()
462+
bind_early = Sys.islinux()
463463

464464
bind_early && bind_client_port(s)
465465
rc = ccall(:jl_tcp_reuseport, Int32, (Ptr{Void},), s.handle)

base/env.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

3-
if is_windows()
3+
if Sys.iswindows()
44
const ERROR_ENVVAR_NOT_FOUND = UInt32(203)
55

66
_getenvlen(var::Vector{UInt16}) = ccall(:GetEnvironmentVariableW,stdcall,UInt32,(Ptr{UInt16},Ptr{UInt16},UInt32),var,C_NULL,0)
@@ -84,7 +84,7 @@ delete!(::EnvHash, k::AbstractString) = (_unsetenv(k); ENV)
8484
setindex!(::EnvHash, v, k::AbstractString) = _setenv(k,string(v))
8585
push!(::EnvHash, k::AbstractString, v) = setindex!(ENV, v, k)
8686

87-
if is_windows()
87+
if Sys.iswindows()
8888
start(hash::EnvHash) = (pos = ccall(:GetEnvironmentStringsW,stdcall,Ptr{UInt16},()); (pos,pos))
8989
function done(hash::EnvHash, block::Tuple{Ptr{UInt16},Ptr{UInt16}})
9090
if unsafe_load(block[1]) == 0

base/event.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ function wait()
247247
# unreachable
248248
end
249249

250-
if is_windows()
250+
if Sys.iswindows()
251251
pause() = ccall(:Sleep, stdcall, Void, (UInt32,), 0xffffffff)
252252
else
253253
pause() = ccall(:pause, Void, ())

base/exports.jl

+1-8
Original file line numberDiff line numberDiff line change
@@ -1257,14 +1257,6 @@ export
12571257
@code_llvm,
12581258
@code_native,
12591259

1260-
# platform-conditional code
1261-
@static,
1262-
is_windows,
1263-
is_linux,
1264-
is_apple,
1265-
is_bsd,
1266-
is_unix,
1267-
12681260
# tasks
12691261
@schedule,
12701262
@sync,
@@ -1294,6 +1286,7 @@ export
12941286
@goto,
12951287
@view,
12961288
@views,
1289+
@static,
12971290

12981291
# SparseArrays module re-exports
12991292
SparseArrays,

base/file.jl

+9-9
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function cd(dir::AbstractString)
5151
end
5252
cd() = cd(homedir())
5353

54-
if is_windows()
54+
if Sys.iswindows()
5555
function cd(f::Function, dir::AbstractString)
5656
old = pwd()
5757
try
@@ -91,7 +91,7 @@ this function throws an error. See [`mkpath`](@ref) for a function which creates
9191
required intermediate directories.
9292
"""
9393
function mkdir(path::AbstractString, mode::Unsigned=0o777)
94-
@static if is_windows()
94+
@static if Sys.iswindows()
9595
ret = ccall(:_wmkdir, Int32, (Cwstring,), path)
9696
else
9797
ret = ccall(:mkdir, Int32, (Cstring, UInt32), path, mode)
@@ -136,7 +136,7 @@ directory, then all contents are removed recursively.
136136
function rm(path::AbstractString; force::Bool=false, recursive::Bool=false)
137137
if islink(path) || !isdir(path)
138138
try
139-
@static if is_windows()
139+
@static if Sys.iswindows()
140140
# is writable on windows actually means "is deletable"
141141
if (filemode(path) & 0o222) == 0
142142
chmod(path, 0o777)
@@ -155,7 +155,7 @@ function rm(path::AbstractString; force::Bool=false, recursive::Bool=false)
155155
rm(joinpath(path, p), force=force, recursive=true)
156156
end
157157
end
158-
@static if is_windows()
158+
@static if Sys.iswindows()
159159
ret = ccall(:_wrmdir, Int32, (Cwstring,), path)
160160
else
161161
ret = ccall(:rmdir, Int32, (Cstring,), path)
@@ -254,7 +254,7 @@ function touch(path::AbstractString)
254254
end
255255
end
256256

257-
if is_windows()
257+
if Sys.iswindows()
258258

259259
function tempdir()
260260
temppath = Vector{UInt16}(32767)
@@ -536,7 +536,7 @@ function sendfile(src::AbstractString, dst::AbstractString)
536536
end
537537
end
538538

539-
if is_windows()
539+
if Sys.iswindows()
540540
const UV_FS_SYMLINK_JUNCTION = 0x0002
541541
end
542542

@@ -550,20 +550,20 @@ Creates a symbolic link to `target` with the name `link`.
550550
soft symbolic links, such as Windows XP.
551551
"""
552552
function symlink(p::AbstractString, np::AbstractString)
553-
@static if is_windows()
553+
@static if Sys.iswindows()
554554
if Sys.windows_version() < Sys.WINDOWS_VISTA_VER
555555
error("Windows XP does not support soft symlinks")
556556
end
557557
end
558558
flags = 0
559-
@static if is_windows()
559+
@static if Sys.iswindows()
560560
if isdir(p)
561561
flags |= UV_FS_SYMLINK_JUNCTION
562562
p = abspath(p)
563563
end
564564
end
565565
err = ccall(:jl_fs_symlink, Int32, (Cstring, Cstring, Cint), p, np, flags)
566-
@static if is_windows()
566+
@static if Sys.iswindows()
567567
if err < 0 && !isdir(p)
568568
Base.warn_once("Note: on Windows, creating file symlinks requires Administrator privileges.")
569569
end

base/filesystem.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import Base:
4444
skip, stat, unsafe_read, unsafe_write, transcode, uv_error, uvhandle,
4545
uvtype, write
4646

47-
if is_windows()
47+
if Sys.iswindows()
4848
import Base: cwstring
4949
end
5050

base/initdefs.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const LOAD_CACHE_PATH = String[]
5050
function init_load_path()
5151
vers = "v$(VERSION.major).$(VERSION.minor)"
5252
if haskey(ENV, "JULIA_LOAD_PATH")
53-
prepend!(LOAD_PATH, split(ENV["JULIA_LOAD_PATH"], @static is_windows() ? ';' : ':'))
53+
prepend!(LOAD_PATH, split(ENV["JULIA_LOAD_PATH"], @static Sys.iswindows() ? ';' : ':'))
5454
end
5555
push!(LOAD_PATH, abspath(JULIA_HOME, "..", "local", "share", "julia", "site", vers))
5656
push!(LOAD_PATH, abspath(JULIA_HOME, "..", "share", "julia", "site", vers))

base/interactiveutil.jl

+14-14
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ for use within backticks. You can change the editor by setting `JULIA_EDITOR`, `
1010
`EDITOR` as an environment variable.
1111
"""
1212
function editor()
13-
if is_windows() || is_apple()
13+
if Sys.iswindows() || Sys.isapple()
1414
default_editor = "open"
1515
elseif isfile("/etc/alternatives/editor")
1616
default_editor = "/etc/alternatives/editor"
@@ -49,11 +49,11 @@ function edit(path::AbstractString, line::Integer=0)
4949
cmd = line != 0 ? `$command $path -l $line` : `$command $path`
5050
elseif startswith(name, "subl") || startswith(name, "atom")
5151
cmd = line != 0 ? `$command $path:$line` : `$command $path`
52-
elseif name == "code" || (is_windows() && uppercase(name) == "CODE.EXE")
52+
elseif name == "code" || (Sys.iswindows() && uppercase(name) == "CODE.EXE")
5353
cmd = line != 0 ? `$command -g $path:$line` : `$command -g $path`
5454
elseif startswith(name, "notepad++")
5555
cmd = line != 0 ? `$command $path -n$line` : `$command $path`
56-
elseif is_apple() && name == "open"
56+
elseif Sys.isapple() && name == "open"
5757
cmd = `open -t $path`
5858
line_unsupported = true
5959
else
@@ -62,8 +62,8 @@ function edit(path::AbstractString, line::Integer=0)
6262
line_unsupported = true
6363
end
6464

65-
if is_windows() && name == "open"
66-
@static is_windows() && # don't emit this ccall on other platforms
65+
if Sys.iswindows() && name == "open"
66+
@static Sys.iswindows() && # don't emit this ccall on other platforms
6767
systemerror(:edit, ccall((:ShellExecuteW, "shell32"), stdcall, Int,
6868
(Ptr{Void}, Cwstring, Cwstring, Ptr{Void}, Ptr{Void}, Cint),
6969
C_NULL, "open", path, C_NULL, C_NULL, 10) 32)
@@ -90,7 +90,7 @@ edit(file, line::Integer) = error("could not find source file for function")
9090

9191
# terminal pager
9292

93-
if is_windows()
93+
if Sys.iswindows()
9494
function less(file::AbstractString, line::Integer)
9595
pager = get(ENV, "PAGER", "more")
9696
g = pager == "more" ? "" : "g"
@@ -123,15 +123,15 @@ less(file, line::Integer) = error("could not find source file for function")
123123

124124
# clipboard copy and paste
125125

126-
if is_apple()
126+
if Sys.isapple()
127127
function clipboard(x)
128128
open(pipeline(`pbcopy`, stderr=STDERR), "w") do io
129129
print(io, x)
130130
end
131131
end
132132
clipboard() = readstring(`pbpaste`)
133133

134-
elseif is_linux()
134+
elseif Sys.islinux()
135135
_clipboardcmd = nothing
136136
function clipboardcmd()
137137
global _clipboardcmd
@@ -158,7 +158,7 @@ elseif is_linux()
158158
readstring(pipeline(cmd, stderr=STDERR))
159159
end
160160

161-
elseif is_windows()
161+
elseif Sys.iswindows()
162162
# TODO: these functions leak memory and memory locks if they throw an error
163163
function clipboard(x::AbstractString)
164164
if containsnul(x)
@@ -262,21 +262,21 @@ function versioninfo(io::IO=STDOUT; verbose::Bool=false, packages::Bool=false)
262262
println(io, "DEBUG build")
263263
end
264264
println(io, "Platform Info:")
265-
println(io, " OS: ", is_windows() ? "Windows" : is_apple() ?
265+
println(io, " OS: ", Sys.iswindows() ? "Windows" : Sys.isapple() ?
266266
"macOS" : Sys.KERNEL, " (", Sys.MACHINE, ")")
267267

268268
if verbose
269269
lsb = ""
270-
if is_linux()
270+
if Sys.islinux()
271271
try lsb = readchomp(pipeline(`lsb_release -ds`, stderr=DevNull)) end
272272
end
273-
if is_windows()
273+
if Sys.iswindows()
274274
try lsb = strip(readstring(`$(ENV["COMSPEC"]) /c ver`)) end
275275
end
276276
if !isempty(lsb)
277277
println(io, " ", lsb)
278278
end
279-
if is_unix()
279+
if Sys.isunix()
280280
println(io, " uname: ", readchomp(`uname -mprsv`))
281281
end
282282
end
@@ -592,7 +592,7 @@ end
592592
# file downloading
593593

594594
downloadcmd = nothing
595-
if is_windows()
595+
if Sys.iswindows()
596596
function download(url::AbstractString, filename::AbstractString)
597597
res = ccall((:URLDownloadToFileW,:urlmon),stdcall,Cuint,
598598
(Ptr{Void},Cwstring,Cwstring,Cuint,Ptr{Void}),C_NULL,url,filename,0,C_NULL)

0 commit comments

Comments
 (0)