29
29
from ctypes import c_char_p as char_p
30
30
from ctypes import py_object
31
31
32
+ try :
33
+ from shutil import which
34
+ except ImportError :
35
+ # For Python < 3.3; it should behave more-or-less similar to
36
+ # shutil.which when used with single argument.
37
+ from distutils .spawn import find_executable as which
38
+
32
39
# this is python 3.3 specific
33
40
from types import ModuleType , FunctionType
34
41
@@ -353,8 +360,8 @@ class Julia(object):
353
360
full access to the entire Julia interpreter.
354
361
"""
355
362
356
- def __init__ (self , init_julia = True , jl_runtime_path = None , jl_init_path = None ,
357
- debug = False ):
363
+ def __init__ (self , init_julia = True , jl_init_path = None , runtime = None ,
364
+ jl_runtime_path = None , debug = False ):
358
365
"""Create a Python object that represents a live Julia interpreter.
359
366
360
367
Parameters
@@ -365,8 +372,8 @@ def __init__(self, init_julia=True, jl_runtime_path=None, jl_init_path=None,
365
372
being called from inside an already running Julia, the flag should
366
373
be passed as False so the interpreter isn't re-initialized.
367
374
368
- jl_runtime_path : str (optional)
369
- Path to your Julia binary, e.g. "/usr/local/bin/julia"
375
+ runtime : str (optional)
376
+ Custom Julia binary, e.g. "/usr/local/bin/julia" or "julia-1.0.0".
370
377
371
378
jl_init_path : str (optional)
372
379
Path to give to jl_init relative to which we find sys.so,
@@ -389,13 +396,29 @@ def __init__(self, init_julia=True, jl_runtime_path=None, jl_init_path=None,
389
396
self .api = _julia_runtime [0 ]
390
397
return
391
398
392
- self ._debug () # so that debug message is shown nicely w/ pytest
399
+ if jl_runtime_path is not None :
400
+ warnings .warn (
401
+ "`jl_runtime_path` is deprecated. Please use `runtime`." ,
402
+ DeprecationWarning )
393
403
394
- if init_julia :
395
- if jl_runtime_path :
404
+ if runtime is None :
405
+ if jl_runtime_path is None :
406
+ runtime = "julia"
407
+ else :
396
408
runtime = jl_runtime_path
409
+ else :
410
+ if jl_runtime_path is None :
411
+ jl_runtime_path = which (runtime )
412
+ if jl_runtime_path is None :
413
+ raise RuntimeError ("Julia runtime {} cannot be found"
414
+ .format (runtime ))
397
415
else :
398
- runtime = 'julia'
416
+ raise TypeError (
417
+ "Both `runtime` and `jl_runtime_path` are specified." )
418
+
419
+ self ._debug () # so that debug message is shown nicely w/ pytest
420
+
421
+ if init_julia :
399
422
jlinfo = juliainfo (runtime )
400
423
JULIA_HOME , libjulia_path , image_file , depsjlexe = jlinfo [:4 ]
401
424
self ._debug ("pyprogramname =" , depsjlexe )
0 commit comments