Skip to content

Commit 0b32b08

Browse files
authored
Remove Core reference from Compat/pycall.jl (#658)
* Remove `Core` reference, fixes #657 * Explicitly import Core.Py into Compat module * test(pycall): add tests for interop with pycall * test(pycall): explicitly test that pycall is using the same python --------- Co-authored-by: Christopher Doris <github.com/cjdoris>
1 parent 57d143f commit 0b32b08

File tree

5 files changed

+21
-9
lines changed

5 files changed

+21
-9
lines changed

Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Libdl = "1"
2323
MacroTools = "0.5"
2424
Markdown = "1"
2525
Pkg = "1"
26+
PyCall = "1"
2627
Requires = "1"
2728
Serialization = "1"
2829
Tables = "1"
@@ -33,8 +34,9 @@ julia = "1.9"
3334

3435
[extras]
3536
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
37+
PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
3638
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
3739
TestItemRunner = "f8b46487-2199-4994-9208-9a1283c18c0a"
3840

3941
[targets]
40-
test = ["Aqua", "Test", "TestItemRunner"]
42+
test = ["Aqua", "PyCall", "Test", "TestItemRunner"]

src/Compat/Compat.jl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@ using Serialization: Serialization, AbstractSerializer, serialize, deserialize
1515
using Tables: Tables
1616
using Requires: @require
1717

18-
import ..PythonCall:
19-
event_loop_on,
20-
event_loop_off,
21-
fix_qt_plugin_path,
22-
pytable
18+
import ..PythonCall: event_loop_on, event_loop_off, fix_qt_plugin_path, pytable
2319

2420
include("gui.jl")
2521
include("ipython.jl")

src/Compat/pycall.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function init_pycall(PyCall::Module)
1010
- Set the environment variable `PYTHON` to `PythonCall.C.CTX.exe_path` and rebuild PyCall. This forces PyCall
1111
to use the same interpreter as PythonCall, but needs to be repeated whenever you switch Julia environment.
1212
"""
13-
@eval function Core.Py(x::$PyCall.PyObject)
13+
@eval function PythonCall.Py(x::$PyCall.PyObject)
1414
C.CTX.matches_pycall::Bool || error($errmsg)
1515
return pynew(C.PyPtr($PyCall.pyreturn(x)))
1616
end

test/Compat.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,13 @@ end
3838
# TODO
3939
end
4040

41-
@testitem "PyCall.jl" begin
42-
# TODO
41+
@testitem "PyCall.jl" setup = [PyCall] begin
42+
x1 = pylist()
43+
x2 = PyCall.PyObject(x1)
44+
x3 = Py(x2)
45+
@test PythonCall.C.CTX.matches_pycall
46+
@test pyisinstance(x3, pybuiltins.list)
47+
@test pyis(x3, x1)
4348
end
4449

4550
@testitem "Serialization.jl" begin

test/runtests.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
using TestItemRunner
22

33
@run_package_tests
4+
5+
@testmodule PyCall begin
6+
using PythonCall: PythonCall
7+
using Pkg: Pkg
8+
ENV["PYTHON"] = PythonCall.python_executable_path()
9+
@info "Building PyCall..." ENV["PYTHON"]
10+
Pkg.build("PyCall")
11+
using PyCall
12+
end

0 commit comments

Comments
 (0)