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 25, 2017
1 parent 888adbc commit cf7fb99
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 43 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ A useful bug report filed as a GitHub issue provides information about how to re
3. When filing a bug report, provide where possible:
- The full error message, including the backtrace.
- A minimal working example, i.e. the smallest chunk of code that triggers the error. Ideally, this should be code that can be pasted into a REPL or run from a source file. If the code is larger than (say) 50 lines, consider putting it in a [gist](https://gist.github.com).
- The version of Julia as provided by the `versioninfo()` command. Occasionally, the longer output produced by `versioninfo(true)` may be useful also, especially if the issue is related to a specific package.
- The version of Julia as provided by the `versioninfo()` command. Occasionally, the longer output produced by `versioninfo(verbose = true)` may be useful also, especially if the issue is related to a specific package.

4. When pasting code blocks or output, put triple backquotes (\`\`\`) around the text so GitHub will format it nicely. Code statements should be surrounded by single backquotes (\`). Be aware that the `@` sign tags users on GitHub, so references to macros should always be in single backquotes. See [GitHub's guide on Markdown](https://guides.github.com/features/mastering-markdown) for more formatting tricks.

Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ Library improvements
method can be opened in an editor by entering the corresponding number in the REPL
and pressing `^Q` ([#22007]).

* The output of `versioninfo()` is now 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 @@ -1348,6 +1348,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 output is
controlled with boolean 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
17 changes: 9 additions & 8 deletions doc/src/devdocs/backtraces.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,22 @@ and follow the instructions to generate the debugging information requested. Ta
## [Version/Environment info](@id dev-version-info)

No matter the error, we will always need to know what version of Julia you are running. When Julia
first starts up, a header is printed out with a version number and date. If your version is
`0.2.0` or higher, please include the output of `versioninfo()` in any report you create:
first starts up, a header is printed out with a version number and date. Please also include the
output of `versioninfo()` in any report you create:

```julia
julia> versioninfo()
Julia Version 0.3.3-pre+25
Commit 417b50a* (2014-11-03 11:32 UTC)
Julia Version 0.7.0-DEV.335
Commit e3f61a4* (2017-05-25 13:28 UTC)
Platform Info:
OS: Linux (x86_64-linux-gnu)
CPU: Intel(R) Core(TM) i7 CPU L 640 @ 2.13GHz
CPU: Intel(R) Core(TM) i5-7600K CPU @ 3.80GHz
WORD_SIZE: 64
BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Nehalem)
LAPACK: libopenblas
BLAS: libopenblas (USE64BITINT NO_AFFINITY HASWELL)
LAPACK: libopenblas64_
LIBM: libopenlibm
LLVM: libLLVM-3.3
LLVM: libLLVM-3.9.1 (ORCJIT, broadwell)
Environment:
```

## Segfaults during bootstrap (`sysimg.jl`)
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 cf7fb99

Please sign in to comment.