forked from intitni/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInitializePython.swift
More file actions
38 lines (34 loc) · 1.1 KB
/
InitializePython.swift
File metadata and controls
38 lines (34 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import Foundation
import Python
import PythonHelper
import PythonKit
import Logger
@MainActor
func initializePython() {
guard let sitePackagePath = Bundle.main.path(forResource: "site-packages", ofType: nil),
let stdLibPath = Bundle.main.path(forResource: "python-stdlib", ofType: nil),
let libDynloadPath = Bundle.main.path(
forResource: "python-stdlib/lib-dynload",
ofType: nil
)
else {
Logger.service.info("Python is not installed!")
return
}
PythonHelper.initializePython(
sitePackagePath: sitePackagePath,
stdLibPath: stdLibPath,
libDynloadPath: libDynloadPath,
Py_Initialize: Py_Initialize,
PyEval_SaveThread: PyEval_SaveThread,
PyGILState_Ensure: PyGILState_Ensure,
PyGILState_Release: PyGILState_Release
)
Task {
// All future task should run inside runPython.
try runPython {
let sys = Python.import("sys")
Logger.service.info("Python Version: \(sys.version_info.major).\(sys.version_info.minor)")
}
}
}