2929from ctypes import c_char_p as char_p
3030from ctypes import py_object
3131
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+
3239# this is python 3.3 specific
3340from types import ModuleType , FunctionType
3441
@@ -353,8 +360,8 @@ class Julia(object):
353360 full access to the entire Julia interpreter.
354361 """
355362
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 ):
358365 """Create a Python object that represents a live Julia interpreter.
359366
360367 Parameters
@@ -365,8 +372,8 @@ def __init__(self, init_julia=True, jl_runtime_path=None, jl_init_path=None,
365372 being called from inside an already running Julia, the flag should
366373 be passed as False so the interpreter isn't re-initialized.
367374
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".
370377
371378 jl_init_path : str (optional)
372379 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,
389396 self .api = _julia_runtime [0 ]
390397 return
391398
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 )
393403
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 :
396408 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 ))
397415 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 :
399422 jlinfo = juliainfo (runtime )
400423 JULIA_HOME , libjulia_path , image_file , depsjlexe = jlinfo [:4 ]
401424 self ._debug ("pyprogramname =" , depsjlexe )
0 commit comments