From 25b63e3dabc1436cf38fb28f73bc00e11c9c03a5 Mon Sep 17 00:00:00 2001 From: cgarling Date: Wed, 20 Aug 2025 12:54:09 -0400 Subject: [PATCH 1/4] Remove `Core` reference, fixes #657 --- src/Compat/pycall.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compat/pycall.jl b/src/Compat/pycall.jl index 2dbfc3d1..fdddd261 100644 --- a/src/Compat/pycall.jl +++ b/src/Compat/pycall.jl @@ -10,7 +10,7 @@ function init_pycall(PyCall::Module) - Set the environment variable `PYTHON` to `PythonCall.C.CTX.exe_path` and rebuild PyCall. This forces PyCall to use the same interpreter as PythonCall, but needs to be repeated whenever you switch Julia environment. """ - @eval function Core.Py(x::$PyCall.PyObject) + @eval function Py(x::$PyCall.PyObject) C.CTX.matches_pycall::Bool || error($errmsg) return pynew(C.PyPtr($PyCall.pyreturn(x))) end From 3e1e007e7ec801801591aa3917d536bb0bf8c023 Mon Sep 17 00:00:00 2001 From: cgarling Date: Wed, 20 Aug 2025 22:19:13 -0400 Subject: [PATCH 2/4] Explicitly import Core.Py into Compat module --- src/Compat/Compat.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Compat/Compat.jl b/src/Compat/Compat.jl index 7e3c9584..b64db800 100644 --- a/src/Compat/Compat.jl +++ b/src/Compat/Compat.jl @@ -9,6 +9,7 @@ using ..PythonCall using ..Utils using ..C using ..Core +import ..Core: Py using ..Wrap using Serialization: Serialization, AbstractSerializer, serialize, deserialize From 338d9b62e7aea909b2e35bec2254834c5db91fd6 Mon Sep 17 00:00:00 2001 From: Christopher Doris Date: Fri, 29 Aug 2025 14:30:28 +0100 Subject: [PATCH 3/4] test(pycall): add tests for interop with pycall --- Project.toml | 4 +++- src/Compat/Compat.jl | 7 +------ src/Compat/pycall.jl | 2 +- test/Compat.jl | 8 ++++++-- test/runtests.jl | 9 +++++++++ 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/Project.toml b/Project.toml index 02209fdc..064df3be 100644 --- a/Project.toml +++ b/Project.toml @@ -23,6 +23,7 @@ Libdl = "1" MacroTools = "0.5" Markdown = "1" Pkg = "1" +PyCall = "1" Requires = "1" Serialization = "1" Tables = "1" @@ -33,8 +34,9 @@ julia = "1.9" [extras] Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" +PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" TestItemRunner = "f8b46487-2199-4994-9208-9a1283c18c0a" [targets] -test = ["Aqua", "Test", "TestItemRunner"] +test = ["Aqua", "PyCall", "Test", "TestItemRunner"] diff --git a/src/Compat/Compat.jl b/src/Compat/Compat.jl index b64db800..db8bd566 100644 --- a/src/Compat/Compat.jl +++ b/src/Compat/Compat.jl @@ -9,18 +9,13 @@ using ..PythonCall using ..Utils using ..C using ..Core -import ..Core: Py using ..Wrap using Serialization: Serialization, AbstractSerializer, serialize, deserialize using Tables: Tables using Requires: @require -import ..PythonCall: - event_loop_on, - event_loop_off, - fix_qt_plugin_path, - pytable +import ..PythonCall: event_loop_on, event_loop_off, fix_qt_plugin_path, pytable include("gui.jl") include("ipython.jl") diff --git a/src/Compat/pycall.jl b/src/Compat/pycall.jl index fdddd261..7cc54a47 100644 --- a/src/Compat/pycall.jl +++ b/src/Compat/pycall.jl @@ -10,7 +10,7 @@ function init_pycall(PyCall::Module) - Set the environment variable `PYTHON` to `PythonCall.C.CTX.exe_path` and rebuild PyCall. This forces PyCall to use the same interpreter as PythonCall, but needs to be repeated whenever you switch Julia environment. """ - @eval function Py(x::$PyCall.PyObject) + @eval function PythonCall.Py(x::$PyCall.PyObject) C.CTX.matches_pycall::Bool || error($errmsg) return pynew(C.PyPtr($PyCall.pyreturn(x))) end diff --git a/test/Compat.jl b/test/Compat.jl index 4db316d5..bb47831e 100644 --- a/test/Compat.jl +++ b/test/Compat.jl @@ -38,8 +38,12 @@ end # TODO end -@testitem "PyCall.jl" begin - # TODO +@testitem "PyCall.jl" setup = [PyCall] begin + x1 = pylist() + x2 = PyCall.PyObject(x1) + x3 = Py(x2) + @test pyisinstance(x3, pybuiltins.list) + @test pyis(x3, x1) end @testitem "Serialization.jl" begin diff --git a/test/runtests.jl b/test/runtests.jl index b9e874db..a4e2b920 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,3 +1,12 @@ using TestItemRunner @run_package_tests + +@testmodule PyCall begin + using PythonCall: PythonCall + using Pkg: Pkg + ENV["PYTHON"] = PythonCall.python_executable_path() + @info "Building PyCall..." ENV["PYTHON"] + Pkg.build("PyCall") + using PyCall +end From 8f7679f97b330f824e6831a0b2b33365e1f20bec Mon Sep 17 00:00:00 2001 From: Christopher Doris Date: Fri, 29 Aug 2025 14:30:56 +0100 Subject: [PATCH 4/4] test(pycall): explicitly test that pycall is using the same python --- test/Compat.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/test/Compat.jl b/test/Compat.jl index bb47831e..3753dd40 100644 --- a/test/Compat.jl +++ b/test/Compat.jl @@ -42,6 +42,7 @@ end x1 = pylist() x2 = PyCall.PyObject(x1) x3 = Py(x2) + @test PythonCall.C.CTX.matches_pycall @test pyisinstance(x3, pybuiltins.list) @test pyis(x3, x1) end