Skip to content

Remove dead code supporting old versions of Julia/Python #647

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions src/C/context.jl
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,8 @@ function init_context()
Py_InitializeEx(0)
atexit() do
CTX.is_initialized = false
if CTX.version === missing || CTX.version < v"3.6"
Py_Finalize()
else
if Py_FinalizeEx() == -1
@warn "Py_FinalizeEx() error"
end
if Py_FinalizeEx() == -1
@warn "Py_FinalizeEx() error"
end
end
end
Expand Down Expand Up @@ -223,8 +219,8 @@ function init_context()
error("Cannot parse version from version string: $(repr(verstr))")
end
CTX.version = VersionNumber(vermatch.match)
v"3.5" ≤ CTX.version < v"4" || error(
"Only Python 3.5+ is supported, this is Python $(CTX.version) at $(CTX.exe_path===missing ? "unknown location" : CTX.exe_path).",
v"3.9" ≤ CTX.version < v"4" || error(
"Only Python 3.9+ is supported, this is Python $(CTX.version) at $(CTX.exe_path===missing ? "unknown location" : CTX.exe_path).",
)

@debug "Initialized PythonCall.jl" CTX.is_embedded CTX.is_initialized CTX.exe_path CTX.lib_path CTX.lib_ptr CTX.pyprogname CTX.pyhome CTX.version
Expand Down
10 changes: 3 additions & 7 deletions src/C/pointers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ const CAPI_FUNC_SIGS = Dict{Symbol,Pair{Tuple,Type}}(
# INITIALIZE
:Py_Initialize => () => Cvoid,
:Py_InitializeEx => (Cint,) => Cvoid,
:Py_Finalize => () => Cvoid,
:Py_FinalizeEx => () => Cint, # 3.6+
:Py_FinalizeEx => () => Cint,
:Py_AtExit => (Ptr{Cvoid},) => Cint,
:Py_IsInitialized => () => Cint,
:Py_SetPythonHome => (Ptr{Cwchar_t},) => Cvoid,
Expand Down Expand Up @@ -283,11 +282,8 @@ const POINTERS = CAPIPointers()

@eval init_pointers(p::CAPIPointers = POINTERS, lib::Ptr = CTX.lib_ptr) = begin
$([
if name == :Py_FinalizeEx
:(p.$name = dlsym_e(lib, $(QuoteNode(name))))
else
:(p.$name = dlsym(lib, $(QuoteNode(name))))
end for name in CAPI_FUNCS
:(p.$name = dlsym(lib, $(QuoteNode(name))))
for name in CAPI_FUNCS
]...)
$(
[
Expand Down
66 changes: 28 additions & 38 deletions src/Core/err.jl
Original file line number Diff line number Diff line change
Expand Up @@ -176,47 +176,37 @@ function _showerror(io::IO, e::PyException, bt; backtrace = true)
pystr(String, x.lineno),
) for x in pyimport("traceback").extract_tb(e.b)
]
if Base.VERSION < v"1.6.0-rc1"
for (i, (name, fname, lineno)) in enumerate(reverse(fs))
println(io)
printstyled(io, " [", i, "] ")
printstyled(io, name, bold = true)
printstyled(io, " at ")
printstyled(io, fname, ":", lineno, bold = true)
end
else
mcdict = Dict{String,Symbol}()
mccyclyer =
Iterators.Stateful(Iterators.cycle(Base.STACKTRACE_MODULECOLORS))
# skip a couple as a basic attempt to make the colours different from the Julia stacktrace
popfirst!(mccyclyer)
popfirst!(mccyclyer)
for (i, (name, fname, lineno)) in enumerate(reverse(fs))
println(io)
printstyled(io, " [", i, "] ")
printstyled(io, name, bold = true)
println(io)
printstyled(io, " @ ", color = :light_black)
mod = file_to_pymodule(fname)
if mod !== nothing
# print the module, with colour determined by the top level name
tmod = first(split(mod, ".", limit = 2))
color = get!(mcdict, tmod) do
popfirst!(mccyclyer)
end
printstyled(io, mod, " ", color = color)
mcdict = Dict{String,Symbol}()
mccyclyer =
Iterators.Stateful(Iterators.cycle(Base.STACKTRACE_MODULECOLORS))
# skip a couple as a basic attempt to make the colours different from the Julia stacktrace
popfirst!(mccyclyer)
popfirst!(mccyclyer)
for (i, (name, fname, lineno)) in enumerate(reverse(fs))
println(io)
printstyled(io, " [", i, "] ")
printstyled(io, name, bold = true)
println(io)
printstyled(io, " @ ", color = :light_black)
mod = file_to_pymodule(fname)
if mod !== nothing
# print the module, with colour determined by the top level name
tmod = first(split(mod, ".", limit = 2))
color = get!(mcdict, tmod) do
popfirst!(mccyclyer)
end
if isfile(fname) &&
:stacktrace_contract_userdir in names(Base, all = true) &&
Base.stacktrace_contract_userdir()
if :replaceuserpath in names(Base, all = true)
fname = Base.replaceuserpath(fname)
elseif :contractuser in names(Base.Filesystem, all = true)
fname = Base.Filesystem.contractuser(fname)
end
printstyled(io, mod, " ", color = color)
end
if isfile(fname) &&
:stacktrace_contract_userdir in names(Base, all = true) &&
Base.stacktrace_contract_userdir()
if :replaceuserpath in names(Base, all = true)
fname = Base.replaceuserpath(fname)
elseif :contractuser in names(Base.Filesystem, all = true)
fname = Base.Filesystem.contractuser(fname)
end
printstyled(io, fname, ":", lineno, color = :light_black)
end
printstyled(io, fname, ":", lineno, color = :light_black)
end
catch err
print(io, "<error while printing stacktrace: $err>")
Expand Down
Loading