@@ -496,16 +496,37 @@ def __init__(self, init_julia=True, jl_runtime_path=None, jl_init_path=None,
496
496
# configuration and so do any packages that depend on it.
497
497
self ._call (u"unshift!(Base.LOAD_CACHE_PATH, abspath(Pkg.Dir._pkgroot()," +
498
498
"\" 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
501
506
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
506
514
""" )
507
515
508
516
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
+
509
530
# Whether we initialized Julia or not, we MUST create at least one
510
531
# instance of PyObject and the convert function. Since these will be
511
532
# needed on every call, we hold them in the Julia object itself so
0 commit comments