Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the output of versioninfo() customizable with kwargs #21974

Merged
merged 1 commit into from
Jun 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -56,6 +56,8 @@ Library improvements
* `resize!` and `sizehint!` methods no longer over-reserve memory when the
requested array size is more than double of its current size ([#22038]).

* 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 @@ -1350,6 +1350,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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we look for prefixes only? Include JL_-prefixed variables too? We've tried to move away from those, but there may be a few lingering here or there.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I simply hoisted the printing of JULIA_* variables to always be displayed and the rest of the env vars for verbose=true. Add JL_ prefixed env vars to always show too?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah, don't bother – I grepped the source code and it seems like we don't have any lingering environment variables that start with JL_ anymore :)

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 doc/src/devdocs/backtraces.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ 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:

```@repl
versioninfo()
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