Skip to content

Commit cf08c5f

Browse files
authored
Merge pull request #190 from RalphAS/ras/import0.7
Workaround for hot-loading handlers in Julia v0.7
2 parents fb40301 + 3beaecd commit cf08c5f

File tree

4 files changed

+55
-27
lines changed

4 files changed

+55
-27
lines changed

appveyor.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ branches:
1111
- /release-.*/
1212
install:
1313
- ps: "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12"
14+
# if there's a newer build queued for the same PR, cancel this one
15+
- ps: if ($env:APPVEYOR_PULL_REQUEST_NUMBER -and $env:APPVEYOR_BUILD_NUMBER -ne ((Invoke-RestMethod `
16+
https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/history?recordsNumber=50).builds | `
17+
Where-Object pullRequestId -eq $env:APPVEYOR_PULL_REQUEST_NUMBER)[0].buildNumber) { `
18+
throw "There are newer queued builds for this pull request, failing early." }
1419
# Download most recent Julia Windows binary
1520
- ps: (new-object net.webclient).DownloadFile(
1621
$env:JULIA_URL,
@@ -21,7 +26,8 @@ install:
2126
build_script:
2227
# Need to convert from shallow to complete for Pkg.clone to work
2328
# - git fetch --unshallow
24-
- C:\projects\julia\bin\julia -e "versioninfo(); Pkg.init(); Pkg.clone(pwd(), \"FileIO\")"
29+
- C:\projects\julia\bin\julia -e "using InteractiveUtils; versioninfo(); import Pkg;
30+
Pkg.clone(pwd(), \"FileIO\"); Pkg.build(\"FileIO\")"
2531

2632
test_script:
27-
- C:\projects\julia\bin\julia -e "Pkg.test(\"FileIO\")"
33+
- C:\projects\julia\bin\julia -e "import Pkg; Pkg.test(\"FileIO\")"

src/loadsave.jl

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,32 @@ const sym2saver = Dict{Symbol,Vector{Symbol}}()
33

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

6+
function _findmod(f::Symbol)
7+
for (u,v) in Base.loaded_modules
8+
(Symbol(v) == f) && return u
9+
end
10+
nothing
11+
end
12+
function topimport(modname)
13+
@eval Base.__toplevel__ import $modname
14+
u = _findmod(modname)
15+
@eval $modname = Base.loaded_modules[$u]
16+
end
17+
618
function checked_import(pkg::Symbol)
7-
isdefined(Main, pkg) && return getfield(Main, pkg)
8-
isdefined(FileIO, pkg) && return getfield(FileIO, pkg)
9-
!is_installed(pkg) && throw(NotInstalledError(pkg, ""))
10-
!isdefined(Main, pkg) && Core.eval(Main, Expr(:import, pkg))
11-
return getfield(Main, pkg)
19+
# kludge for test suite
20+
if isdefined(Main, pkg)
21+
m1 = getfield(Main, pkg)
22+
isa(m1, Module) && return m1
23+
end
24+
if isdefined(FileIO, pkg)
25+
m1 = getfield(FileIO, pkg)
26+
isa(m1, Module) && return m1
27+
end
28+
m = _findmod(pkg)
29+
m == nothing || return Base.loaded_modules[m]
30+
topimport(pkg)
31+
return Base.loaded_modules[_findmod(pkg)]
1232
end
1333

1434

test/error_handling.jl

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
11
println("these tests will print warnings: ")
22

33
@testset "Not installed" begin
4-
Core.eval(Base, :(is_interactive = true)) # for interactive error handling
5-
64
add_format(format"NotInstalled", (), ".not_installed", [:NotInstalled])
7-
stdin_copy = stdin
8-
stderr_copy = stderr
9-
rs, wr = redirect_stdin()
10-
rserr, wrerr = redirect_stderr()
11-
ref = @async save("test.not_installed", nothing)
12-
println(wr, "y")
13-
@test_throws Pkg.Types.CommandError fetch(ref) #("unknown package NotInstalled")
14-
ref = @async save("test.not_installed", nothing)
15-
println(wr, "invalid") #test invalid input
16-
println(wr, "n") # don't install
17-
fetch(ref)
18-
@test istaskdone(ref)
19-
20-
close(rs);close(wr);close(rserr);close(wrerr)
21-
redirect_stdin(stdin_copy)
22-
redirect_stderr(stderr_copy)
5+
@test_throws ArgumentError save("test.not_installed", nothing)
6+
7+
# Core.eval(Base, :(is_interactive = true)) # for interactive error handling
8+
# add_format(format"NotInstalled", (), ".not_installed", [:NotInstalled])
9+
# stdin_copy = stdin
10+
# stderr_copy = stderr
11+
# rs, wr = redirect_stdin()
12+
# rserr, wrerr = redirect_stderr()
13+
# ref = @async save("test.not_installed", nothing)
14+
# println(wr, "y")
15+
# @test_throws ArgumentError fetch(ref) #("unknown package NotInstalled")
16+
# ref = @async save("test.not_installed", nothing)
17+
# println(wr, "invalid") #test invalid input
18+
# println(wr, "n") # don't install
19+
# fetch(ref)
20+
# @test istaskdone(ref)
21+
22+
# close(rs);close(wr);close(rserr);close(wrerr)
23+
# redirect_stdin(stdin_copy)
24+
# redirect_stderr(stderr_copy)
2325

24-
Core.eval(Base, :(is_interactive = false)) # for interactive error handling
26+
# Core.eval(Base, :(is_interactive = false)) # for interactive error handling
2527

2628
end
2729

test/test_mimesave.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ for filetype in [".svg", ".pdf", ".eps", ".png"]
3737

3838
@test content_new == content_original
3939
finally
40-
rm(output_filename * filetype)
40+
isfile(output_filename * filetype) && rm(output_filename * filetype)
4141
end
4242

4343
end

0 commit comments

Comments
 (0)