Skip to content

Commit

Permalink
make the output of versioninfo() customizable with kwargs
Browse files Browse the repository at this point in the history
and prettify the printing a bit
  • Loading branch information
fredrikekre committed May 22, 2017
1 parent a72aad4 commit 92c2913
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 34 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Library improvements
* the functions `base` and `digits` digits now accept a negative
base (like `ndigits` did) ([#21692]).

* The output of `versioninfo` can now be controlled with keyword arguments ([#21974]).

Compiler/Runtime improvements
-----------------------------

Expand Down
4 changes: 4 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1342,6 +1342,10 @@ end
@deprecate srand(filename::AbstractString, n::Integer=4) srand(read!(filename, Array{UInt32}(Int(n))))
@deprecate MersenneTwister(filename::AbstractString) srand(MersenneTwister(0), read!(filename, Array{UInt32}(Int(4))))

# PR #21974
@deprecate versioninfo(verbose::Bool) versioninfo(verbose=verbose)
@deprecate versioninfo(io::IO, verbose::Bool) versioninfo(io, verbose=verbose)

# END 0.7 deprecations

# BEGIN 1.0 deprecations
Expand Down
84 changes: 52 additions & 32 deletions base/interactiveutil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -245,26 +245,26 @@ end


"""
versioninfo(io::IO=STDOUT, verbose::Bool=false)
versioninfo(io::IO=STDOUT; verbose::Bool=false, packages::Bool=false)
Print information about the version of Julia in use. If the `verbose` argument is `true`,
detailed system information is shown as well.
Print information about the version of Julia in use. The level of detail
in the output can be controlled with the following keyword arguments:
- `packages`: print information about installed packages
- `verbose`: print all additional information
"""
function versioninfo(io::IO=STDOUT, verbose::Bool=false)
println(io, "Julia Version $VERSION")
function versioninfo(io::IO=STDOUT; verbose::Bool=false, packages::Bool=false)
println(io, "Julia Version $VERSION")
if !isempty(GIT_VERSION_INFO.commit_short)
println(io, "Commit $(GIT_VERSION_INFO.commit_short) ($(GIT_VERSION_INFO.date_string))")
println(io, "Commit $(GIT_VERSION_INFO.commit_short) ($(GIT_VERSION_INFO.date_string))")
end
if ccall(:jl_is_debugbuild, Cint, ())!=0
println(io, "DEBUG build")
end
println(io, "Platform Info:")
println(io, " OS: ", is_windows() ? "Windows" : is_apple() ?
println(io, "Platform Info:")
println(io, " OS: ", is_windows() ? "Windows" : is_apple() ?
"macOS" : Sys.KERNEL, " (", Sys.MACHINE, ")")

cpu = Sys.cpu_info()
println(io, " CPU: ", cpu[1].model)
println(io, " WORD_SIZE: ", Sys.WORD_SIZE)
if verbose
lsb = ""
if is_linux()
Expand All @@ -274,45 +274,65 @@ function versioninfo(io::IO=STDOUT, verbose::Bool=false)
try lsb = strip(readstring(`$(ENV["COMSPEC"]) /c ver`)) end
end
if !isempty(lsb)
println(io, " ", lsb)
println(io, " ", lsb)
end
if is_unix()
println(io, " uname: ", readchomp(`uname -mprsv`))
println(io, " uname: ", readchomp(`uname -mprsv`))
end
end

if verbose
cpuio = IOBuffer() # print cpu_summary with correct alignment
Sys.cpu_summary(cpuio)
for (i, line) in enumerate(split(String(take!(cpuio)), "\n"))
prefix = i == 1 ? " CPU: " : " "
println(io, prefix, line)
end
println(io, "Memory: $(Sys.total_memory()/2^30) GB ($(Sys.free_memory()/2^20) MB free)")
try println(io, "Uptime: $(Sys.uptime()) sec") end
print(io, "Load Avg: ")
print_matrix(io, Sys.loadavg()')
println(io )
Sys.cpu_summary(io)
println(io )
else
cpu = Sys.cpu_info()
println(io, " CPU: ", cpu[1].model)
end

if verbose
println(io, " Memory: $(Sys.total_memory()/2^30) GB ($(Sys.free_memory()/2^20) MB free)")
try println(io, " Uptime: $(Sys.uptime()) sec") end
print(io, " Load Avg: ")
print_matrix(io, Sys.loadavg()')
println(io)
end
println(io, " WORD_SIZE: ", Sys.WORD_SIZE)
if Base.libblas_name == "libopenblas" || BLAS.vendor() == :openblas || BLAS.vendor() == :openblas64
openblas_config = BLAS.openblas_get_config()
println(io, " BLAS: libopenblas (", openblas_config, ")")
println(io, " BLAS: libopenblas (", openblas_config, ")")
else
println(io, " BLAS: ",libblas_name)
println(io, " BLAS: ",libblas_name)
end
println(io, " LAPACK: ",liblapack_name)
println(io, " LIBM: ",libm_name)
println(io, " LLVM: libLLVM-",libllvm_version," (", Sys.JIT, ", ", Sys.cpu_name, ")")

println(io, "Environment:")
for (k,v) in ENV
if ismatch(r"JULIA", String(k))
println(io, " $(k) = $(v)")
end
end
println(io, " LAPACK: ",liblapack_name)
println(io, " LIBM: ",libm_name)
println(io, " LLVM: libLLVM-",libllvm_version," (", Sys.JIT, ", ", Sys.cpu_name, ")")
if verbose
println(io, "Environment:")
for (k,v) in ENV
if match(r"JULIA|PATH|FLAG|^TERM$|HOME", String(k)) !== nothing
if ismatch(r"PATH|FLAG|^TERM$|HOME", String(k))
println(io, " $(k) = $(v)")
end
end
println(io )
println(io, "Package Directory: ", Pkg.dir())
end
if packages || verbose
println(io, "Packages:")
println(io, " Package Directory: ", Pkg.dir())
println(io, " Package Status:")
Pkg.status(io)
end
end
versioninfo(verbose::Bool) = versioninfo(STDOUT,verbose)

# displaying type-ambiguity warnings


"""
code_warntype([io::IO], f, types)
Expand Down
4 changes: 2 additions & 2 deletions test/pkg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ temp_pkg_dir() do
@test_throws PkgError Pkg.installed("MyFakePackage")
@test Pkg.installed("Example") === nothing

# check that versioninfo(io, true) doesn't error and produces some output
# check that versioninfo(io; verbose=true) doesn't error and produces some output
# (done here since it calls Pkg.status which might error or clone metadata)
buf = PipeBuffer()
versioninfo(buf, true)
versioninfo(buf, verbose=true)
ver = readstring(buf)
@test startswith(ver, "Julia Version $VERSION")
@test contains(ver, "Environment:")
Expand Down

0 comments on commit 92c2913

Please sign in to comment.