Skip to content

Commit

Permalink
Resolve runtime path (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf authored and stevengj committed Sep 10, 2018
1 parent 9d1833f commit 65301c8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ Main.eval("sin.(xs)")

If you need a custom setup for `pyjulia`, it must be done *before*
importing any Julia modules. For example, to use the Julia
interpreter at `PATH/TO/MY/CUSTOM/julia`, run:
executable named `custom_julia`, run:

```python
from julia import Julia
j = julia.Julia(jl_runtime_path="PATH/TO/MY/CUSTOM/julia")
jl = julia.Julia(runtime="custom_julia")
```

You can then use, e.g.,
Expand Down
39 changes: 31 additions & 8 deletions julia/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@
from ctypes import c_char_p as char_p
from ctypes import py_object

try:
from shutil import which
except ImportError:
# For Python < 3.3; it should behave more-or-less similar to
# shutil.which when used with single argument.
from distutils.spawn import find_executable as which

# this is python 3.3 specific
from types import ModuleType, FunctionType

Expand Down Expand Up @@ -353,8 +360,8 @@ class Julia(object):
full access to the entire Julia interpreter.
"""

def __init__(self, init_julia=True, jl_runtime_path=None, jl_init_path=None,
debug=False):
def __init__(self, init_julia=True, jl_init_path=None, runtime=None,
jl_runtime_path=None, debug=False):
"""Create a Python object that represents a live Julia interpreter.
Parameters
Expand All @@ -365,8 +372,8 @@ def __init__(self, init_julia=True, jl_runtime_path=None, jl_init_path=None,
being called from inside an already running Julia, the flag should
be passed as False so the interpreter isn't re-initialized.
jl_runtime_path : str (optional)
Path to your Julia binary, e.g. "/usr/local/bin/julia"
runtime : str (optional)
Custom Julia binary, e.g. "/usr/local/bin/julia" or "julia-1.0.0".
jl_init_path : str (optional)
Path to give to jl_init relative to which we find sys.so,
Expand All @@ -389,13 +396,29 @@ def __init__(self, init_julia=True, jl_runtime_path=None, jl_init_path=None,
self.api = _julia_runtime[0]
return

self._debug() # so that debug message is shown nicely w/ pytest
if jl_runtime_path is not None:
warnings.warn(
"`jl_runtime_path` is deprecated. Please use `runtime`.",
DeprecationWarning)

if init_julia:
if jl_runtime_path:
if runtime is None:
if jl_runtime_path is None:
runtime = "julia"
else:
runtime = jl_runtime_path
else:
if jl_runtime_path is None:
jl_runtime_path = which(runtime)
if jl_runtime_path is None:
raise RuntimeError("Julia runtime {} cannot be found"
.format(runtime))
else:
runtime = 'julia'
raise TypeError(
"Both `runtime` and `jl_runtime_path` are specified.")

self._debug() # so that debug message is shown nicely w/ pytest

if init_julia:
jlinfo = juliainfo(runtime)
JULIA_HOME, libjulia_path, image_file, depsjlexe = jlinfo[:4]
self._debug("pyprogramname =", depsjlexe)
Expand Down
2 changes: 1 addition & 1 deletion test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@


orig_env = os.environ.copy()
julia = Julia(jl_runtime_path=os.getenv("JULIA_EXE"), debug=True)
julia = Julia(runtime=os.getenv("JULIA_EXE"), debug=True)


class JuliaTest(unittest.TestCase):
Expand Down

0 comments on commit 65301c8

Please sign in to comment.