-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Julia 1.0 support #183
Julia 1.0 support #183
Changes from all commits
e33636b
d6dd5db
4c916ab
5b02ab5
24022ed
1d75179
a1f0b4b
33f62a6
c1c579d
e31331a
8cb559e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
from __future__ import print_function, absolute_import | ||
|
||
import os | ||
import signal | ||
import subprocess | ||
import sys | ||
from contextlib import contextmanager | ||
|
@@ -21,14 +22,20 @@ def maybe_rebuild(rebuild, julia): | |
env = os.environ.copy() | ||
info = juliainfo(julia) | ||
|
||
build = [julia, '-e', 'Pkg.build("PyCall")'] | ||
build = [julia, '-e', """ | ||
if VERSION >= v"0.7.0-DEV.3630" | ||
using Pkg | ||
end | ||
Pkg.build("PyCall") | ||
"""] | ||
print('Building PyCall.jl with PYTHON =', sys.executable) | ||
print(*build) | ||
sys.stdout.flush() | ||
subprocess.check_call(build, env=dict(env, PYTHON=sys.executable)) | ||
try: | ||
yield | ||
finally: | ||
print() # clear out messages from py.test | ||
print('Restoring previous PyCall.jl build...') | ||
print(*build) | ||
if info.pyprogramname: | ||
|
@@ -42,8 +49,29 @@ def maybe_rebuild(rebuild, julia): | |
yield | ||
|
||
|
||
@contextmanager | ||
def ignoring(sig): | ||
""" | ||
Context manager for ignoring signal `sig`. | ||
|
||
For example,:: | ||
|
||
with ignoring(signal.SIGINT): | ||
do_something() | ||
|
||
would ignore user's ctrl-c during ``do_something()``. This is | ||
useful when launching interactive program (in which ctrl-c is a | ||
valid keybinding) from Python. | ||
""" | ||
s = signal.signal(sig, signal.SIG_IGN) | ||
try: | ||
yield | ||
finally: | ||
signal.signal(sig, s) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we have a comment about what's going on here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a docstring. |
||
|
||
|
||
def with_rebuilt(rebuild, julia, command): | ||
with maybe_rebuild(rebuild, julia): | ||
with maybe_rebuild(rebuild, julia), ignoring(signal.SIGINT): | ||
print('Execute:', *command) | ||
return subprocess.call(command) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,8 @@ | |
import sys | ||
import os | ||
|
||
import pytest | ||
|
||
python_version = sys.version_info | ||
|
||
|
||
|
@@ -56,7 +58,7 @@ def add(a, b): | |
self.assertTrue(all(x == y for x, y in zip([11, 11, 11], | ||
julia.map(lambda x: x + 1, | ||
array.array('I', [10, 10, 10]))))) | ||
self.assertEqual(6, julia.foldr(add, 0, [1, 2, 3])) | ||
self.assertEqual(6, julia.reduce(add, [1, 2, 3])) | ||
|
||
def test_call_python_with_julia_args(self): | ||
self.assertEqual(6, sum(julia.eval('(1, 2, 3)'))) | ||
|
@@ -95,10 +97,12 @@ def test_from_import_non_existing_julia_name(self): | |
assert not spamspamspam | ||
|
||
def test_julia_module_bang(self): | ||
from julia import Base | ||
xs = [1, 2, 3] | ||
ys = Base.scale_b(xs[:], 2) | ||
assert all(x * 2 == y for x, y in zip(xs, ys)) | ||
from julia.Base import Channel, put_b, take_b | ||
chan = Channel(1) | ||
sent = 123 | ||
put_b(chan, sent) | ||
received = take_b(chan) | ||
assert sent == received | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I go ahead and I do #183 (comment) (to make sure that it works on CIs). If you prefer If CIs and you are happy with it then I think it's ready for merge. |
||
|
||
def test_import_julia_submodule(self): | ||
from julia.Base import Enums | ||
|
@@ -121,6 +125,10 @@ def test_module_dir(self): | |
from julia import Base | ||
assert 'resize_b' in dir(Base) | ||
|
||
@pytest.mark.skipif( | ||
"JULIA_EXE" in orig_env, | ||
reason=("cannot be tested with custom Julia executable;" | ||
" JULIA_EXE is set to {}".format(orig_env.get("JULIA_EXE")))) | ||
def test_import_without_setup(self): | ||
command = [sys.executable, '-c', 'from julia import Base'] | ||
print('Executing:', *command) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These lines above are for suppressing "
Pkg.dir(pkgname, paths...)
is deprecated" warning.I took the code from
Pkg.dir
: https://github.com/JuliaLang/Pkg.jl/blob/df546844d98dfe233889e91a86f076e01926f69e/src/API.jl#L456-L463 (Note:Base.locate_package(::Nothing) = nothing
is defined so I don't think we need to guard againstBase.identify_package
returningnothing
asPkg.dir
does.)