Skip to content

Commit

Permalink
Merge pull request #190 from RalphAS/ras/import0.7
Browse files Browse the repository at this point in the history
Workaround for hot-loading handlers in Julia v0.7
  • Loading branch information
SimonDanisch authored Jul 16, 2018
2 parents fb40301 + 3beaecd commit cf08c5f
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 27 deletions.
10 changes: 8 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ branches:
- /release-.*/
install:
- ps: "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12"
# if there's a newer build queued for the same PR, cancel this one
- ps: if ($env:APPVEYOR_PULL_REQUEST_NUMBER -and $env:APPVEYOR_BUILD_NUMBER -ne ((Invoke-RestMethod `
https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/history?recordsNumber=50).builds | `
Where-Object pullRequestId -eq $env:APPVEYOR_PULL_REQUEST_NUMBER)[0].buildNumber) { `
throw "There are newer queued builds for this pull request, failing early." }
# Download most recent Julia Windows binary
- ps: (new-object net.webclient).DownloadFile(
$env:JULIA_URL,
Expand All @@ -21,7 +26,8 @@ install:
build_script:
# Need to convert from shallow to complete for Pkg.clone to work
# - git fetch --unshallow
- C:\projects\julia\bin\julia -e "versioninfo(); Pkg.init(); Pkg.clone(pwd(), \"FileIO\")"
- C:\projects\julia\bin\julia -e "using InteractiveUtils; versioninfo(); import Pkg;
Pkg.clone(pwd(), \"FileIO\"); Pkg.build(\"FileIO\")"

test_script:
- C:\projects\julia\bin\julia -e "Pkg.test(\"FileIO\")"
- C:\projects\julia\bin\julia -e "import Pkg; Pkg.test(\"FileIO\")"
30 changes: 25 additions & 5 deletions src/loadsave.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,32 @@ const sym2saver = Dict{Symbol,Vector{Symbol}}()

is_installed(pkg::Symbol) = get(Pkg.installed(), string(pkg), nothing) != nothing

function _findmod(f::Symbol)
for (u,v) in Base.loaded_modules
(Symbol(v) == f) && return u
end
nothing
end
function topimport(modname)
@eval Base.__toplevel__ import $modname
u = _findmod(modname)
@eval $modname = Base.loaded_modules[$u]
end

function checked_import(pkg::Symbol)
isdefined(Main, pkg) && return getfield(Main, pkg)
isdefined(FileIO, pkg) && return getfield(FileIO, pkg)
!is_installed(pkg) && throw(NotInstalledError(pkg, ""))
!isdefined(Main, pkg) && Core.eval(Main, Expr(:import, pkg))
return getfield(Main, pkg)
# kludge for test suite
if isdefined(Main, pkg)
m1 = getfield(Main, pkg)
isa(m1, Module) && return m1
end
if isdefined(FileIO, pkg)
m1 = getfield(FileIO, pkg)
isa(m1, Module) && return m1
end
m = _findmod(pkg)
m == nothing || return Base.loaded_modules[m]
topimport(pkg)
return Base.loaded_modules[_findmod(pkg)]
end


Expand Down
40 changes: 21 additions & 19 deletions test/error_handling.jl
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
println("these tests will print warnings: ")

@testset "Not installed" begin
Core.eval(Base, :(is_interactive = true)) # for interactive error handling

add_format(format"NotInstalled", (), ".not_installed", [:NotInstalled])
stdin_copy = stdin
stderr_copy = stderr
rs, wr = redirect_stdin()
rserr, wrerr = redirect_stderr()
ref = @async save("test.not_installed", nothing)
println(wr, "y")
@test_throws Pkg.Types.CommandError fetch(ref) #("unknown package NotInstalled")
ref = @async save("test.not_installed", nothing)
println(wr, "invalid") #test invalid input
println(wr, "n") # don't install
fetch(ref)
@test istaskdone(ref)

close(rs);close(wr);close(rserr);close(wrerr)
redirect_stdin(stdin_copy)
redirect_stderr(stderr_copy)
@test_throws ArgumentError save("test.not_installed", nothing)

# Core.eval(Base, :(is_interactive = true)) # for interactive error handling
# add_format(format"NotInstalled", (), ".not_installed", [:NotInstalled])
# stdin_copy = stdin
# stderr_copy = stderr
# rs, wr = redirect_stdin()
# rserr, wrerr = redirect_stderr()
# ref = @async save("test.not_installed", nothing)
# println(wr, "y")
# @test_throws ArgumentError fetch(ref) #("unknown package NotInstalled")
# ref = @async save("test.not_installed", nothing)
# println(wr, "invalid") #test invalid input
# println(wr, "n") # don't install
# fetch(ref)
# @test istaskdone(ref)

# close(rs);close(wr);close(rserr);close(wrerr)
# redirect_stdin(stdin_copy)
# redirect_stderr(stderr_copy)

Core.eval(Base, :(is_interactive = false)) # for interactive error handling
# Core.eval(Base, :(is_interactive = false)) # for interactive error handling

end

Expand Down
2 changes: 1 addition & 1 deletion test/test_mimesave.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ for filetype in [".svg", ".pdf", ".eps", ".png"]

@test content_new == content_original
finally
rm(output_filename * filetype)
isfile(output_filename * filetype) && rm(output_filename * filetype)
end

end
Expand Down

0 comments on commit cf08c5f

Please sign in to comment.