@@ -311,6 +311,8 @@ def is_accessible_name(name):
311
311
isprotected (name ) or
312
312
notascii (name ))
313
313
314
+ # fmt: on
315
+
314
316
315
317
def isdefined (julia , parent , member ):
316
318
return julia .eval ("isdefined({}, :({}))" .format (parent , member ))
@@ -338,39 +340,6 @@ def determine_if_statically_linked():
338
340
return linked_libpython () is None
339
341
340
342
341
- juliainfo_script = """
342
- println(VERSION < v"0.7.0-DEV.3073" ? JULIA_HOME : Base.Sys.BINDIR)
343
- if VERSION >= v"0.7.0-DEV.3630"
344
- using Libdl
345
- using Pkg
346
- end
347
- println(Libdl.dlpath(string("lib", splitext(Base.julia_exename())[1])))
348
- println(unsafe_string(Base.JLOptions().image_file))
349
-
350
- println(VERSION)
351
- println(VERSION.major)
352
- println(VERSION.minor)
353
- println(VERSION.patch)
354
-
355
- if VERSION < v"0.7.0"
356
- PyCall_depsfile = Pkg.dir("PyCall","deps","deps.jl")
357
- else
358
- pkg = Base.PkgId(Base.UUID(0x438e738f_606a_5dbb_bf0a_cddfbfd45ab0), "PyCall")
359
- modpath = Base.locate_package(pkg)
360
- if modpath == nothing
361
- PyCall_depsfile = nothing
362
- else
363
- PyCall_depsfile = joinpath(dirname(modpath),"..","deps","deps.jl")
364
- end
365
- end
366
- if PyCall_depsfile !== nothing && isfile(PyCall_depsfile)
367
- include(PyCall_depsfile)
368
- println(pyprogramname)
369
- println(libpython)
370
- end
371
- """
372
-
373
-
374
343
class JuliaInfo (object ):
375
344
"""
376
345
Information required for initializing Julia runtime.
@@ -417,16 +386,22 @@ def load(cls, julia="julia", **popen_kwargs):
417
386
# object file: No such file or directory":
418
387
popen_kwargs .setdefault ("env" , _enviorn )
419
388
389
+ juliainfo_script = os .path .join (
390
+ os .path .dirname (os .path .realpath (__file__ )), "juliainfo.jl"
391
+ )
420
392
proc = subprocess .Popen (
421
- [julia , "--startup-file=no" , "-e" , juliainfo_script ],
393
+ [julia , "--startup-file=no" , juliainfo_script ],
422
394
stdout = subprocess .PIPE ,
423
395
stderr = subprocess .PIPE ,
424
396
universal_newlines = True ,
425
- ** popen_kwargs )
397
+ ** popen_kwargs
398
+ )
426
399
427
400
stdout , stderr = proc .communicate ()
428
401
retcode = proc .wait ()
429
402
if retcode != 0 :
403
+ logger .debug ("STDOUT from %s:\n %s" , julia , stdout )
404
+ logger .debug ("STDERR from %s:\n %s" , julia , stderr )
430
405
if sys .version_info [0 ] < 3 :
431
406
output = "\n " .join (["STDOUT:" , stdout , "STDERR:" , stderr ])
432
407
raise subprocess .CalledProcessError (
@@ -445,9 +420,19 @@ def load(cls, julia="julia", **popen_kwargs):
445
420
446
421
return cls (julia , * args )
447
422
448
- def __init__ (self , julia , bindir , libjulia_path , sysimage ,
449
- version_raw , version_major , version_minor , version_patch ,
450
- python = None , libpython_path = None ):
423
+ def __init__ (
424
+ self ,
425
+ julia ,
426
+ version_raw ,
427
+ version_major ,
428
+ version_minor ,
429
+ version_patch ,
430
+ bindir = None ,
431
+ libjulia_path = None ,
432
+ sysimage = None ,
433
+ python = None ,
434
+ libpython_path = None ,
435
+ ):
451
436
self .julia = julia
452
437
self .bindir = bindir
453
438
self .libjulia_path = libjulia_path
@@ -501,6 +486,9 @@ def is_compatible_exe(jl_libpython):
501
486
# `jl_libpython` to be a `str` always.
502
487
503
488
489
+ # fmt: off
490
+
491
+
504
492
def setup_libjulia (libjulia ):
505
493
# Store the running interpreter reference so we can start using it via self.call
506
494
libjulia .jl_ .argtypes = [c_void_p ]
@@ -951,77 +939,28 @@ def __init__(self, init_julia=True, jl_init_path=None, runtime=None,
951
939
self .api = get_libjulia ()
952
940
elif init_julia :
953
941
jlinfo = JuliaInfo .load (runtime )
942
+ if jlinfo .version_info < (0 , 7 ):
943
+ raise RuntimeError ("PyJulia does not support Julia < 0.7 anymore" )
944
+
954
945
self .api = LibJulia .from_juliainfo (jlinfo )
955
946
956
947
if jl_init_path :
957
948
self .api .bindir = jl_init_path
958
949
959
950
options = JuliaOptions (** julia_options )
960
951
961
- use_separate_cache = not (
962
- options .compiled_modules == "no" or jlinfo .is_compatible_python ()
963
- )
964
- logger .debug ("use_separate_cache = %s" , use_separate_cache )
965
- if use_separate_cache :
966
- PYCALL_JULIA_HOME = os .path .join (
967
- os .path .dirname (os .path .realpath (__file__ )), "fake-julia" ).replace ("\\ " , "\\ \\ " )
968
- os .environ ["JULIA_HOME" ] = PYCALL_JULIA_HOME # TODO: this line can be removed when dropping Julia v0.6
969
- os .environ ["JULIA_BINDIR" ] = PYCALL_JULIA_HOME
970
- self .api .bindir = PYCALL_JULIA_HOME
952
+ is_compatible_python = jlinfo .is_compatible_python ()
953
+ logger .debug ("is_compatible_python = %r" , is_compatible_python )
954
+ logger .debug ("compiled_modules = %r" , options .compiled_modules )
955
+ if not (options .compiled_modules == "no" or is_compatible_python ):
956
+ raise_separate_cache_error (runtime , jlinfo )
971
957
972
958
was_initialized = self .api .jl_is_initialized ()
973
959
if was_initialized :
974
960
set_libjulia (self .api )
975
961
else :
976
962
self .api .init_julia (options )
977
963
978
- if use_separate_cache :
979
- if jlinfo .version_info < (0 , 6 ):
980
- raise RuntimeError (
981
- "PyJulia does not support Julia < 0.6 anymore" )
982
- elif jlinfo .version_info >= (0 , 7 ):
983
- raise_separate_cache_error (runtime , jlinfo )
984
- # Intercept precompilation
985
- os .environ ["PYCALL_PYTHON_EXE" ] = sys .executable
986
- os .environ ["PYCALL_JULIA_HOME" ] = PYCALL_JULIA_HOME
987
- os .environ ["PYJULIA_IMAGE_FILE" ] = jlinfo .sysimage
988
- os .environ ["PYCALL_LIBJULIA_PATH" ] = os .path .dirname (jlinfo .libjulia_path )
989
- # Add a private cache directory. PyCall needs a different
990
- # configuration and so do any packages that depend on it.
991
- self ._call (u"unshift!(Base.LOAD_CACHE_PATH, abspath(Pkg.Dir._pkgroot()," +
992
- "\" lib\" , \" pyjulia%s-v$(VERSION.major).$(VERSION.minor)\" ))" % sys .version_info [0 ])
993
-
994
- # If PyCall.jl is already pre-compiled, for the global
995
- # environment, hide it while we are loading PyCall.jl
996
- # for PyJulia which has to compile a new cache if it
997
- # does not exist. However, Julia does not compile a
998
- # new cache if it exists in Base.LOAD_CACHE_PATH[2:end].
999
- # https://github.com/JuliaPy/pyjulia/issues/92#issuecomment-289303684
1000
- self ._call (u"""
1001
- for path in Base.LOAD_CACHE_PATH[2:end]
1002
- cache = joinpath(path, "PyCall.ji")
1003
- backup = joinpath(path, "PyCall.ji.backup")
1004
- if isfile(cache)
1005
- mv(cache, backup; remove_destination=true)
1006
- end
1007
- end
1008
- """ )
1009
-
1010
- # This is mainly for initiating the precompilation:
1011
- self ._call (u"using PyCall" )
1012
-
1013
- if use_separate_cache :
1014
- self ._call (u"""
1015
- for path in Base.LOAD_CACHE_PATH[2:end]
1016
- cache = joinpath(path, "PyCall.ji")
1017
- backup = joinpath(path, "PyCall.ji.backup")
1018
- if !isfile(cache) && isfile(backup)
1019
- mv(backup, cache)
1020
- end
1021
- rm(backup; force=true)
1022
- end
1023
- """ )
1024
-
1025
964
# We are assuming that `jl_is_initialized()` was true only
1026
965
# if this process was a Julia process (hence PyCall had
1027
966
# already called `atexit(Py_Finalize)`). This is not true
0 commit comments