Skip to content

Commit 3ac5f4d

Browse files
author
Christopher Doris
committed
Merge branch 'main' into v1
2 parents 1df6867 + 045b94c commit 3ac5f4d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+142
-235
lines changed

docs/src/pycall.md

Lines changed: 1 addition & 1 deletion

pysrc/juliacall/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ def convert(T, x):
2424
def interactive(enable=True):
2525
"Allow the Julia event loop to run in the background of the Python REPL."
2626
if enable:
27-
PythonCall._set_python_input_hook()
27+
PythonCall.Compat._set_python_input_hook()
2828
else:
29-
PythonCall._unset_python_input_hook()
29+
PythonCall.Compat._unset_python_input_hook()
3030

3131
class JuliaError(Exception):
3232
"An error arising in Julia code."

pysrc/juliacall/ipython.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def load_ipython_extension(ip):
9595
ip.events.register('post_execute', PythonCall._ipython._flush_stdio)
9696
# push displays
9797
PythonCall.seval("""begin
98-
pushdisplay(_compat.PythonDisplay())
99-
pushdisplay(_compat.IPythonDisplay())
98+
pushdisplay(Compat.PythonDisplay())
99+
pushdisplay(Compat.IPythonDisplay())
100100
nothing
101101
end""")

src/CPython/_.jl renamed to src/C/C.jl

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"""
2-
module _CPython
2+
module PythonCall.C
33
44
This module provides a direct interface to the Python C API.
55
"""
6-
module _CPython
6+
module C
77

88
using Base: @kwdef
99
using UnsafePointers: UnsafePtr
@@ -12,16 +12,12 @@ using Pkg: Pkg
1212
using Requires: @require
1313
using Libdl: dlpath, dlopen, dlopen_e, dlclose, dlsym, dlsym_e, RTLD_LAZY, RTLD_DEEPBIND, RTLD_GLOBAL
1414

15-
# import Base: @kwdef
16-
# import CondaPkg
17-
# import Pkg
18-
# using Libdl, Requires, UnsafePointers, Serialization, ..Utils
19-
2015
include("consts.jl")
2116
include("pointers.jl")
2217
include("extras.jl")
2318
include("context.jl")
2419
include("gil.jl")
20+
include("api.jl")
2521

2622
function __init__()
2723
init_context()

src/C/api.jl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""
2+
python_executable_path()
3+
4+
Path to the Python interpreter, or `missing` if not known.
5+
"""
6+
python_executable_path() = CTX.exe_path
7+
8+
"""
9+
python_library_path()
10+
11+
Path to libpython, or `missing` if not known.
12+
"""
13+
python_library_path() = CTX.lib_path
14+
15+
"""
16+
python_library_handle()
17+
18+
Handle to the open libpython, or `C_NULL` if not known.
19+
"""
20+
python_library_handle() = CTX.lib_ptr
21+
22+
"""
23+
python_version()
24+
25+
The version of Python, or `missing` if not known.
26+
"""
27+
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.

src/compat/_.jl renamed to src/Compat/Compat.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
"""
2-
module _compat
2+
module PythonCall.Compat
33
44
Misc bits and bobs for compatibility.
55
"""
6-
module _compat
6+
module Compat
77
using ..PythonCall: PythonCall # needed for docstring cross-refs
8-
using .._Py
9-
using .._Py: C, Utils, pynew, incref, getptr, pycopy!, pymodulehooks, pyisnull, pybytes_asvector, pysysmodule, pyosmodule, pystr_fromUTF8
10-
using .._pyconvert: pyconvert, @pyconvert
11-
using .._pywrap: PyPandasDataFrame
8+
using ..Core
9+
using ..Core: C, Utils, pynew, incref, getptr, pycopy!, pymodulehooks, pyisnull, pybytes_asvector, pysysmodule, pyosmodule, pystr_fromUTF8
10+
using ..Convert: pyconvert, @pyconvert
11+
using ..Wrap: PyPandasDataFrame
1212
using Serialization: Serialization, AbstractSerializer, serialize, deserialize
1313
using Tables: Tables
1414
using Requires: @require
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/Convert/Convert.jl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""
2+
module PythonCall.Convert
3+
4+
Implements `pyconvert`.
5+
"""
6+
module Convert
7+
8+
using ..Core
9+
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
10+
using Dates: Date, Time, DateTime, Millisecond
11+
12+
import ..Core: pyconvert
13+
14+
include("pyconvert.jl")
15+
include("rules.jl")
16+
include("ctypes.jl")
17+
include("numpy.jl")
18+
include("pandas.jl")
19+
20+
function __init__()
21+
C.with_gil() do
22+
init_pyconvert()
23+
init_ctypes()
24+
init_numpy()
25+
init_pandas()
26+
end
27+
end
28+
29+
end
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/Py/_.jl renamed to src/Core/Core.jl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
"""
2-
module _Py
2+
module PythonCall.Core
33
44
Defines the `Py` type and directly related functions.
55
"""
6-
module _Py
6+
module Core
77

