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

don't show Environment: in versioninfo output when env is empty #27050

Merged
merged 1 commit into from
May 10, 2018
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
19 changes: 8 additions & 11 deletions stdlib/InteractiveUtils/src/InteractiveUtils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,14 @@ function versioninfo(io::IO=stdout; verbose::Bool=false, packages::Bool=false)
println(io, " LIBM: ",Base.libm_name)
println(io, " LLVM: libLLVM-",Base.libllvm_version," (", Sys.JIT, ", ", Sys.CPU_NAME, ")")

println(io, "Environment:")
for (k,v) in ENV
if occursin(r"JULIA", String(k))
println(io, " $(k) = $(v)")
end
end
if verbose
for (k,v) in ENV
if occursin(r"PATH|FLAG|^TERM$|HOME", String(k))
println(io, " $(k) = $(v)")
end
env_strs = [String[ " $(k) = $(v)" for (k,v) in ENV if occursin(r"JULIA", k)];
(verbose ?
String[ " $(k) = $(v)" for (k,v) in ENV if occursin(r"PATH|FLAG|^TERM$|HOME", k)] :
[])]
Copy link
Member

Choose a reason for hiding this comment

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

Just a suggestion, take it or leave it, but it seems this might be a bit clearer/DRYer as

env_strs = ["$k = $v" for (k, v) in ENV if occursin("JULIA", k) || (verbose && occursin(r"PATH|FLAG|^TERM$|HOME", k))]

Copy link
Member Author

Choose a reason for hiding this comment

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

That occurred to me, but the old code printed all the JULIA variables first, so I figured I'd preserve that.

Copy link
Member

Choose a reason for hiding this comment

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

env_strs = ["$k = $v" for (k, v) in ENV if occursin("JULIA", k)]
if verbose
    append!(env_strs, ["$k = $v" for (k, v) in ENV if occursin(r"PATH|FLAG|^TERM$|HOME", k)])
end

?

Anyway, doesn't really matter.

if !isempty(env_strs)
println(io, "Environment:")
for str in env_strs
println(io, str)
end
end
if packages || verbose
Expand Down
6 changes: 6 additions & 0 deletions stdlib/InteractiveUtils/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ end
@test isempty(readdir(dir))
end
end
let exename = `$(Base.julia_cmd()) --startup-file=no`
@test !occursin("Environment:", read(setenv(`$exename -e 'using InteractiveUtils; versioninfo()'`,
String[]), String))
@test occursin("Environment:", read(setenv(`$exename -e 'using InteractiveUtils; versioninfo()'`,
String["JULIA_CPU_CORES=1"]), String))
end
end

const curmod = @__MODULE__
Expand Down