Skip to content

Commit 2e1499f

Browse files
author
Christopher Rowley
committed
remove CONFIG, add fix_qt_plugin_path preference
1 parent deb7570 commit 2e1499f

9 files changed

Lines changed: 22 additions & 44 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
* Removed unsafe API: `getptr`, `pycopy!`, `pyisnull`, `pynew`, `PyNULL`, `unsafe_pynext`.
1010
A `Py` is now always a valid, fixed, non-NULL Python object in the documented API.
1111
* Python errors no longer automatically set `sys.last_traceback` etc. when displayed from Julia.
12-
* Removed `CONFIG.auto_sys_last_traceback`.
12+
* Added [`fix_qt_plugin_path` preference](@ref pythoncall-config), replacing `CONFIG.auto_fix_qt_plugin_path`.
13+
* Removed `PythonCall.CONFIG`.
1314
* Changes to `PythonCall.GC` (now more like `Base.GC`):
1415
* `enable(true)` replaces `enable()`.
1516
* `enable(false)` replaces `disable()`.

docs/src/pythoncall.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ variables.
289289
| `exe` | `JULIA_PYTHONCALL_EXE` | Path to the Python executable, or special values (see below). |
290290
| `lib` | `JULIA_PYTHONCALL_LIB` | Path to the Python library (usually inferred automatically). |
291291
| `pickle` | `JULIA_PYTHONCALL_PICKLE` | Pickle module to use for serialization (`pickle` or `dill`). |
292+
| `fix_qt_plugin_path=<true\|false>` | `JULIA_PYTHONCALL_FIX_QT_PLUGIN_PATH=<false\|true\|0\|1\|no\|yes>` | When true (the default), automatically [fix the Qt plugin path](@ref `PythonCall.fix_qt_plugin_path`) when activating a Qt-based event loop. |
292293

