Skip to content

Commit 8b6737c

Browse files
committed
Add the InteractiveUtils.diagnostics() function
1 parent 8667272 commit 8b6737c

File tree

2 files changed

+117
-0
lines changed

2 files changed

+117
-0
lines changed

stdlib/InteractiveUtils/src/InteractiveUtils.jl

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,115 @@ function versioninfo(io::IO=stdout; verbose::Bool=false)
158158
end
159159
end
160160

161+
# copied from JuliaLang/julia#43807
162+
# TODO: delete this function once JuliaLang/julia#43807 is merged
163+
function _global_julia_startup_file()
164+
# If the user built us with a specific Base.SYSCONFDIR, check that location first for a startup.jl file
165+
# If it is not found, then continue on to the relative path based on Sys.BINDIR
166+
BINDIR = Sys.BINDIR::String
167+
SYSCONFDIR = Base.SYSCONFDIR::String
168+
if !isempty(SYSCONFDIR)
169+
p1 = abspath(BINDIR, SYSCONFDIR, "julia", "startup.jl")
170+
isfile(p1) && return p1
171+
end
172+
p2 = abspath(BINDIR, "..", "etc", "julia", "startup.jl")
173+
isfile(p2) && return p2
174+
return nothing
175+
end
176+
177+
# copied from JuliaLang/julia#43807
178+
# TODO: delete this function once JuliaLang/julia#43807 is merged
179+
function _local_julia_startup_file()
180+
if !isempty(DEPOT_PATH)
181+
path = abspath(DEPOT_PATH[1], "config", "startup.jl")
182+
isfile(path) && return path
183+
end
184+
return nothing
185+
end
186+
187+
"""
188+
diagnostics(io::IO=stdout)
189+
190+
Print a variety of useful debugging info.
191+
192+
!!! warning "Warning"
193+
The output of this function may contain sensitive information. Before sharing the output,
194+
please review the output and remove any data that should not be shared publicly.
195+
196+
See also: [`versioninfo`](@ref).
197+
"""
198+
function diagnostics(io::IO=stdout)
199+
# 1. InteractiveUtils.versioninfo(; verbose = true)
200+
# 2. Threads.nthreads()
201+
# 3. Information about the global startup file
202+
# 4. Information about the local startup file
203+
# 5. Base.julia_cmd()
204+
# 6. LinearAlgebra.versioninfo()
205+
# 7. Registry status
206+
# 8. Project status
207+
# 9. Manifest status
208+
# 10. List of outdated packages in the project
209+
# 11. List of outdated packages in the manifest
210+
# 12. Information about the current Pkg server
211+
212+
# So that we don't have to add these stdlibs as dependencies of InteractiveUtils
213+
downloads_module = Base.require(Base, :Downloads)
214+
linearalgebra_module = Base.require(Base, :LinearAlgebra)
215+
pkg_module = Base.require(Base, :Pkg)
216+
217+
versioninfo(io; verbose=true) # InteractiveUtils.versioninfo
218+
println(io, "Miscellaneous Info:")
219+
println(io, " Threads.nthreads(): ", Base.Threads.nthreads())
220+
for pair in [
221+
("Global" => _global_julia_startup_file()),
222+
("Local" => _local_julia_startup_file()),
223+
]
224+
filename = pair[2]
225+
if filename === nothing
226+
description = "does not exist"
227+
else
228+
str = strip(read(filename, String))
229+
expr = Base.Meta.parse(str; raise=false)
230+
if expr === nothing
231+
description = "does not contain any code"
232+
else
233+
description = "exists and contains code ($(filename))"
234+
end
235+
end
236+
println(io, " $(pair[1]) startup file: ", description)
237+
end
238+
println(io, " Base.julia_cmd(): ", Base.julia_cmd())
239+
linearalgebra_module.versioninfo(io)
240+
pkg_module.status(; io, mode=pkg_module.PKGMODE_PROJECT)
241+
pkg_module.status(; io, mode=pkg_module.PKGMODE_MANIFEST)
242+
println(io, "Outdated Packages:")
243+
pkg_module.status(; io, outdated=true, mode=pkg_module.PKGMODE_PROJECT)
244+
pkg_module.status(; io, outdated=true, mode=pkg_module.PKGMODE_MANIFEST)
245+
pkg_module.Registry.status(io)
246+
247+
println(io, "Pkg Server Info:")
248+
pkg_server = pkg_module.pkg_server()
249+
println(io, " Pkg.pkg_server(): ", pkg_server)
250+
if pkg_server !== nothing
251+
pkg_server_url = convert(String, strip(pkg_server))::String
252+
if !isempty(pkg_server_url)
253+
debug = (type, message) -> begin
254+
s = strip(message)
255+
if !isempty(s)
256+
println(io, " ", s)
257+
end
258+
end
259+
downloads_module.request(
260+
pkg_server_url;
261+
debug,
262+
timeout = 5,
263+
throw = false,
264+
);
265+
end
266+
end
267+
268+
return nothing
269+
end
161270

162271
function type_close_enough(@nospecialize(x), @nospecialize(t))
163272
x == t && return true

stdlib/InteractiveUtils/test/runtests.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,14 @@ end
239239
end
240240
end
241241

242+
@testset "diagnostics" begin
243+
# check that diagnostics(io) doesn't error, produces some output
244+
buf = PipeBuffer()
245+
InteractiveUtils.diagnostics(buf)
246+
output = read(buf, String)
247+
@test startswith(output, "Julia Version $VERSION")
248+
end
249+
242250
const curmod = @__MODULE__
243251
const curmod_name = fullname(curmod)
244252
const curmod_str = curmod === Main ? "Main" : join(curmod_name, ".")

0 commit comments

Comments
 (0)