@@ -60,7 +60,7 @@ function init_context()
60
60
CTX. which = :CondaPkg
61
61
elseif exe_path == " @PyCall"
62
62
# PyCall compatibility mode
63
- PyCall = Base. require (PYCALL_PKGID)
63
+ PyCall = Base. require (PYCALL_PKGID):: Module
64
64
exe_path = PyCall. python:: String
65
65
CTX. lib_path = PyCall. libpython:: String
66
66
CTX. which = :PyCall
@@ -86,7 +86,7 @@ function init_context()
86
86
setenv (` $(CTX. exe_path) $args ` , env)
87
87
end
88
88
89
- # Find Python library
89
+ # Find and open Python library
90
90
lib_path = something (
91
91
CTX. lib_path=== missing ? nothing : CTX. lib_path,
92
92
get (ENV , " JULIA_PYTHONCALL_LIB" , nothing ),
@@ -117,16 +117,22 @@ function init_context()
117
117
If you know where the library is, set environment variable 'JULIA_PYTHONCALL_LIB' to its path.
118
118
""" )
119
119
end
120
+
121
+ # Close the library when Julia exits
122
+ atexit () do
123
+ dlclose (CTX. lib_ptr)
124
+ end
125
+
126
+ # Get function pointers from the library
120
127
init_pointers ()
121
128
122
- # Initialize
129
+ # Initialize the interpreter
123
130
with_gil () do
124
131
CTX. is_preinitialized = Py_IsInitialized () != 0
125
132
if CTX. is_preinitialized
126
- # Already initialized (maybe you're using PyCall as well)
127
- @assert CTX. which in (:embedded , :PyCall )
133
+ @assert CTX. which == :PyCall
128
134
else
129
- @assert CTX. which in ( :unknown , :CondaPkg )
135
+ @assert CTX. which != :PyCall
130
136
# Find ProgramName and PythonHome
131
137
script = if Sys. iswindows ()
132
138
"""
@@ -178,34 +184,12 @@ function init_context()
178
184
if Py_AtExit (@cfunction (_atpyexit, Cvoid, ())) == - 1
179
185
@warn " Py_AtExit() error"
180
186
end
181
- if CTX. which != :embedded
182
- atexit () do
183
- dlclose (CTX. lib_ptr)
184
- end
185
- end
186
187
end
187
188
end
188
189
189
190
# Compare libpath with PyCall
190
191
@require PyCall= " 438e738f-606a-5dbb-bf0a-cddfbfd45ab0" init_pycall (PyCall)
191
192
192
- # C.PyObject_TryConvert_AddRule("builtins.object", PyObject, CTryConvertRule_wrapref, -100)
193
- # C.PyObject_TryConvert_AddRule("builtins.object", PyRef, CTryConvertRule_wrapref, -200)
194
- # C.PyObject_TryConvert_AddRule("collections.abc.Sequence", PyList, CTryConvertRule_wrapref, 100)
195
- # C.PyObject_TryConvert_AddRule("collections.abc.Set", PySet, CTryConvertRule_wrapref, 100)
196
- # C.PyObject_TryConvert_AddRule("collections.abc.Mapping", PyDict, CTryConvertRule_wrapref, 100)
197
- # C.PyObject_TryConvert_AddRule("_io._IOBase", PyIO, CTryConvertRule_trywrapref, 100)
198
- # C.PyObject_TryConvert_AddRule("io.IOBase", PyIO, CTryConvertRule_trywrapref, 100)
199
- # C.PyObject_TryConvert_AddRule("<buffer>", PyArray, CTryConvertRule_trywrapref, 200)
200
- # C.PyObject_TryConvert_AddRule("<buffer>", Array, CTryConvertRule_PyArray_tryconvert, 0)
201
- # C.PyObject_TryConvert_AddRule("<buffer>", PyBuffer, CTryConvertRule_wrapref, -200)
202
- # C.PyObject_TryConvert_AddRule("<arrayinterface>", PyArray, CTryConvertRule_trywrapref, 200)
203
- # C.PyObject_TryConvert_AddRule("<arrayinterface>", Array, CTryConvertRule_PyArray_tryconvert, 0)
204
- # C.PyObject_TryConvert_AddRule("<arraystruct>", PyArray, CTryConvertRule_trywrapref, 200)
205
- # C.PyObject_TryConvert_AddRule("<arraystruct>", Array, CTryConvertRule_PyArray_tryconvert, 0)
206
- # C.PyObject_TryConvert_AddRule("<array>", PyArray, CTryConvertRule_trywrapref, 0)
207
- # C.PyObject_TryConvert_AddRule("<array>", Array, CTryConvertRule_PyArray_tryconvert, 0)
208
-
209
193
with_gil () do
210
194
211
195
# Get the python version
@@ -215,8 +199,8 @@ function init_context()
215
199
error (" Cannot parse version from version string: $(repr (verstr)) " )
216
200
end
217
201
CTX. version = VersionNumber (vermatch. match)
218
- v " 3" ≤ CTX. version < v " 4" || error (
219
- " Only Python 3 is supported, this is Python $(CTX. version) at $(CTX. exe_path=== missing ? " unknown location" : CTX. exe_path) ." ,
202
+ v " 3.5 " ≤ CTX. version < v " 4" || error (
203
+ " Only Python 3.5+ is supported, this is Python $(CTX. version) at $(CTX. exe_path=== missing ? " unknown location" : CTX. exe_path) ." ,
220
204
)
221
205
222
206
end
0 commit comments