Skip to content

Commit 9f61fda

Browse files
fredrikekreKristofferC
authored andcommitted
make the output of versioninfo() customizable with kwargs (#21974)
and prettify the printing a bit
1 parent a3c9bbd commit 9f61fda

File tree

6 files changed

+63
-37
lines changed

6 files changed

+63
-37
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ A useful bug report filed as a GitHub issue provides information about how to re
4848
3. When filing a bug report, provide where possible:
4949
- The full error message, including the backtrace.
5050
- 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).
51-
- 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.
51+
- 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.
5252

5353
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.
5454

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ Library improvements
5656
* `resize!` and `sizehint!` methods no longer over-reserve memory when the
5757
requested array size is more than double of its current size ([#22038]).
5858

59+
* The output of `versioninfo()` is now controlled with keyword arguments ([#21974]).
60+
5961
Compiler/Runtime improvements
6062
-----------------------------
6163

base/deprecated.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,6 +1350,10 @@ end
13501350
@deprecate srand(filename::AbstractString, n::Integer=4) srand(read!(filename, Array{UInt32}(Int(n))))
13511351
@deprecate MersenneTwister(filename::AbstractString) srand(MersenneTwister(0), read!(filename, Array{UInt32}(Int(4))))
13521352

1353+
# PR #21974
1354+
@deprecate versioninfo(verbose::Bool) versioninfo(verbose=verbose)
1355+
@deprecate versioninfo(io::IO, verbose::Bool) versioninfo(io, verbose=verbose)
1356+
13531357
# END 0.7 deprecations
13541358

13551359
# BEGIN 1.0 deprecations

base/interactiveutil.jl

Lines changed: 52 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -245,26 +245,26 @@ end
245245

246246

247247
"""
248-
versioninfo(io::IO=STDOUT, verbose::Bool=false)
248+
versioninfo(io::IO=STDOUT; verbose::Bool=false, packages::Bool=false)
249249
250-
Print information about the version of Julia in use. If the `verbose` argument is `true`,
251-
detailed system information is shown as well.
250+
Print information about the version of Julia in use. The output is
251+
controlled with boolean keyword arguments:
252+
253+
- `packages`: print information about installed packages
254+
- `verbose`: print all additional information
252255
"""
253-
function versioninfo(io::IO=STDOUT, verbose::Bool=false)
254-
println(io, "Julia Version $VERSION")
256+
function versioninfo(io::IO=STDOUT; verbose::Bool=false, packages::Bool=false)
257+
println(io, "Julia Version $VERSION")
255258
if !isempty(GIT_VERSION_INFO.commit_short)
256-
println(io, "Commit $(GIT_VERSION_INFO.commit_short) ($(GIT_VERSION_INFO.date_string))")
259+
println(io, "Commit $(GIT_VERSION_INFO.commit_short) ($(GIT_VERSION_INFO.date_string))")
257260
end
258261
if ccall(:jl_is_debugbuild, Cint, ())!=0
259262
println(io, "DEBUG build")
260263
end
261-
println(io, "Platform Info:")
262-
println(io, " OS: ", is_windows() ? "Windows" : is_apple() ?
264+
println(io, "Platform Info:")
265+
println(io, " OS: ", is_windows() ? "Windows" : is_apple() ?
263266
"macOS" : Sys.KERNEL, " (", Sys.MACHINE, ")")
264267

265-
cpu = Sys.cpu_info()
266-
println(io, " CPU: ", cpu[1].model)
267-
println(io, " WORD_SIZE: ", Sys.WORD_SIZE)
268268
if verbose
269269
lsb = ""
270270
if is_linux()
@@ -274,45 +274,65 @@ function versioninfo(io::IO=STDOUT, verbose::Bool=false)
274274
try lsb = strip(readstring(`$(ENV["COMSPEC"]) /c ver`)) end
275275
end
276276
if !isempty(lsb)
277-
println(io, " ", lsb)
277+
println(io, " ", lsb)
278278
end
279279
if is_unix()
280-
println(io, " uname: ", readchomp(`uname -mprsv`))
280+
println(io, " uname: ", readchomp(`uname -mprsv`))
281+
end
282+
end
283+
284+
if verbose
285+
cpuio = IOBuffer() # print cpu_summary with correct alignment
286+
Sys.cpu_summary(cpuio)
287+
for (i, line) in enumerate(split(String(take!(cpuio)), "\n"))
288+
prefix = i == 1 ? " CPU: " : " "
289+
println(io, prefix, line)
281290
end
282-
println(io, "Memory: $(Sys.total_memory()/2^30) GB ($(Sys.free_memory()/2^20) MB free)")
283-
try println(io, "Uptime: $(Sys.uptime()) sec") end
284-
print(io, "Load Avg: ")
285-
print_matrix(io, Sys.loadavg()')
286-
println(io )
287-
Sys.cpu_summary(io)
288-
println(io )
291+
else
292+
cpu = Sys.cpu_info()
293+
println(io, " CPU: ", cpu[1].model)
289294
end
295+
296+
if verbose
297+
println(io, " Memory: $(Sys.total_memory()/2^30) GB ($(Sys.free_memory()/2^20) MB free)")
298+
try println(io, " Uptime: $(Sys.uptime()) sec") end
299+
print(io, " Load Avg: ")
300+
print_matrix(io, Sys.loadavg()')
301+
println(io)
302+
end
303+
println(io, " WORD_SIZE: ", Sys.WORD_SIZE)
290304
if Base.libblas_name == "libopenblas" || BLAS.vendor() == :openblas || BLAS.vendor() == :openblas64
291305
openblas_config = BLAS.openblas_get_config()
292-
println(io, " BLAS: libopenblas (", openblas_config, ")")
306+
println(io, " BLAS: libopenblas (", openblas_config, ")")
293307
else
294-
println(io, " BLAS: ",libblas_name)
308+
println(io, " BLAS: ",libblas_name)
309+
end
310+
println(io, " LAPACK: ",liblapack_name)
311+
println(io, " LIBM: ",libm_name)
312+
println(io, " LLVM: libLLVM-",libllvm_version," (", Sys.JIT, ", ", Sys.cpu_name, ")")
313+
314+
println(io, "Environment:")
315+
for (k,v) in ENV
316+
if ismatch(r"JULIA", String(k))
317+
println(io, " $(k) = $(v)")
318+
end
295319
end
296-
println(io, " LAPACK: ",liblapack_name)
297-
println(io, " LIBM: ",libm_name)
298-
println(io, " LLVM: libLLVM-",libllvm_version," (", Sys.JIT, ", ", Sys.cpu_name, ")")
299320
if verbose
300-
println(io, "Environment:")
301321
for (k,v) in ENV
302-
if match(r"JULIA|PATH|FLAG|^TERM$|HOME", String(k)) !== nothing
322+
if ismatch(r"PATH|FLAG|^TERM$|HOME", String(k))
303323
println(io, " $(k) = $(v)")
304324
end
305325
end
306-
println(io )
307-
println(io, "Package Directory: ", Pkg.dir())
326+
end
327+
if packages || verbose
328+
println(io, "Packages:")
329+
println(io, " Package Directory: ", Pkg.dir())
330+
println(io, " Package Status:")
308331
Pkg.status(io)
309332
end
310333
end
311-
versioninfo(verbose::Bool) = versioninfo(STDOUT,verbose)
312334

313335
# displaying type-ambiguity warnings
314-
315-
316336
"""
317337
code_warntype([io::IO], f, types)
318338

doc/src/devdocs/backtraces.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ and follow the instructions to generate the debugging information requested. Ta
1515
## [Version/Environment info](@id dev-version-info)
1616

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

2121
```@repl
2222
versioninfo()

test/pkg.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ temp_pkg_dir() do
5959
@test_throws PkgError Pkg.installed("MyFakePackage")
6060
@test Pkg.installed("Example") === nothing
6161

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

0 commit comments

Comments
 (0)