88
const VERSION = v"0.9.15"
99
const ROOT_DIR = dirname(dirname(@__DIR__))
1010

1111
using ..PythonCall: PythonCall # needed for docstring cross-refs
12-
using .._CPython: _CPython as C
13-
using .._Utils: _Utils as Utils
12+
using ..C: C
13+
using ..GC: GC
14+
using ..Utils: Utils
1415
using Base: @propagate_inbounds, @kwdef
1516
using Dates: Date, Time, DateTime, year, month, day, hour, minute, second, millisecond, microsecond, nanosecond
1617
using MacroTools: @capture
1718
using Markdown: Markdown
18-
# using MacroTools, Dates, Tables, Markdown, Serialization, Requires, Pkg, REPL
1919

20-
include("gc.jl")
2120
include("Py.jl")
2221
include("err.jl")
2322
include("config.jl")
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.

src/Py/gc.jl renamed to src/GC/GC.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
"""
2+
module PythonCall.GC
3+
24
Garbage collection of Python objects.
35
46
See `disable` and `enable`.
57
"""
68
module GC
79

8-
using .._Py: C
10+
using ..C: C
911

1012
const ENABLED = Ref(true)
1113
const QUEUE = C.PyPtr[]

src/jlwrap/C.jl renamed to src/JlWrap/C.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Cjl
22

3-
using ..._CPython: _CPython as C
4-
using ..._Utils: _Utils as Utils
3+
using ...C: C
4+
using ...Utils: Utils
55
using Base: @kwdef
66
using UnsafePointers: UnsafePtr
77
using Serialization: serialize, deserialize

src/jlwrap/_.jl renamed to src/JlWrap/JlWrap.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
"""
2-
module _jlwrap
2+
module PythonCall.JlWrap
33
44
Defines the Python object wrappers around Julia objects (`juliacall.AnyValue` etc).
55
"""
6-
module _jlwrap
6+
module JlWrap
77

88
using ..PythonCall: PythonCall
9-
using .._Py
10-
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
11-
using .._pyconvert: pyconvert, @pyconvert, PYCONVERT_PRIORITY_WRAP, pyconvert_add_rule, pyconvert_tryconvert, pyconvertarg, pyconvert_result
9+
using ..Core
10+
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
11+
using ..Convert: pyconvert, @pyconvert, PYCONVERT_PRIORITY_WRAP, pyconvert_add_rule, pyconvert_tryconvert, pyconvertarg, pyconvert_result
1212

1313
using Pkg: Pkg
1414
using Base: @propagate_inbounds, allocatedinline
1515

16-
import .._Py: Py
16+
import ..Core: Py
1717

1818
include("C.jl")
1919
include("base.jl")
@@ -48,7 +48,7 @@ function __init__()
4848
init_callback()
4949
# add packages to juliacall
5050
jl = pyjuliacallmodule
51-
jl.Core = Core
51+
jl.Core = Base.Core
5252
jl.Base = Base
5353
jl.Main = Main
5454
jl.Pkg = Pkg
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.

src/pymacro/_.jl renamed to src/PyMacro/PyMacro.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
# - splatting
1313

1414
"""
15-
module _pymacro
15+
module PythonCall.PyMacro
1616
1717
Provides the `@py` macro.
1818
"""
19-
module _pymacro
19+
module PyMacro
2020

21-
using .._Py
22-
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
21+
using ..Core
22+
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
2323

2424
using MacroTools: MacroTools, @capture, isexpr
2525

@@ -149,7 +149,7 @@ py_macro_assign(body, ans, ex) = push!(body, :($ans = $ex))
149149

150150
py_macro_del(body, var, tmp) = if tmp; push!(body, :($pydel!($var))); end
151151

152-
ismacroexpr(ex, name) = isexpr(ex, :macrocall) && (ex.args[1] === Symbol(name) || ex.args[1] === GlobalRef(Core, Symbol(name)))
152+
ismacroexpr(ex, name) = isexpr(ex, :macrocall) && (ex.args[1] === Symbol(name) || ex.args[1] === GlobalRef(Base.Core, Symbol(name)))
153153

154154
function py_macro_lower(st, body, ans, ex; flavour=:expr)
155155

src/PythonCall.jl

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,43 @@ module PythonCall
33
const VERSION = v"0.9.15"
44
const ROOT_DIR = dirname(@__DIR__)
55

