Skip to content

Commit 33ecf12

Browse files
committed
Detach LangChain Python
1 parent e71d936 commit 33ecf12

3 files changed

Lines changed: 32 additions & 57 deletions

File tree

Copilot for Xcode.xcodeproj/project.pbxproj

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@
3838
C87B03AC293B2CF300C77EAE /* XcodeKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C81458902939EFDC00135263 /* XcodeKit.framework */; };
3939
C87B03AD293B2CF300C77EAE /* XcodeKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = C81458902939EFDC00135263 /* XcodeKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
4040
C882175C294187EF00A22FD3 /* Client in Frameworks */ = {isa = PBXBuildFile; productRef = C882175B294187EF00A22FD3 /* Client */; };
41-
C8A3AE522A2884DA0046E809 /* Python.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = C8A3AE512A2883430046E809 /* Python.xcframework */; };
4241
C8A3AE592A2885A70046E809 /* InitializePython.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8A3AE582A2885A70046E809 /* InitializePython.swift */; };
43-
C8A3AE5B2A288AF90046E809 /* site-packages in Resources */ = {isa = PBXBuildFile; fileRef = C8A3AE5A2A288AF90046E809 /* site-packages */; };
44-
C8A3B1772A288FA90046E809 /* python-stdlib in Resources */ = {isa = PBXBuildFile; fileRef = C8A3B1762A288FA90046E809 /* python-stdlib */; };
4542
C8C8B60929AFA35F00034BEE /* CopilotForXcodeExtensionService.app in Embed XPCService */ = {isa = PBXBuildFile; fileRef = C861E60E2994F6070056CB02 /* CopilotForXcodeExtensionService.app */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
4643
C8DCF00029CE11D500FDDDD7 /* ChatWithSelection.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8DCEFFF29CE11D500FDDDD7 /* ChatWithSelection.swift */; };
4744
/* End PBXBuildFile section */
@@ -209,7 +206,6 @@
209206
buildActionMask = 2147483647;
210207
files = (
211208
C861E61E2994F6150056CB02 /* Service in Frameworks */,
212-
C8A3AE522A2884DA0046E809 /* Python.xcframework in Frameworks */,
213209
);
214210
runOnlyForDeploymentPostprocessing = 0;
215211
};
@@ -497,8 +493,6 @@
497493
files = (
498494
C861E6152994F6080056CB02 /* Assets.xcassets in Resources */,
499495
C81291D72994FE6900196E12 /* Main.storyboard in Resources */,
500-
C8A3B1772A288FA90046E809 /* python-stdlib in Resources */,
501-
C8A3AE5B2A288AF90046E809 /* site-packages in Resources */,
502496
);
503497
runOnlyForDeploymentPostprocessing = 0;
504498
};
@@ -522,7 +516,7 @@
522516
);
523517
runOnlyForDeploymentPostprocessing = 0;
524518
shellPath = /bin/sh;
525-
shellScript = "set -e\necho \"Signing as $EXPANDED_CODE_SIGN_IDENTITY_NAME ($EXPANDED_CODE_SIGN_IDENTITY)\"\nfind \"$CODESIGNING_FOLDER_PATH/Contents/Resources/python-stdlib/lib-dynload\" -name \"*.so\" -exec /usr/bin/codesign --force --sign \"$EXPANDED_CODE_SIGN_IDENTITY\" -o runtime --timestamp=none --preserve-metadata=identifier,entitlements,flags --generate-entitlement-der {} \\;\n";
519+
shellScript = "#set -e\n#echo \"Signing as $EXPANDED_CODE_SIGN_IDENTITY_NAME ($EXPANDED_CODE_SIGN_IDENTITY)\"\n#find \"$CODESIGNING_FOLDER_PATH/Contents/Resources/python-stdlib/lib-dynload\" -name \"*.so\" -exec /usr/bin/codesign --force --sign \"$EXPANDED_CODE_SIGN_IDENTITY\" -o runtime --timestamp=none --preserve-metadata=identifier,entitlements,flags --generate-entitlement-der {} \\;\n";
526520
};
527521
C8A3B1782A2894E10046E809 /* Sign Python Site Packages */ = {
528522
isa = PBXShellScriptBuildPhase;
@@ -541,7 +535,7 @@
541535
);
542536
runOnlyForDeploymentPostprocessing = 0;
543537
shellPath = /bin/sh;
544-
shellScript = "set -e\necho \"Signing as $EXPANDED_CODE_SIGN_IDENTITY_NAME ($EXPANDED_CODE_SIGN_IDENTITY)\"\nfind \"$CODESIGNING_FOLDER_PATH/Contents/Resources/site-packages\" -type f \\( -name \"*.so\" -o -name \"*.dylib\" \\) -exec /usr/bin/codesign --force --sign \"$EXPANDED_CODE_SIGN_IDENTITY\" -o runtime --timestamp=none --preserve-metadata=identifier,entitlements,flags --generate-entitlement-der {} \\;\n";
538+
shellScript = "#set -e\n#echo \"Signing as $EXPANDED_CODE_SIGN_IDENTITY_NAME ($EXPANDED_CODE_SIGN_IDENTITY)\"\n#find \"$CODESIGNING_FOLDER_PATH/Contents/Resources/site-packages\" -type f \\( -name \"*.so\" -o -name \"*.dylib\" \\) -exec /usr/bin/codesign --force --sign \"$EXPANDED_CODE_SIGN_IDENTITY\" -o runtime --timestamp=none --preserve-metadata=identifier,entitlements,flags --generate-entitlement-der {} \\;\n";
545539
};
546540
/* End PBXShellScriptBuildPhase section */
547541

