44A handle to a loaded instance of libpython, its interpreter, function pointers, etc.
55"""
66@kwdef mutable struct Context
7- is_embedded :: Bool = false
8- is_initialized :: Bool = false
9- is_preinitialized :: Bool = false
10- lib_ptr :: Ptr{Cvoid} = C_NULL
11- exe_path :: Union{String, Missing} = missing
12- lib_path :: Union{String, Missing} = missing
13- dlopen_flags :: UInt32 = RTLD_LAZY | RTLD_DEEPBIND | RTLD_GLOBAL
14- pyprogname :: Union{String, Missing} = missing
15- pyprogname_w :: Any = missing
16- pyhome :: Union{String, Missing} = missing
17- pyhome_w :: Any = missing
18- which :: Symbol = :unknown # :CondaPkg, :PyCall, :embedded or :unknown
19- version :: Union{VersionNumber, Missing} = missing
20- matches_pycall :: Union{Bool, Missing} = missing
7+ is_embedded:: Bool = false
8+ is_initialized:: Bool = false
9+ is_preinitialized:: Bool = false
10+ lib_ptr:: Ptr{Cvoid} = C_NULL
11+ exe_path:: Union{String,Missing} = missing
12+ lib_path:: Union{String,Missing} = missing
13+ dlopen_flags:: UInt32 = RTLD_LAZY | RTLD_DEEPBIND | RTLD_GLOBAL
14+ pyprogname:: Union{String,Missing} = missing
15+ pyprogname_w:: Any = missing
16+ pyhome:: Union{String,Missing} = missing
17+ pyhome_w:: Any = missing
18+ which:: Symbol = :unknown # :CondaPkg, :PyCall, :embedded or :unknown
19+ version:: Union{VersionNumber,Missing} = missing
20+ matches_pycall:: Union{Bool,Missing} = missing
2121end
2222
2323const CTX = Context ()
@@ -60,7 +60,9 @@ function init_context()
6060 exe_path:: String
6161 else
6262 # By default, we use Python installed by CondaPkg.
63- exe_path = Sys. iswindows () ? joinpath (CondaPkg. envdir (), " python.exe" ) : joinpath (CondaPkg. envdir (), " bin" , " python" )
63+ exe_path =
64+ Sys. iswindows () ? joinpath (CondaPkg. envdir (), " python.exe" ) :
65+ joinpath (CondaPkg. envdir (), " bin" , " python" )
6466 # It's not sufficient to only activate the env while Python is initialising,
6567 # it must also be active when loading extension modules (e.g. numpy). So we
6668 # activate the environment globally.
@@ -83,7 +85,7 @@ function init_context()
8385
8486 # Ensure Python is runnable
8587 try
86- run (pipeline (` $exe_path --version` , stdout = devnull , stderr = devnull ))
88+ run (pipeline (` $exe_path --version` , stdout = devnull , stderr = devnull ))
8789 catch
8890 error (" Python executable $(repr (exe_path)) is not executable." )
8991 end
@@ -99,9 +101,9 @@ function init_context()
99101
100102 # Find and open Python library
101103 lib_path = something (
102- CTX. lib_path=== missing ? nothing : CTX. lib_path,
104+ CTX. lib_path === missing ? nothing : CTX. lib_path,
103105 get (ENV , " JULIA_PYTHONCALL_LIB" , nothing ),
104- Some (nothing )
106+ Some (nothing ),
105107 )
106108 if lib_path != = nothing
107109 lib_ptr = dlopen_e (lib_path, CTX. dlopen_flags)
@@ -112,7 +114,9 @@ function init_context()
112114 CTX. lib_ptr = lib_ptr
113115 end
114116 else
115- for lib_path in readlines (python_cmd ([joinpath (@__DIR__ , " find_libpython.py" ), " --list-all" ]))
117+ for lib_path in readlines (
118+ python_cmd ([joinpath (@__DIR__ , " find_libpython.py" ), " --list-all" ]),
119+ )
116120 lib_ptr = dlopen_e (lib_path, CTX. dlopen_flags)
117121 if lib_ptr == C_NULL
118122 @warn " Python library $(repr (lib_path)) could not be opened."
@@ -138,7 +142,7 @@ function init_context()
138142 init_pointers ()
139143
140144 # Compare libpath with PyCall
141- @require PyCall= " 438e738f-606a-5dbb-bf0a-cddfbfd45ab0" init_pycall (PyCall)
145+ @require PyCall = " 438e738f-606a-5dbb-bf0a-cddfbfd45ab0" init_pycall (PyCall)
142146
143147 # Initialize the interpreter
144148 with_gil () do
0 commit comments