From e33636bb11ac8c5dda373e25cb8d66c4883ab5d5 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Thu, 16 Aug 2018 17:13:55 -0700 Subject: [PATCH 01/11] Pass runtime to juliainfo --- julia/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/julia/core.py b/julia/core.py index 959d8d96..f2db1513 100644 --- a/julia/core.py +++ b/julia/core.py @@ -342,7 +342,7 @@ def __init__(self, init_julia=True, jl_runtime_path=None, jl_init_path=None, runtime = jl_runtime_path else: runtime = 'julia' - JULIA_HOME, libjulia_path, image_file, depsjlexe = juliainfo() + JULIA_HOME, libjulia_path, image_file, depsjlexe = juliainfo(runtime) self._debug("pyprogramname =", depsjlexe) self._debug("sys.executable =", sys.executable) exe_differs = is_different_exe(depsjlexe, sys.executable) From d6dd5db17e64dd34bbef5c2ea920b00c5255dd0f Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Thu, 16 Aug 2018 17:52:37 -0700 Subject: [PATCH 02/11] Ignore SIGINT in with_rebuilt so that it works well with debuggers --- julia/with_rebuilt.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/julia/with_rebuilt.py b/julia/with_rebuilt.py index 7c4b7cac..bb30b402 100644 --- a/julia/with_rebuilt.py +++ b/julia/with_rebuilt.py @@ -8,6 +8,7 @@ from __future__ import print_function, absolute_import import os +import signal import subprocess import sys from contextlib import contextmanager @@ -42,8 +43,17 @@ def maybe_rebuild(rebuild, julia): yield +@contextmanager +def ignoring(sig): + s = signal.signal(sig, signal.SIG_IGN) + try: + yield + finally: + signal.signal(sig, s) + + 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) From 4c916abd62fc60e83fd818633a550f1993c4a86e Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Thu, 16 Aug 2018 17:10:28 -0700 Subject: [PATCH 03/11] Fix with_rebuilt for Julia 1.0 --- julia/core.py | 10 ++++++---- julia/with_rebuilt.py | 8 +++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/julia/core.py b/julia/core.py index f2db1513..36a3b1f1 100644 --- a/julia/core.py +++ b/julia/core.py @@ -262,14 +262,16 @@ def juliainfo(runtime='julia'): [runtime, "-e", """ println(VERSION < v"0.7.0-DEV.3073" ? JULIA_HOME : Base.Sys.BINDIR) + if VERSION >= v"0.7.0-DEV.3630" + using Libdl + using Pkg + end println(Libdl.dlpath(string("lib", splitext(Base.julia_exename())[1]))) println(unsafe_string(Base.JLOptions().image_file)) PyCall_depsfile = Pkg.dir("PyCall","deps","deps.jl") if isfile(PyCall_depsfile) - eval(Module(:__anon__), - Expr(:toplevel, - :(Main.Base.include($PyCall_depsfile)), - :(println(pyprogramname)))) + include(PyCall_depsfile) + println(pyprogramname) end """]) args = output.decode("utf-8").rstrip().split("\n") diff --git a/julia/with_rebuilt.py b/julia/with_rebuilt.py index bb30b402..a3b0bbfa 100644 --- a/julia/with_rebuilt.py +++ b/julia/with_rebuilt.py @@ -22,7 +22,12 @@ 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() @@ -30,6 +35,7 @@ def maybe_rebuild(rebuild, julia): try: yield finally: + print() # clear out messages from py.test print('Restoring previous PyCall.jl build...') print(*build) if info.pyprogramname: From 5b02ab5d98bcee825f28e2f48ea2463970bc86ed Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Thu, 16 Aug 2018 18:09:35 -0700 Subject: [PATCH 04/11] Make tests Julia 1.0-compatible --- test/test_core.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/test_core.py b/test/test_core.py index ed998d9b..c1e2720c 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -56,7 +56,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)'))) @@ -97,8 +97,8 @@ def test_from_import_non_existing_julia_name(self): 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)) + ys = Base.fill_b(xs[:], 10) + assert all(y == 10 for y in ys) def test_import_julia_submodule(self): from julia.Base import Enums From 24022ed04e6becaadbb55c56782058f271ca84d1 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Thu, 16 Aug 2018 18:27:16 -0700 Subject: [PATCH 05/11] Test with Julia 1.0 in Travis CI --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 127b5324..1f65117c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,7 @@ python: env: matrix: - JULIA_VERSION=0.6.4 CROSS_VERSION=1 - - JULIA_VERSION=0.7.0-rc2 + - JULIA_VERSION=1.0.0 # - JULIA_VERSION=nightly global: - TOXENV=py @@ -17,7 +17,7 @@ matrix: - language: generic env: - PYTHON=python2 - - JULIA_VERSION=0.7.0-rc2 + - JULIA_VERSION=1.0.0 # - JULIA_VERSION=nightly os: osx - language: generic @@ -29,7 +29,7 @@ matrix: - language: generic env: - PYTHON=python3 - - JULIA_VERSION=0.7.0-rc2 + - JULIA_VERSION=1.0.0 # - JULIA_VERSION=nightly os: osx - language: generic From 1d75179ab24f5cb123ba315d4badf8edd8a2ae5e Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Thu, 16 Aug 2018 18:37:11 -0700 Subject: [PATCH 06/11] Fix .travis.yml and appveyor.yml --- .travis.yml | 2 +- appveyor.yml | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1f65117c..1c032ac7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -54,7 +54,7 @@ before_script: - which $PYTHON - $PYTHON -m pip --version - $PYTHON -m pip install --quiet tox - - julia -e 'Pkg.add("PyCall")' + - julia --color=yes -e 'VERSION >= v"0.7.0-DEV.5183" && using Pkg; Pkg.add("PyCall")' script: # "py,py27" below would be redundant when the main interpreter is diff --git a/appveyor.yml b/appveyor.yml index 193efc50..85651094 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -63,7 +63,15 @@ build_script: # - C:\projects\julia\bin\julia -e "versioninfo(); Pkg.add(\"PyCall\"); Pkg.init(); Pkg.resolve()" # - C:\projects\julia\bin\julia -e "using PyCall; @assert isdefined(:PyCall); @assert typeof(PyCall) === Module" - "SET PYTHON=%PYTHONDIR%\\python.exe" - - C:\projects\julia\bin\julia -e "versioninfo(); Pkg.add(\"PyCall\")" + - C:\projects\julia\bin\julia -e " + if VERSION >= v\"0.7.0-DEV.3630\"; + using InteractiveUtils; + versioninfo(verbose=true); + else + versioninfo(true); + end; + VERSION >= v\"0.7.0-DEV.5183\" && using Pkg; + Pkg.add(\"PyCall\")" - "%PYTHONDIR%\\python.exe -m pip install --quiet tox" test_script: From a1f0b4b6cd8adb3f61940b5f502a14d7dbfebb6d Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Fri, 17 Aug 2018 15:48:36 -0700 Subject: [PATCH 07/11] Document with_rebuilt.ignoring --- julia/with_rebuilt.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/julia/with_rebuilt.py b/julia/with_rebuilt.py index a3b0bbfa..902adfd4 100644 --- a/julia/with_rebuilt.py +++ b/julia/with_rebuilt.py @@ -51,6 +51,18 @@ def maybe_rebuild(rebuild, julia): @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 From 33f62a62a526ca20d577dfd4ae9c6f42f6062c1a Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Fri, 17 Aug 2018 21:14:23 -0700 Subject: [PATCH 08/11] Skip test_import_without_setup if JULIA_EXE is set --- test/test_core.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/test_core.py b/test/test_core.py index c1e2720c..3a031d32 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -12,6 +12,8 @@ import sys import os +import pytest + python_version = sys.version_info @@ -121,6 +123,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) From c1c579dced1f0d9fbdc6b120123ef7d3f012c73c Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Sun, 19 Aug 2018 22:50:30 -0700 Subject: [PATCH 09/11] Don't use Pkg.dir in Julia >= 0.7 --- julia/core.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/julia/core.py b/julia/core.py index 36a3b1f1..ed8ca971 100644 --- a/julia/core.py +++ b/julia/core.py @@ -268,7 +268,12 @@ def juliainfo(runtime='julia'): end println(Libdl.dlpath(string("lib", splitext(Base.julia_exename())[1]))) println(unsafe_string(Base.JLOptions().image_file)) - PyCall_depsfile = Pkg.dir("PyCall","deps","deps.jl") + if VERSION < v"0.7.0" + PyCall_depsfile = Pkg.dir("PyCall","deps","deps.jl") + else + modpath = Base.locate_package(Base.identify_package("PyCall")) + PyCall_depsfile = joinpath(dirname(modpath),"..","deps","deps.jl") + end if isfile(PyCall_depsfile) include(PyCall_depsfile) println(pyprogramname) From e31331a444f757c98a476af0ee311d79dbb75610 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Sun, 19 Aug 2018 23:27:58 -0700 Subject: [PATCH 10/11] Don't call isfile(nothing) --- julia/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/julia/core.py b/julia/core.py index ed8ca971..b97f033c 100644 --- a/julia/core.py +++ b/julia/core.py @@ -274,7 +274,7 @@ def juliainfo(runtime='julia'): modpath = Base.locate_package(Base.identify_package("PyCall")) PyCall_depsfile = joinpath(dirname(modpath),"..","deps","deps.jl") end - if isfile(PyCall_depsfile) + if PyCall_depsfile !== nothing && isfile(PyCall_depsfile) include(PyCall_depsfile) println(pyprogramname) end From 8cb559e0e44c57dc9eef3bba5e6c749070ea2c49 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Mon, 20 Aug 2018 22:50:56 -0700 Subject: [PATCH 11/11] Test mutation in test_julia_module_bang --- test/test_core.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/test_core.py b/test/test_core.py index 3a031d32..b1760342 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -97,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.fill_b(xs[:], 10) - assert all(y == 10 for y in 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 def test_import_julia_submodule(self): from julia.Base import Enums