DEVELOPMENT.md

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ Most of the logics are implemented inside the package `Core`.
2727

2828
## Building and Archiving the App
2929

30-
1. Run `make setup` to setup the project. (You may need to install the specific version of python to install the dependencies, please check `Python/site-packages/install.sh` for details.)
31-
2. Build or archive the Copilot for Xcode target.
30+
1. Build or archive the Copilot for Xcode target.
3231

3332
## Testing Extension
3433

@@ -44,24 +43,6 @@ For new tests, they should be added to the `TestPlan.xctestplan`.
4443

4544
To create a chat plugin, please use the `TerminalChatPlugin` as an example. You should add your plugin to the target `ChatPlugin` and register it in `ChatService`.
4645

47-
## LangChain and Python
48-
49-
The app uses PythonKit to execute Python code.
50-
51-
When running Python code, ensure that you wrap it inside `runPython`. This will automatically insert `GilStateEnsure` and `GilStateRelease` for you.
52-
53-
```swift
54-
import PythonHelper
55-
56-
try runPython {
57-
// access python here
58-
}
59-
```
60-
61-
Instead of throwing a `PythonError`, `runPython` will throw a `ReadablePythonError`.
62-
63-
If importing a Python module causes the app to crash, it is usually due to the thread's stack size being too small. To resolve this, try importing with `Python.attemptImportOnPythonThread`, which is defined in `PythonHelper`, or simply import from the main thread.
64-
6546
## Code Style
6647

6748
We use SwiftFormat to format the code.
Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
import Foundation
2-
import Python
2+
//import Python
33
import PythonHelper
44
import PythonKit
55
import Logger
66

77
@MainActor
88
func initializePython() {
9-
guard let sitePackagePath = Bundle.main.path(forResource: "site-packages", ofType: nil),
10-
let stdLibPath = Bundle.main.path(forResource: "python-stdlib", ofType: nil),
11-
let libDynloadPath = Bundle.main.path(
12-
forResource: "python-stdlib/lib-dynload",
13-
ofType: nil
14-
)
15-
else {
16-
Logger.service.info("Python is not installed!")
17-
return
18-
}
19-
20-
PythonHelper.initializePython(
21-
sitePackagePath: sitePackagePath,
22-
stdLibPath: stdLibPath,
23-
libDynloadPath: libDynloadPath,
24-
Py_Initialize: Py_Initialize,
25-
PyEval_SaveThread: PyEval_SaveThread,
26-
PyGILState_Ensure: PyGILState_Ensure,
27-
PyGILState_Release: PyGILState_Release
28-
)
29-
30-
Task {
31-
// All future task should run inside runPython.
32-
try runPython {
33-
let sys = Python.import("sys")
34-
Logger.service.info("Python Version: \(sys.version_info.major).\(sys.version_info.minor)")
35-
}
36-
}
9+
// guard let sitePackagePath = Bundle.main.path(forResource: "site-packages", ofType: nil),
10+
// let stdLibPath = Bundle.main.path(forResource: "python-stdlib", ofType: nil),
11+
// let libDynloadPath = Bundle.main.path(
12+
// forResource: "python-stdlib/lib-dynload",
13+
// ofType: nil
14+
// )
15+
// else {
16+
// Logger.service.info("Python is not installed!")
17+
// return
18+
// }
19+
//
20+
// PythonHelper.initializePython(
21+
// sitePackagePath: sitePackagePath,
22+
// stdLibPath: stdLibPath,
23+
// libDynloadPath: libDynloadPath,
24+
// Py_Initialize: Py_Initialize,
25+
// PyEval_SaveThread: PyEval_SaveThread,
26+
// PyGILState_Ensure: PyGILState_Ensure,
27+
// PyGILState_Release: PyGILState_Release
28+
// )
29+
//
30+
// Task {
31+
// // All future task should run inside runPython.
32+
// try runPython {
33+
// let sys = Python.import("sys")
34+
// Logger.service.info("Python Version: \(sys.version_info.major).\(sys.version_info.minor)")
35+
// }
36+
// }
3737
}
3838

0 commit comments

Comments
 (0)