Skip to content

Commit

Permalink
Merge branch 'main' into v1
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Doris committed Nov 7, 2023
2 parents 1df6867 + 045b94c commit 3ac5f4d
Show file tree
Hide file tree
Showing 75 changed files with 142 additions and 235 deletions.
2 changes: 1 addition & 1 deletion docs/src/pycall.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions pysrc/juliacall/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
4 changes: 2 additions & 2 deletions pysrc/juliacall/ipython.py
Original file line number Diff line number Diff line change
Expand Up @@ -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""")
10 changes: 3 additions & 7 deletions src/CPython/_.jl → src/C/C.jl
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
Expand Down
27 changes: 27 additions & 0 deletions src/C/api.jl
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions src/compat/_.jl → src/Compat/Compat.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
29 changes: 29 additions & 0 deletions src/Convert/Convert.jl
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
11 changes: 5 additions & 6 deletions src/Py/_.jl → src/Core/Core.jl
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 3 additions & 1 deletion src/Py/gc.jl → src/GC/GC.jl
Original file line number Diff line number Diff line change
@@ -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[]
Expand Down
4 changes: 2 additions & 2 deletions src/jlwrap/C.jl → src/JlWrap/C.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 7 additions & 7 deletions src/jlwrap/_.jl → src/JlWrap/JlWrap.jl
Original file line number Diff line number Diff line change
@@ -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")
Expand Down Expand Up @@ -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
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 5 additions & 5 deletions src/pymacro/_.jl → src/PyMacro/PyMacro.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand Down
34 changes: 19 additions & 15 deletions src/PythonCall.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/utils/_.jl → src/Utils/Utils.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module _Utils
module Utils

function explode_union(T)
@nospecialize T
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 8 additions & 8 deletions src/pywrap/_.jl → src/Wrap/Wrap.jl
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
File renamed without changes.
29 changes: 0 additions & 29 deletions src/pyconvert/_.jl

This file was deleted.

Loading

0 comments on commit 3ac5f4d

Please sign in to comment.