6-
include("utils/_.jl")
7-
include("CPython/_.jl")
8-
include("Py/_.jl")
9-
include("pyconvert/_.jl")
10-
include("pymacro/_.jl")
11-
include("pywrap/_.jl")
12-
include("jlwrap/_.jl")
13-
include("compat/_.jl")
6+
include("Utils/Utils.jl")
7+
include("C/C.jl")
8+
include("GC/GC.jl")
9+
include("Core/Core.jl")
10+
include("Convert/Convert.jl")
11+
include("PyMacro/PyMacro.jl")
12+
include("Wrap/Wrap.jl")
13+
include("JlWrap/JlWrap.jl")
14+
include("Compat/Compat.jl")
1415

1516
# re-export everything
16-
for m in [:_Py, :_pyconvert, :_pymacro, :_pywrap, :_jlwrap, :_compat]
17+
for m in [:Core, :Convert, :PyMacro, :Wrap, :JlWrap, :Compat]
1718
for k in names(@eval($m))
1819
if k != m
19-
@eval using .$m: $k
20+
@eval const $k = $m.$k
2021
@eval export $k
2122
end
2223
end
2324
end
2425

2526
# non-exported API
26-
for k in [:C, :GC, :pynew, :pyisnull, :pycopy!, :getptr, :pydel!, :unsafe_pynext, :PyNULL, :CONFIG]
27-
@eval const $k = _Py.$k
27+
for k in [:python_executable_path, :python_library_path, :python_library_handle, :python_version]
28+
@eval const $k = C.$k
29+
end
30+
for k in [:pynew, :pyisnull, :pycopy!, :getptr, :pydel!, :unsafe_pynext, :PyNULL, :CONFIG]
31+
@eval const $k = Core.$k
2832
end
2933
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]
30-
@eval const $k = _pyconvert.$k
34+
@eval const $k = Convert.$k
3135
end
3236
for k in [:event_loop_on, :event_loop_off, :fix_qt_plugin_path]
33-
@eval const $k = _compat.$k
37+
@eval const $k = Compat.$k
3438
end
3539

3640
# not API but used in tests
3741
for k in [:pyjlanytype, :pyjlarraytype, :pyjlvectortype, :pyjlbinaryiotype, :pyjltextiotype, :pyjldicttype, :pyjlmoduletype, :pyjlintegertype, :pyjlrationaltype, :pyjlrealtype, :pyjlcomplextype, :pyjlsettype, :pyjltypetype]
38-
@eval const $k = _jlwrap.$k
42+
@eval const $k = JlWrap.$k
3943
end
4044

4145
end

src/utils/_.jl renamed to src/Utils/Utils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module _Utils
1+
module Utils
22

33
function explode_union(T)
44
@nospecialize T
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.

src/pywrap/_.jl renamed to src/Wrap/Wrap.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
"""
2-
module _pywrap
2+
module PythonCall.Wrap
33
44
Defines Julia wrappers around Python objects, including `PyList`, `PyDict`, `PyArray` and `PyIO`.
55
"""
6-
module _pywrap
6+
module Wrap
77

8-
using .._Py
9-
using .._Py: C, Utils, @autopy, unsafe_pynext, pyisnull, PyNULL, getptr, pydel!, pybytes_asvector, pystr_asUTF8vector, pystr_fromUTF8, incref, decref, pynew, pyisnone, pyistuple, pyisstr
10-
using .._pyconvert: pyconvert, pyconvert_tryconvert, pyconvert_unconverted, pyconvert_isunconverted, pyconvert_return, pyconvert_result
11-
using .._pymacro
8+
using ..Core
9+
using ..Core: C, Utils, @autopy, unsafe_pynext, pyisnull, PyNULL, getptr, pydel!, pybytes_asvector, pystr_asUTF8vector, pystr_fromUTF8, incref, decref, pynew, pyisnone, pyistuple, pyisstr
10+
using ..Convert: pyconvert, pyconvert_tryconvert, pyconvert_unconverted, pyconvert_isunconverted, pyconvert_return, pyconvert_result
11+
using ..PyMacro
1212

1313
using Base: @propagate_inbounds
1414
using Tables: Tables
1515
using UnsafePointers: UnsafePtr
1616

17-
import .._Py: Py, ispy
18-
import .._pyconvert: pyconvert_add_rule, PYCONVERT_PRIORITY_ARRAY, PYCONVERT_PRIORITY_CANONICAL, PYCONVERT_PRIORITY_NORMAL
17+
import ..Core: Py, ispy
18+
import ..Convert: pyconvert_add_rule, PYCONVERT_PRIORITY_ARRAY, PYCONVERT_PRIORITY_CANONICAL, PYCONVERT_PRIORITY_NORMAL
1919

2020
include("PyIterable.jl")
2121
include("PyDict.jl")
File renamed without changes.

src/pyconvert/_.jl

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)