293294
The easiest way to set these preferences is with the
294295
[`PreferenceTools`](https://github.com/cjdoris/PreferenceTools.jl)

docs/src/v1-migration-guide.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ work.
6565

6666
* Instead of `pdb.pm()` use `pdb.post_mortem(err[1].exception)`.
6767

68+
The `PythonCall.CONFIG.auto_fix_qt_plugin_path` config has been replaced with the
69+
[`fix_qt_plugin_path` preference](@ref pythoncall-config).
70+
71+
* Instead of `PythonCall.CONFIG.auto_fix_qt_plugin_path = false`, set preference
72+
`pkg> preference add PythonCall fix_qt_plugin_path=false` or the env var
73+
`JULIA_PYTHONCALL_FIX_QT_PLUGIN_PATH=0`.
74+
6875
## `PythonCall.GC`
6976

7077
This submodule has been changed to closer mimic the `Base.GC` API.

src/API/publics.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ if Base.VERSION ≥ v"1.11"
1212
python_version,
1313
1414
# Core
15-
CONFIG,
1615
pydel!,
1716
1817
# Compat

src/Compat/gui.jl

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This fixes the problem that Qt does not know where to find its `qt.conf` file, b
77
always looks relative to `sys.executable`, which can be the Julia executable not the Python
88
one when using this package.
99
10-
If `CONFIG.auto_fix_qt_plugin_path` is true, then this is run automatically before `PyQt4`, `PyQt5`, `PySide`, `PySide2` or `PySide6` are imported.
10+
If the `fix_qt_plugin_path` preference is true, then this is run automatically before `PyQt4`, `PyQt5`, `PySide`, `PySide2` or `PySide6` are imported.
1111
"""
1212
function fix_qt_plugin_path()
1313
C.CTX.exe_path === nothing && return false
@@ -53,30 +53,6 @@ function fix_qt_plugin_path()
5353
return false
5454
end
5555

56-
# """
57-
# pyinteract(; force=false, sleep=0.1)
58-
59-
# Some Python GUIs can work interactively, meaning the GUI is available but the interactive prompt is returned (e.g. after calling `matplotlib.pyplot.ion()`).
60-
# To use these from Julia, currently you must manually call `pyinteract()` each time you want to interact.
61-
62-
# Internally, this is calling the `PyOS_InputHook` asynchronously. Only one copy is run at a time unless `force` is true.
63-
64-
# The asynchronous task waits for `sleep` seconds before calling the hook function.
65-
# This gives time for the next prompt to be printed and waiting for input.
66-
# As a result, there will be a small delay before the GUI becomes interactive.
67-
# """
68-
# pyinteract(; force::Bool = false, sleep::Real = 0.1) =
69-
# if !CONFIG.inputhookrunning || force
70-
# CONFIG.inputhookrunning = true
71-
# @async begin
72-
# sleep > 0 && Base.sleep(sleep)
73-
# C.PyOS_RunInputHook()
74-
# CONFIG.inputhookrunning = false
75-
# end
76-
# nothing
77-
# end
78-
# export pyinteract
79-
8056
const EVENT_LOOPS = Dict{Symbol,Base.Timer}()
8157

8258
const new_event_loop_callback = pynew()
@@ -158,13 +134,14 @@ function init_gui()
158134
pycopy!(new_event_loop_callback, g["new_event_loop_callback"])
159135

160136
# add a hook to automatically call fix_qt_plugin_path()
161-
fixqthook =
162-
Py(() -> (PythonCall.CONFIG.auto_fix_qt_plugin_path && fix_qt_plugin_path(); nothing))
163-
pymodulehooks.add_hook("PyQt4", fixqthook)
164-
pymodulehooks.add_hook("PyQt5", fixqthook)
165-
pymodulehooks.add_hook("PySide", fixqthook)
166-
pymodulehooks.add_hook("PySide2", fixqthook)
167-
pymodulehooks.add_hook("PySide6", fixqthook)
137+
if getpref_fix_qt_plugin_path()
138+
fixqthook = Py(fix_qt_plugin_path)
139+
pymodulehooks.add_hook("PyQt4", fixqthook)
140+
pymodulehooks.add_hook("PyQt5", fixqthook)
141+
pymodulehooks.add_hook("PySide", fixqthook)
142+
pymodulehooks.add_hook("PySide2", fixqthook)
143+
pymodulehooks.add_hook("PySide6", fixqthook)
144+
end
168145
end
169146
end
170147

src/Core/Core.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ export
196196

197197
include("Py.jl")
198198
include("err.jl")
199-
include("config.jl")
200199
include("consts.jl")
201200
include("builtins.jl")
202201
include("stdlib.jl")

src/Core/config.jl

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

src/PythonCall.jl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ include("Wrap/Wrap.jl")
1515
include("JlWrap/JlWrap.jl")
1616
include("Compat/Compat.jl")
1717

18-
# non-exported API
19-
using .Core: CONFIG
20-
2118
# not API but used in tests
2219
for k in [
2320
:pyjlanytype,

src/Utils/Utils.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@ end
1212

1313
checkpref(::Type{String}, x) = error("invalid preference of type $(type(x)), expecting a string")
1414
checkpref(::Type{String}, x::AbstractString) = convert(String, x)
15+
checkpref(::Type{Bool}, x::Bool) = x
16+
checkpref(::Type{Bool}, x::AbstractString) = x in ("1", "yes", "true") ? true : x in ("0", "no", "false") ? false : error("expecting '0', 'no', 'false', '1', 'yes' or 'true'")
1517

1618
# Specific preference functions
1719
getpref_exe() = getpref(String, "exe", "JULIA_PYTHONCALL_EXE", "")
1820
getpref_lib() = getpref(String, "lib", "JULIA_PYTHONCALL_LIB", nothing)
1921
getpref_pickle() = getpref(String, "pickle", "JULIA_PYTHONCALL_PICKLE", "pickle")
22+
getpref_fix_qt_plugin_path() = getpref(Bool, "fix_qt_plugin_path", "JULIA_PYTHONCALL_FIX_QT_PLUGIN_PATH", true)
2023

2124
function explode_union(T)
2225
@nospecialize T

0 commit comments

Comments
 (0)