Skip to content

Commit d46de1c

Browse files
committed
More robust pre-compilation cache handling for Julia 0.6
fixes #175
1 parent 0acce57 commit d46de1c

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

julia/core.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -496,16 +496,37 @@ def __init__(self, init_julia=True, jl_runtime_path=None, jl_init_path=None,
496496
# configuration and so do any packages that depend on it.
497497
self._call(u"unshift!(Base.LOAD_CACHE_PATH, abspath(Pkg.Dir._pkgroot()," +
498498
"\"lib\", \"pyjulia%s-v$(VERSION.major).$(VERSION.minor)\"))" % sys.version_info[0])
499-
# If PyCall.ji does not exist, create an empty file to force
500-
# recompilation
499+
500+
# If PyCall.jl is already pre-compiled, for the global
501+
# environment, hide it while we are loading PyCall.jl
502+
# for PyJulia which has to compile a new cache if it
503+
# does not exist. However, Julia does not compile a
504+
# new cache if it exists in Base.LOAD_CACHE_PATH[2:end].
505+
# https://github.com/JuliaPy/pyjulia/issues/92#issuecomment-289303684
501506
self._call(u"""
502-
isdir(Base.LOAD_CACHE_PATH[1]) ||
503-
mkpath(Base.LOAD_CACHE_PATH[1])
504-
depsfile = joinpath(Base.LOAD_CACHE_PATH[1],"PyCall.ji")
505-
isfile(depsfile) || touch(depsfile)
507+
for path in Base.LOAD_CACHE_PATH[2:end]
508+
cache = joinpath(path, "PyCall.ji")
509+
backup = joinpath(path, "PyCall.ji.backup")
510+
if isfile(cache)
511+
mv(cache, backup; remove_destination=true)
512+
end
513+
end
506514
""")
507515

508516
self._call(u"using PyCall")
517+
518+
if use_separate_cache:
519+
self._call(u"""
520+
for path in Base.LOAD_CACHE_PATH[2:end]
521+
cache = joinpath(path, "PyCall.ji")
522+
backup = joinpath(path, "PyCall.ji.backup")
523+
if !isfile(cache) && isfile(backup)
524+
mv(backup, cache)
525+
end
526+
rm(backup; force=true)
527+
end
528+
""")
529+
509530
# Whether we initialized Julia or not, we MUST create at least one
510531
# instance of PyObject and the convert function. Since these will be
511532
# needed on every call, we hold them in the Julia object itself so

0 commit comments

Comments
 (0)