diff --git a/docs/src/pycall.md b/docs/src/pycall.md index 852b8f53..89d95e86 100644 --- a/docs/src/pycall.md +++ b/docs/src/pycall.md @@ -10,7 +10,7 @@ On this page, we give some tips for migrating between the two modules and a comp - On Unix (Linux, Mac, etc.) the Python interpreter used by PythonCall and PyCall must be the same (see below). - On Windows, it appears to be possible for PythonCall and PyCall to use different interpreters. - To force PythonCall to use the same Python interpreter as PyCall, set the environment variable `JULIA_PYTHONCALL_EXE` to `"@PyCall"`. Note that this will opt out of automatic dependency management using CondaPkg. -- Alternatively, to force PyCall to use the same interpreter as PythonCall, set the environment variable `PYTHON` to `PythonCall.C.CTX.exe_path` and then `Pkg.build("PyCall")`. You will need to do this each time you change project, because PythonCall by default uses a different Python for each project. +- Alternatively, to force PyCall to use the same interpreter as PythonCall, set the environment variable `PYTHON` to `PythonCall.python_executable_path()` and then `Pkg.build("PyCall")`. You will need to do this each time you change project, because PythonCall by default uses a different Python for each project. ## Comparison diff --git a/pysrc/juliacall/__init__.py b/pysrc/juliacall/__init__.py index cdec9396..ca08b8a5 100644 --- a/pysrc/juliacall/__init__.py +++ b/pysrc/juliacall/__init__.py @@ -24,9 +24,9 @@ def convert(T, x): def interactive(enable=True): "Allow the Julia event loop to run in the background of the Python REPL." if enable: - PythonCall._set_python_input_hook() + PythonCall.Compat._set_python_input_hook() else: - PythonCall._unset_python_input_hook() + PythonCall.Compat._unset_python_input_hook() class JuliaError(Exception): "An error arising in Julia code." diff --git a/pysrc/juliacall/ipython.py b/pysrc/juliacall/ipython.py index b416aa98..9d9289a5 100644 --- a/pysrc/juliacall/ipython.py +++ b/pysrc/juliacall/ipython.py @@ -95,7 +95,7 @@ def load_ipython_extension(ip): ip.events.register('post_execute', PythonCall._ipython._flush_stdio) # push displays PythonCall.seval("""begin - pushdisplay(_compat.PythonDisplay()) - pushdisplay(_compat.IPythonDisplay()) + pushdisplay(Compat.PythonDisplay()) + pushdisplay(Compat.IPythonDisplay()) nothing end""") diff --git a/src/CPython/_.jl b/src/C/C.jl similarity index 74% rename from src/CPython/_.jl rename to src/C/C.jl index c2be2d13..4ceda829 100644 --- a/src/CPython/_.jl +++ b/src/C/C.jl @@ -1,9 +1,9 @@ """ - module _CPython + module PythonCall.C This module provides a direct interface to the Python C API. """ -module _CPython +module C using Base: @kwdef using UnsafePointers: UnsafePtr @@ -12,16 +12,12 @@ using Pkg: Pkg using Requires: @require using Libdl: dlpath, dlopen, dlopen_e, dlclose, dlsym, dlsym_e, RTLD_LAZY, RTLD_DEEPBIND, RTLD_GLOBAL -# import Base: @kwdef -# import CondaPkg -# import Pkg -# using Libdl, Requires, UnsafePointers, Serialization, ..Utils - include("consts.jl") include("pointers.jl") include("extras.jl") include("context.jl") include("gil.jl") +include("api.jl") function __init__() init_context() diff --git a/src/C/api.jl b/src/C/api.jl new file mode 100644 index 00000000..00930fbc --- /dev/null +++ b/src/C/api.jl @@ -0,0 +1,27 @@ +""" + python_executable_path() + +Path to the Python interpreter, or `missing` if not known. +""" +python_executable_path() = CTX.exe_path + +""" + python_library_path() + +Path to libpython, or `missing` if not known. +""" +python_library_path() = CTX.lib_path + +""" + python_library_handle() + +Handle to the open libpython, or `C_NULL` if not known. +""" +python_library_handle() = CTX.lib_ptr + +""" + python_version() + +The version of Python, or `missing` if not known. +""" +python_version() = CTX.version diff --git a/src/CPython/consts.jl b/src/C/consts.jl similarity index 100% rename from src/CPython/consts.jl rename to src/C/consts.jl diff --git a/src/CPython/context.jl b/src/C/context.jl similarity index 100% rename from src/CPython/context.jl rename to src/C/context.jl diff --git a/src/CPython/extras.jl b/src/C/extras.jl similarity index 100% rename from src/CPython/extras.jl rename to src/C/extras.jl diff --git a/src/CPython/find_libpython.py b/src/C/find_libpython.py similarity index 100% rename from src/CPython/find_libpython.py rename to src/C/find_libpython.py diff --git a/src/CPython/gil.jl b/src/C/gil.jl similarity index 100% rename from src/CPython/gil.jl rename to src/C/gil.jl diff --git a/src/CPython/pointers.jl b/src/C/pointers.jl similarity index 100% rename from src/CPython/pointers.jl rename to src/C/pointers.jl diff --git a/src/compat/_.jl b/src/Compat/Compat.jl similarity index 69% rename from src/compat/_.jl rename to src/Compat/Compat.jl index 0bead30d..a82ff7b8 100644 --- a/src/compat/_.jl +++ b/src/Compat/Compat.jl @@ -1,14 +1,14 @@ """ - module _compat + module PythonCall.Compat Misc bits and bobs for compatibility. """ -module _compat +module Compat using ..PythonCall: PythonCall # needed for docstring cross-refs - using .._Py - using .._Py: C, Utils, pynew, incref, getptr, pycopy!, pymodulehooks, pyisnull, pybytes_asvector, pysysmodule, pyosmodule, pystr_fromUTF8 - using .._pyconvert: pyconvert, @pyconvert - using .._pywrap: PyPandasDataFrame + using ..Core + using ..Core: C, Utils, pynew, incref, getptr, pycopy!, pymodulehooks, pyisnull, pybytes_asvector, pysysmodule, pyosmodule, pystr_fromUTF8 + using ..Convert: pyconvert, @pyconvert + using ..Wrap: PyPandasDataFrame using Serialization: Serialization, AbstractSerializer, serialize, deserialize using Tables: Tables using Requires: @require diff --git a/src/compat/gui.jl b/src/Compat/gui.jl similarity index 100% rename from src/compat/gui.jl rename to src/Compat/gui.jl diff --git a/src/compat/ipython.jl b/src/Compat/ipython.jl similarity index 100% rename from src/compat/ipython.jl rename to src/Compat/ipython.jl diff --git a/src/compat/multimedia.jl b/src/Compat/multimedia.jl similarity index 100% rename from src/compat/multimedia.jl rename to src/Compat/multimedia.jl diff --git a/src/compat/pycall.jl b/src/Compat/pycall.jl similarity index 100% rename from src/compat/pycall.jl rename to src/Compat/pycall.jl diff --git a/src/compat/serialization.jl b/src/Compat/serialization.jl similarity index 100% rename from src/compat/serialization.jl rename to src/Compat/serialization.jl diff --git a/src/compat/tables.jl b/src/Compat/tables.jl similarity index 100% rename from src/compat/tables.jl rename to src/Compat/tables.jl diff --git a/src/Convert/Convert.jl b/src/Convert/Convert.jl new file mode 100644 index 00000000..961e84f0 --- /dev/null +++ b/src/Convert/Convert.jl @@ -0,0 +1,29 @@ +""" + module PythonCall.Convert + +Implements `pyconvert`. +""" +module Convert + +using ..Core +using ..Core: C, Utils, @autopy, getptr, incref, pynew, PyNULL, pyisnull, pydel!, pyisint, iserrset_ambig, pyisnone, pyisTrue, pyisFalse, pyfloat_asdouble, pycomplex_ascomplex, pyisstr, pystr_asstring, pyisbytes, pybytes_asvector, pybytes_asUTF8string, pyisfloat, pyisrange, pytuple_getitem, unsafe_pynext, pyistuple, pydatetimetype, pytime_isaware, pydatetime_isaware, _base_pydatetime, _base_datetime, errmatches, errclear, errset, pyiscomplex, pythrow, pybool_asbool +using Dates: Date, Time, DateTime, Millisecond + +import ..Core: pyconvert + +include("pyconvert.jl") +include("rules.jl") +include("ctypes.jl") +include("numpy.jl") +include("pandas.jl") + +function __init__() + C.with_gil() do + init_pyconvert() + init_ctypes() + init_numpy() + init_pandas() + end +end + +end diff --git a/src/pyconvert/ctypes.jl b/src/Convert/ctypes.jl similarity index 100% rename from src/pyconvert/ctypes.jl rename to src/Convert/ctypes.jl diff --git a/src/pyconvert/numpy.jl b/src/Convert/numpy.jl similarity index 100% rename from src/pyconvert/numpy.jl rename to src/Convert/numpy.jl diff --git a/src/pyconvert/pandas.jl b/src/Convert/pandas.jl similarity index 100% rename from src/pyconvert/pandas.jl rename to src/Convert/pandas.jl diff --git a/src/pyconvert/pyconvert.jl b/src/Convert/pyconvert.jl similarity index 100% rename from src/pyconvert/pyconvert.jl rename to src/Convert/pyconvert.jl diff --git a/src/pyconvert/rules.jl b/src/Convert/rules.jl similarity index 100% rename from src/pyconvert/rules.jl rename to src/Convert/rules.jl diff --git a/src/Py/_.jl b/src/Core/Core.jl similarity index 79% rename from src/Py/_.jl rename to src/Core/Core.jl index 065c87c7..d8ae6358 100644 --- a/src/Py/_.jl +++ b/src/Core/Core.jl @@ -1,23 +1,22 @@ """ - module _Py + module PythonCall.Core Defines the `Py` type and directly related functions. """ -module _Py +module Core const VERSION = v"0.9.15" const ROOT_DIR = dirname(dirname(@__DIR__)) using ..PythonCall: PythonCall # needed for docstring cross-refs -using .._CPython: _CPython as C -using .._Utils: _Utils as Utils +using ..C: C +using ..GC: GC +using ..Utils: Utils using Base: @propagate_inbounds, @kwdef using Dates: Date, Time, DateTime, year, month, day, hour, minute, second, millisecond, microsecond, nanosecond using MacroTools: @capture using Markdown: Markdown -# using MacroTools, Dates, Tables, Markdown, Serialization, Requires, Pkg, REPL -include("gc.jl") include("Py.jl") include("err.jl") include("config.jl") diff --git a/src/Py/Py.jl b/src/Core/Py.jl similarity index 100% rename from src/Py/Py.jl rename to src/Core/Py.jl diff --git a/src/Py/builtins.jl b/src/Core/builtins.jl similarity index 100% rename from src/Py/builtins.jl rename to src/Core/builtins.jl diff --git a/src/Py/config.jl b/src/Core/config.jl similarity index 100% rename from src/Py/config.jl rename to src/Core/config.jl diff --git a/src/Py/consts.jl b/src/Core/consts.jl similarity index 100% rename from src/Py/consts.jl rename to src/Core/consts.jl diff --git a/src/Py/err.jl b/src/Core/err.jl similarity index 100% rename from src/Py/err.jl rename to src/Core/err.jl diff --git a/src/Py/juliacall.jl b/src/Core/juliacall.jl similarity index 100% rename from src/Py/juliacall.jl rename to src/Core/juliacall.jl diff --git a/src/Py/pyconst_macro.jl b/src/Core/pyconst_macro.jl similarity index 100% rename from src/Py/pyconst_macro.jl rename to src/Core/pyconst_macro.jl diff --git a/src/Py/stdlib.jl b/src/Core/stdlib.jl similarity index 100% rename from src/Py/stdlib.jl rename to src/Core/stdlib.jl diff --git a/src/Py/gc.jl b/src/GC/GC.jl similarity index 97% rename from src/Py/gc.jl rename to src/GC/GC.jl index 76c7ed21..0d1fa9a8 100644 --- a/src/Py/gc.jl +++ b/src/GC/GC.jl @@ -1,11 +1,13 @@ """ + module PythonCall.GC + Garbage collection of Python objects. See `disable` and `enable`. """ module GC -using .._Py: C +using ..C: C const ENABLED = Ref(true) const QUEUE = C.PyPtr[] diff --git a/src/jlwrap/C.jl b/src/JlWrap/C.jl similarity index 99% rename from src/jlwrap/C.jl rename to src/JlWrap/C.jl index a948e21a..e90dc478 100644 --- a/src/jlwrap/C.jl +++ b/src/JlWrap/C.jl @@ -1,7 +1,7 @@ module Cjl -using ..._CPython: _CPython as C -using ..._Utils: _Utils as Utils +using ...C: C +using ...Utils: Utils using Base: @kwdef using UnsafePointers: UnsafePtr using Serialization: serialize, deserialize diff --git a/src/jlwrap/_.jl b/src/JlWrap/JlWrap.jl similarity index 66% rename from src/jlwrap/_.jl rename to src/JlWrap/JlWrap.jl index 4ad22787..b794f366 100644 --- a/src/jlwrap/_.jl +++ b/src/JlWrap/JlWrap.jl @@ -1,19 +1,19 @@ """ - module _jlwrap + module PythonCall.JlWrap Defines the Python object wrappers around Julia objects (`juliacall.AnyValue` etc). """ -module _jlwrap +module JlWrap using ..PythonCall: PythonCall -using .._Py -using .._Py: C, Utils, pynew, @autopy, incref, decref, setptr!, getptr, pyjuliacallmodule, pycopy!, errcheck, errset, PyNULL, pyistuple, pyisnull, pyJuliaError, pydel!, pyistype, pytypecheck, pythrow, pytuple_getitem, pyisslice, pystr_asstring, pyosmodule, pyisstr -using .._pyconvert: pyconvert, @pyconvert, PYCONVERT_PRIORITY_WRAP, pyconvert_add_rule, pyconvert_tryconvert, pyconvertarg, pyconvert_result +using ..Core +using ..Core: C, Utils, pynew, @autopy, incref, decref, setptr!, getptr, pyjuliacallmodule, pycopy!, errcheck, errset, PyNULL, pyistuple, pyisnull, pyJuliaError, pydel!, pyistype, pytypecheck, pythrow, pytuple_getitem, pyisslice, pystr_asstring, pyosmodule, pyisstr +using ..Convert: pyconvert, @pyconvert, PYCONVERT_PRIORITY_WRAP, pyconvert_add_rule, pyconvert_tryconvert, pyconvertarg, pyconvert_result using Pkg: Pkg using Base: @propagate_inbounds, allocatedinline -import .._Py: Py +import ..Core: Py include("C.jl") include("base.jl") @@ -48,7 +48,7 @@ function __init__() init_callback() # add packages to juliacall jl = pyjuliacallmodule - jl.Core = Core + jl.Core = Base.Core jl.Base = Base jl.Main = Main jl.Pkg = Pkg diff --git a/src/jlwrap/any.jl b/src/JlWrap/any.jl similarity index 100% rename from src/jlwrap/any.jl rename to src/JlWrap/any.jl diff --git a/src/jlwrap/array.jl b/src/JlWrap/array.jl similarity index 100% rename from src/jlwrap/array.jl rename to src/JlWrap/array.jl diff --git a/src/jlwrap/base.jl b/src/JlWrap/base.jl similarity index 100% rename from src/jlwrap/base.jl rename to src/JlWrap/base.jl diff --git a/src/jlwrap/callback.jl b/src/JlWrap/callback.jl similarity index 100% rename from src/jlwrap/callback.jl rename to src/JlWrap/callback.jl diff --git a/src/jlwrap/dict.jl b/src/JlWrap/dict.jl similarity index 100% rename from src/jlwrap/dict.jl rename to src/JlWrap/dict.jl diff --git a/src/jlwrap/io.jl b/src/JlWrap/io.jl similarity index 100% rename from src/jlwrap/io.jl rename to src/JlWrap/io.jl diff --git a/src/jlwrap/iter.jl b/src/JlWrap/iter.jl similarity index 100% rename from src/jlwrap/iter.jl rename to src/JlWrap/iter.jl diff --git a/src/jlwrap/module.jl b/src/JlWrap/module.jl similarity index 100% rename from src/jlwrap/module.jl rename to src/JlWrap/module.jl diff --git a/src/jlwrap/number.jl b/src/JlWrap/number.jl similarity index 100% rename from src/jlwrap/number.jl rename to src/JlWrap/number.jl diff --git a/src/jlwrap/objectarray.jl b/src/JlWrap/objectarray.jl similarity index 100% rename from src/jlwrap/objectarray.jl rename to src/JlWrap/objectarray.jl diff --git a/src/jlwrap/raw.jl b/src/JlWrap/raw.jl similarity index 100% rename from src/jlwrap/raw.jl rename to src/JlWrap/raw.jl diff --git a/src/jlwrap/set.jl b/src/JlWrap/set.jl similarity index 100% rename from src/jlwrap/set.jl rename to src/JlWrap/set.jl diff --git a/src/jlwrap/type.jl b/src/JlWrap/type.jl similarity index 100% rename from src/jlwrap/type.jl rename to src/JlWrap/type.jl diff --git a/src/jlwrap/vector.jl b/src/JlWrap/vector.jl similarity index 100% rename from src/jlwrap/vector.jl rename to src/JlWrap/vector.jl diff --git a/src/pymacro/_.jl b/src/PyMacro/PyMacro.jl similarity index 98% rename from src/pymacro/_.jl rename to src/PyMacro/PyMacro.jl index 908d7e95..04bf9718 100644 --- a/src/pymacro/_.jl +++ b/src/PyMacro/PyMacro.jl @@ -12,14 +12,14 @@ # - splatting """ - module _pymacro + module PythonCall.PyMacro Provides the `@py` macro. """ -module _pymacro +module PyMacro -using .._Py -using .._Py: pyisnot, pynotin, BUILTINS, pynew, pycallargs, pydel!, pycopy!, pystr_intern!, pynulltuple, pytuple_setitem, pyset_add, pyisnull, unsafe_pynext, pydict_setitem, pylist_setitem, pynulllist, pybool_asbool, pythrow +using ..Core +using ..Core: pyisnot, pynotin, BUILTINS, pynew, pycallargs, pydel!, pycopy!, pystr_intern!, pynulltuple, pytuple_setitem, pyset_add, pyisnull, unsafe_pynext, pydict_setitem, pylist_setitem, pynulllist, pybool_asbool, pythrow using MacroTools: MacroTools, @capture, isexpr @@ -149,7 +149,7 @@ py_macro_assign(body, ans, ex) = push!(body, :($ans = $ex)) py_macro_del(body, var, tmp) = if tmp; push!(body, :($pydel!($var))); end -ismacroexpr(ex, name) = isexpr(ex, :macrocall) && (ex.args[1] === Symbol(name) || ex.args[1] === GlobalRef(Core, Symbol(name))) +ismacroexpr(ex, name) = isexpr(ex, :macrocall) && (ex.args[1] === Symbol(name) || ex.args[1] === GlobalRef(Base.Core, Symbol(name))) function py_macro_lower(st, body, ans, ex; flavour=:expr) diff --git a/src/PythonCall.jl b/src/PythonCall.jl index 323316cb..618b99d4 100644 --- a/src/PythonCall.jl +++ b/src/PythonCall.jl @@ -3,39 +3,43 @@ module PythonCall const VERSION = v"0.9.15" const ROOT_DIR = dirname(@__DIR__) -include("utils/_.jl") -include("CPython/_.jl") -include("Py/_.jl") -include("pyconvert/_.jl") -include("pymacro/_.jl") -include("pywrap/_.jl") -include("jlwrap/_.jl") -include("compat/_.jl") +include("Utils/Utils.jl") +include("C/C.jl") +include("GC/GC.jl") +include("Core/Core.jl") +include("Convert/Convert.jl") +include("PyMacro/PyMacro.jl") +include("Wrap/Wrap.jl") +include("JlWrap/JlWrap.jl") +include("Compat/Compat.jl") # re-export everything -for m in [:_Py, :_pyconvert, :_pymacro, :_pywrap, :_jlwrap, :_compat] +for m in [:Core, :Convert, :PyMacro, :Wrap, :JlWrap, :Compat] for k in names(@eval($m)) if k != m - @eval using .$m: $k + @eval const $k = $m.$k @eval export $k end end end # non-exported API -for k in [:C, :GC, :pynew, :pyisnull, :pycopy!, :getptr, :pydel!, :unsafe_pynext, :PyNULL, :CONFIG] - @eval const $k = _Py.$k +for k in [:python_executable_path, :python_library_path, :python_library_handle, :python_version] + @eval const $k = C.$k +end +for k in [:pynew, :pyisnull, :pycopy!, :getptr, :pydel!, :unsafe_pynext, :PyNULL, :CONFIG] + @eval const $k = Core.$k end for k in [:pyconvert_add_rule, :pyconvert_return, :pyconvert_unconverted, :PYCONVERT_PRIORITY_WRAP, :PYCONVERT_PRIORITY_ARRAY, :PYCONVERT_PRIORITY_CANONICAL, :PYCONVERT_PRIORITY_NORMAL, :PYCONVERT_PRIORITY_FALLBACK] - @eval const $k = _pyconvert.$k + @eval const $k = Convert.$k end for k in [:event_loop_on, :event_loop_off, :fix_qt_plugin_path] - @eval const $k = _compat.$k + @eval const $k = Compat.$k end # not API but used in tests for k in [:pyjlanytype, :pyjlarraytype, :pyjlvectortype, :pyjlbinaryiotype, :pyjltextiotype, :pyjldicttype, :pyjlmoduletype, :pyjlintegertype, :pyjlrationaltype, :pyjlrealtype, :pyjlcomplextype, :pyjlsettype, :pyjltypetype] - @eval const $k = _jlwrap.$k + @eval const $k = JlWrap.$k end end diff --git a/src/utils/_.jl b/src/Utils/Utils.jl similarity index 99% rename from src/utils/_.jl rename to src/Utils/Utils.jl index f258c196..921ef6d6 100644 --- a/src/utils/_.jl +++ b/src/Utils/Utils.jl @@ -1,4 +1,4 @@ -module _Utils +module Utils function explode_union(T) @nospecialize T diff --git a/src/pywrap/PyArray.jl b/src/Wrap/PyArray.jl similarity index 100% rename from src/pywrap/PyArray.jl rename to src/Wrap/PyArray.jl diff --git a/src/pywrap/PyDict.jl b/src/Wrap/PyDict.jl similarity index 100% rename from src/pywrap/PyDict.jl rename to src/Wrap/PyDict.jl diff --git a/src/pywrap/PyIO.jl b/src/Wrap/PyIO.jl similarity index 100% rename from src/pywrap/PyIO.jl rename to src/Wrap/PyIO.jl diff --git a/src/pywrap/PyIterable.jl b/src/Wrap/PyIterable.jl similarity index 100% rename from src/pywrap/PyIterable.jl rename to src/Wrap/PyIterable.jl diff --git a/src/pywrap/PyList.jl b/src/Wrap/PyList.jl similarity index 100% rename from src/pywrap/PyList.jl rename to src/Wrap/PyList.jl diff --git a/src/pywrap/PyPandasDataFrame.jl b/src/Wrap/PyPandasDataFrame.jl similarity index 100% rename from src/pywrap/PyPandasDataFrame.jl rename to src/Wrap/PyPandasDataFrame.jl diff --git a/src/pywrap/PySet.jl b/src/Wrap/PySet.jl similarity index 100% rename from src/pywrap/PySet.jl rename to src/Wrap/PySet.jl diff --git a/src/pywrap/PyTable.jl b/src/Wrap/PyTable.jl similarity index 100% rename from src/pywrap/PyTable.jl rename to src/Wrap/PyTable.jl diff --git a/src/pywrap/_.jl b/src/Wrap/Wrap.jl similarity index 80% rename from src/pywrap/_.jl rename to src/Wrap/Wrap.jl index bb50b9fa..4f934b28 100644 --- a/src/pywrap/_.jl +++ b/src/Wrap/Wrap.jl @@ -1,21 +1,21 @@ """ - module _pywrap + module PythonCall.Wrap Defines Julia wrappers around Python objects, including `PyList`, `PyDict`, `PyArray` and `PyIO`. """ -module _pywrap +module Wrap -using .._Py -using .._Py: C, Utils, @autopy, unsafe_pynext, pyisnull, PyNULL, getptr, pydel!, pybytes_asvector, pystr_asUTF8vector, pystr_fromUTF8, incref, decref, pynew, pyisnone, pyistuple, pyisstr -using .._pyconvert: pyconvert, pyconvert_tryconvert, pyconvert_unconverted, pyconvert_isunconverted, pyconvert_return, pyconvert_result -using .._pymacro +using ..Core +using ..Core: C, Utils, @autopy, unsafe_pynext, pyisnull, PyNULL, getptr, pydel!, pybytes_asvector, pystr_asUTF8vector, pystr_fromUTF8, incref, decref, pynew, pyisnone, pyistuple, pyisstr +using ..Convert: pyconvert, pyconvert_tryconvert, pyconvert_unconverted, pyconvert_isunconverted, pyconvert_return, pyconvert_result +using ..PyMacro using Base: @propagate_inbounds using Tables: Tables using UnsafePointers: UnsafePtr -import .._Py: Py, ispy -import .._pyconvert: pyconvert_add_rule, PYCONVERT_PRIORITY_ARRAY, PYCONVERT_PRIORITY_CANONICAL, PYCONVERT_PRIORITY_NORMAL +import ..Core: Py, ispy +import ..Convert: pyconvert_add_rule, PYCONVERT_PRIORITY_ARRAY, PYCONVERT_PRIORITY_CANONICAL, PYCONVERT_PRIORITY_NORMAL include("PyIterable.jl") include("PyDict.jl") diff --git a/src/pywrap/convert_rules.jl b/src/Wrap/convert_rules.jl similarity index 100% rename from src/pywrap/convert_rules.jl rename to src/Wrap/convert_rules.jl diff --git a/src/pyconvert/_.jl b/src/pyconvert/_.jl deleted file mode 100644 index e818f745..00000000 --- a/src/pyconvert/_.jl +++ /dev/null @@ -1,29 +0,0 @@ -""" - module _pyconvert - -Implements `pyconvert`. -""" -module _pyconvert - -using .._Py -using .._Py: C, Utils, @autopy, getptr, incref, pynew, PyNULL, pyisnull, pydel!, pyisint, iserrset_ambig, pyisnone, pyisTrue, pyisFalse, pyfloat_asdouble, pycomplex_ascomplex, pyisstr, pystr_asstring, pyisbytes, pybytes_asvector, pybytes_asUTF8string, pyisfloat, pyisrange, pytuple_getitem, unsafe_pynext, pyistuple, pydatetimetype, pytime_isaware, pydatetime_isaware, _base_pydatetime, _base_datetime, errmatches, errclear, errset, pyiscomplex, pythrow, pybool_asbool -using Dates: Date, Time, DateTime, Millisecond - -import .._Py: pyconvert - -include("pyconvert.jl") -include("rules.jl") -include("ctypes.jl") -include("numpy.jl") -include("pandas.jl") - -function __init__() - C.with_gil() do - init_pyconvert() - init_ctypes() - init_numpy() - init_pandas() - end -end - -end diff --git a/srcold/PythonCall.jl b/srcold/PythonCall.jl deleted file mode 100644 index b76b215c..00000000 --- a/srcold/PythonCall.jl +++ /dev/null @@ -1,140 +0,0 @@ -module PythonCall - -const VERSION = v"0.9.15" -const ROOT_DIR = dirname(@__DIR__) - -using Base: @propagate_inbounds -using MacroTools, Dates, Tables, Markdown, Serialization, Requires, Pkg, REPL - -include("utils.jl") - -include("cpython/CPython.jl") - -include("gc.jl") -include("Py.jl") -include("err.jl") -include("config.jl") -include("convert.jl") -# abstract interfaces -include("abstract/object.jl") -include("abstract/iter.jl") -include("abstract/builtins.jl") -include("abstract/number.jl") -include("abstract/collection.jl") -# concrete types -include("concrete/import.jl") -include("concrete/consts.jl") -include("concrete/str.jl") -include("concrete/bytes.jl") -include("concrete/tuple.jl") -include("concrete/list.jl") -include("concrete/dict.jl") -include("concrete/bool.jl") -include("concrete/int.jl") -include("concrete/float.jl") -include("concrete/complex.jl") -include("concrete/set.jl") -include("concrete/slice.jl") -include("concrete/range.jl") -include("concrete/none.jl") -include("concrete/type.jl") -include("concrete/fraction.jl") -include("concrete/datetime.jl") -include("concrete/code.jl") -include("concrete/ctypes.jl") -include("concrete/numpy.jl") -include("concrete/pandas.jl") -# @py -# anything below can depend on @py, anything above cannot -include("py_macro.jl") -# jlwrap -include("jlwrap/base.jl") -include("jlwrap/raw.jl") -include("jlwrap/callback.jl") -include("jlwrap/any.jl") -include("jlwrap/module.jl") -include("jlwrap/type.jl") -include("jlwrap/iter.jl") -include("jlwrap/objectarray.jl") -include("jlwrap/array.jl") -include("jlwrap/vector.jl") -include("jlwrap/dict.jl") -include("jlwrap/set.jl") -include("jlwrap/number.jl") -include("jlwrap/io.jl") -# pywrap -include("pywrap/PyIterable.jl") -include("pywrap/PyList.jl") -include("pywrap/PySet.jl") -include("pywrap/PyDict.jl") -include("pywrap/PyArray.jl") -include("pywrap/PyIO.jl") -include("pywrap/PyTable.jl") -include("pywrap/PyPandasDataFrame.jl") -# misc -include("pyconst_macro.jl") -include("juliacall.jl") -include("compat/stdlib.jl") -include("compat/with.jl") -include("compat/multimedia.jl") -include("compat/serialization.jl") -include("compat/gui.jl") -include("compat/ipython.jl") -include("compat/tables.jl") - -function __init__() - C.with_gil() do - init_consts() - init_pyconvert() - init_datetime() - # juliacall/jlwrap - init_juliacall() - init_jlwrap_base() - init_jlwrap_raw() - init_jlwrap_callback() - init_jlwrap_any() - init_jlwrap_module() - init_jlwrap_type() - init_jlwrap_iter() - init_jlwrap_array() - init_jlwrap_vector() - init_jlwrap_dict() - init_jlwrap_set() - init_jlwrap_number() - init_jlwrap_io() - init_juliacall_2() - # compat - init_stdlib() - init_pyshow() - init_gui() - init_tables() - init_ctypes() - init_numpy() - init_pandas() - end - @require PyCall="438e738f-606a-5dbb-bf0a-cddfbfd45ab0" init_pycall(PyCall) -end - -function init_pycall(PyCall::Module) - # allow explicit conversion between PythonCall.Py and PyCall.PyObject - # provided they are using the same interpretr - errmsg = """ - Conversion between `PyCall.PyObject` and `PythonCall.Py` is only possible when using the same Python interpreter. - - There are two ways to achieve this: - - Set the environment variable `JULIA_PYTHONCALL_EXE` to `"@PyCall"`. This forces PythonCall to use the same - interpreter as PyCall, but PythonCall loses the ability to manage its own dependencies. - - 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) - C.CTX.matches_pycall::Bool || error($errmsg) - return pynew(C.PyPtr($PyCall.pyreturn(x))) - end - @eval function $PyCall.PyObject(x::Py) - C.CTX.matches_pycall::Bool || error($errmsg) - return $PyCall.PyObject($PyCall.PyPtr(incref(getptr(x)))) - end -end - -end diff --git a/test/aqua.jl b/test/Aqua.jl similarity index 100% rename from test/aqua.jl rename to test/Aqua.jl diff --git a/test/C.jl b/test/C.jl new file mode 100644 index 00000000..69f8697a --- /dev/null +++ b/test/C.jl @@ -0,0 +1,18 @@ +@testitem "python info" begin + @testset "python_executable_path" begin + @test PythonCall.python_executable_path() isa String + @test occursin("python", PythonCall.python_executable_path()) + end + @testset "python_library_path" begin + @test PythonCall.python_library_path() isa String + @test occursin("python", PythonCall.python_library_path()) + end + @testset "python_library_handle" begin + @test PythonCall.python_library_handle() isa Ptr{Cvoid} + @test PythonCall.python_library_handle() != C_NULL + end + @testset "python_version" begin + @test PythonCall.python_version() isa VersionNumber + @test PythonCall.python_version().major == 3 + end +end diff --git a/test/compat.jl b/test/Compat.jl similarity index 98% rename from test/compat.jl rename to test/Compat.jl index 95f0a6d0..77deb310 100644 --- a/test/compat.jl +++ b/test/Compat.jl @@ -21,7 +21,7 @@ end pystdout = sys.stdout fp = sys.stdout = io.StringIO() try - d = PythonCall._compat.PythonDisplay() + d = PythonCall.Compat.PythonDisplay() @test display(d, 123) === nothing fp.seek(0) @test pyconvert(String, fp.read()) == "123\n" diff --git a/test/pyconvert.jl b/test/Convert.jl similarity index 100% rename from test/pyconvert.jl rename to test/Convert.jl diff --git a/test/Py.jl b/test/Core.jl similarity index 100% rename from test/Py.jl rename to test/Core.jl diff --git a/test/GC.jl b/test/GC.jl new file mode 100644 index 00000000..46409041 --- /dev/null +++ b/test/GC.jl @@ -0,0 +1 @@ +# TODO diff --git a/test/jlwrap.jl b/test/JlWrap.jl similarity index 100% rename from test/jlwrap.jl rename to test/JlWrap.jl diff --git a/test/pymacro.jl b/test/PyMacro.jl similarity index 100% rename from test/pymacro.jl rename to test/PyMacro.jl diff --git a/test/utils.jl b/test/Utils.jl similarity index 64% rename from test/utils.jl rename to test/Utils.jl index 2f195fd9..a0d38492 100644 --- a/test/utils.jl +++ b/test/Utils.jl @@ -1,11 +1,11 @@ @testitem "mimes_for" begin for x in Any[1, "foo", [], 'z'] - @test PythonCall._Utils.mimes_for(x) isa Vector{String} + @test PythonCall.Utils.mimes_for(x) isa Vector{String} end end @testitem "StaticString length and indexing" begin - s = PythonCall._Utils.StaticString{UInt32, 44}("ababababb") + s = PythonCall.Utils.StaticString{UInt32, 44}("ababababb") @test length(s) == 9 @test s[1] == 'a' @test s[1:2] == "ab" diff --git a/test/pywrap.jl b/test/Wrap.jl similarity index 100% rename from test/pywrap.jl rename to test/Wrap.jl