Skip to content

Commit 61233a8

Browse files
committed
Make pkg_resources_version more robust
1 parent fe49ab2 commit 61233a8

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

src/convenience.jl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,14 @@ function envinfo(io::IO = STDOUT; verbosity::Int = 1)
1717
end
1818

1919
function pkg_resources_version(name)
20-
pkg_resources = try
21-
pyimport("pkg_resources")
20+
try
21+
return pyimport("pkg_resources")[:get_distribution](name)[:version]
2222
catch err
23-
if ! (err isa PyCall.PyError)
24-
rethrow()
23+
if err isa PyCall.PyError || err isa KeyError
24+
return
2525
end
26-
return
26+
rethrow()
2727
end
28-
return pkg_resources[:get_distribution](name)[:version]
2928
end
3029

3130
function _pyversion(name)

test/test_convenience.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ include("preamble.jl")
77
@test IPython.pyversion("julia") isa String
88
@test IPython.pyversion("IPython") isa String
99
@test IPython.pyversion("IPython") == IPython._pyversion("IPython")
10+
@test IPython.pkg_resources_version("__NON_EXISTING__") isa Void
1011

1112
println("vvv DRY RUN vvv")
1213
@test_nothrow IPython.install_dependency("ipython"; dry_run=true)

0 commit comments

Comments
 (0)