From 12b520cce34e7dba378d5c6d351e705d91badb7c Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Mon, 1 Dec 2025 11:53:40 -0800 Subject: [PATCH 1/8] Fixed iOS framework identifier generation and bump `archive` dependency (#185) * Fix leading dash in framework identifier generation Ensures that any leading dashes are removed from the generated framework identifier in xcframework_utils.sh. Defaults to 'framework' if the identifier is empty after processing. * Update CFBundlePackageType to FMWK in plist generation Changed the CFBundlePackageType from 'APPL' to 'FMWK' in the create_plist function to correctly identify the bundle as a framework. Also made a minor whitespace adjustment in create_xcframework_from_dylibs. * Bump `archive` dependency to `^4.0.7` (#184) * update `archive` dependency to ``^4.0.7` and bump serious_python version to `0.9.5` * revert flutter_lints dependency to version 2.0.0 * Bump version to 0.9.5 for Android and Darwin Updated the version number to 0.9.5 in both the Android build.gradle and Darwin podspec files to prepare for a new release. --------- Co-authored-by: Feodor Fitsner * Update changelogs for iOS framework identifier fix Added notes to all package changelogs for version 0.9.5 about the fix for iOS framework identifier generation. --------- Co-authored-by: TheEthicalBoy <98978078+ndonkoHenri@users.noreply.github.com> --- src/serious_python/CHANGELOG.md | 5 +++++ src/serious_python/pubspec.yaml | 4 ++-- src/serious_python_android/CHANGELOG.md | 5 +++++ src/serious_python_android/android/build.gradle | 2 +- src/serious_python_android/pubspec.yaml | 2 +- .../darwin/serious_python_darwin.podspec | 2 +- src/serious_python_darwin/darwin/xcframework_utils.sh | 6 +++++- src/serious_python_darwin/pubspec.yaml | 2 +- src/serious_python_linux/CHANGELOG.md | 5 +++++ src/serious_python_linux/pubspec.yaml | 2 +- src/serious_python_platform_interface/CHANGELOG.md | 5 +++++ src/serious_python_platform_interface/lib/src/utils.dart | 4 ++-- src/serious_python_platform_interface/pubspec.yaml | 2 +- src/serious_python_windows/CHANGELOG.md | 5 +++++ src/serious_python_windows/pubspec.yaml | 2 +- 15 files changed, 41 insertions(+), 12 deletions(-) diff --git a/src/serious_python/CHANGELOG.md b/src/serious_python/CHANGELOG.md index 614940aa..4791e9d0 100644 --- a/src/serious_python/CHANGELOG.md +++ b/src/serious_python/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.9.5 + +* Bump `archive` to `^4.0.7`. +* Fixed iOS framework identifier generation. + ## 0.9.4 * 16 KB memory page support for Android 15+ (by [@ReYaNOW](https://github.com/ReYaNOW)). diff --git a/src/serious_python/pubspec.yaml b/src/serious_python/pubspec.yaml index 732cee5f..640186fb 100644 --- a/src/serious_python/pubspec.yaml +++ b/src/serious_python/pubspec.yaml @@ -2,7 +2,7 @@ name: serious_python description: A cross-platform plugin for adding embedded Python runtime to your Flutter apps. homepage: https://flet.dev repository: https://github.com/flet-dev/serious-python -version: 0.9.4 +version: 0.9.5 platforms: ios: @@ -44,7 +44,7 @@ dependencies: path: ../serious_python_linux path_provider: ^2.1.3 - archive: ^3.6.1 + archive: ^4.0.7 path: ^1.9.0 args: ^2.5.0 toml: ^0.15.0 diff --git a/src/serious_python_android/CHANGELOG.md b/src/serious_python_android/CHANGELOG.md index 658f9f8d..89c435fa 100644 --- a/src/serious_python_android/CHANGELOG.md +++ b/src/serious_python_android/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.9.5 + +* Bump `archive` to `^4.0.7`. +* Fixed iOS framework identifier generation. + ## 0.9.4 * 16 KB memory page support for Android 15+ (by [@ReYaNOW](https://github.com/ReYaNOW)). diff --git a/src/serious_python_android/android/build.gradle b/src/serious_python_android/android/build.gradle index 35d43607..39d1f4d3 100644 --- a/src/serious_python_android/android/build.gradle +++ b/src/serious_python_android/android/build.gradle @@ -1,5 +1,5 @@ group 'com.flet.serious_python_android' -version '0.9.4' +version '0.9.5' def python_version = '3.12' diff --git a/src/serious_python_android/pubspec.yaml b/src/serious_python_android/pubspec.yaml index 90adfe9c..d0291a00 100644 --- a/src/serious_python_android/pubspec.yaml +++ b/src/serious_python_android/pubspec.yaml @@ -2,7 +2,7 @@ name: serious_python_android description: Android implementation of the serious_python plugin homepage: https://flet.dev repository: https://github.com/flet-dev/serious-python -version: 0.9.4 +version: 0.9.5 environment: sdk: ">=3.0.0 <4.0.0" diff --git a/src/serious_python_darwin/darwin/serious_python_darwin.podspec b/src/serious_python_darwin/darwin/serious_python_darwin.podspec index 05f0de51..5993eac2 100644 --- a/src/serious_python_darwin/darwin/serious_python_darwin.podspec +++ b/src/serious_python_darwin/darwin/serious_python_darwin.podspec @@ -4,7 +4,7 @@ # Pod::Spec.new do |s| s.name = 'serious_python_darwin' - s.version = '0.9.4' + s.version = '0.9.5' s.summary = 'A cross-platform plugin for adding embedded Python runtime to your Flutter apps.' s.description = <<-DESC A cross-platform plugin for adding embedded Python runtime to your Flutter apps. diff --git a/src/serious_python_darwin/darwin/xcframework_utils.sh b/src/serious_python_darwin/darwin/xcframework_utils.sh index 14ab4373..87447b4a 100644 --- a/src/serious_python_darwin/darwin/xcframework_utils.sh +++ b/src/serious_python_darwin/darwin/xcframework_utils.sh @@ -23,7 +23,7 @@ create_plist() { CFBundleInfoDictionaryVersion 6.0 CFBundlePackageType - APPL + FMWK CFBundleShortVersionString 1.0 CFBundleSupportedPlatforms @@ -55,6 +55,10 @@ create_xcframework_from_dylibs() { dylib_without_ext=$(echo $dylib_relative_path | cut -d "." -f 1) framework=$(echo $dylib_without_ext | tr "/" ".") framework_identifier=${framework//_/-} + while [[ $framework_identifier == -* ]]; do + framework_identifier=${framework_identifier#-} + done + framework_identifier=${framework_identifier:-framework} # creating "iphoneos" framework fd=iphoneos/$framework.framework diff --git a/src/serious_python_darwin/pubspec.yaml b/src/serious_python_darwin/pubspec.yaml index 655f04c3..284f47c1 100644 --- a/src/serious_python_darwin/pubspec.yaml +++ b/src/serious_python_darwin/pubspec.yaml @@ -2,7 +2,7 @@ name: serious_python_darwin description: iOS and macOS implementations of the serious_python plugin homepage: https://flet.dev repository: https://github.com/flet-dev/serious-python -version: 0.9.4 +version: 0.9.5 environment: sdk: ">=3.0.0 <4.0.0" diff --git a/src/serious_python_linux/CHANGELOG.md b/src/serious_python_linux/CHANGELOG.md index 0f06bba1..269bbc1f 100644 --- a/src/serious_python_linux/CHANGELOG.md +++ b/src/serious_python_linux/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.9.5 + +* Bump `archive` to `^4.0.7`. +* Fixed iOS framework identifier generation. + ## 0.9.4 * 16 KB memory page support for Android 15+ (by [@ReYaNOW](https://github.com/ReYaNOW)). diff --git a/src/serious_python_linux/pubspec.yaml b/src/serious_python_linux/pubspec.yaml index b2b22e82..47f3a8f3 100644 --- a/src/serious_python_linux/pubspec.yaml +++ b/src/serious_python_linux/pubspec.yaml @@ -2,7 +2,7 @@ name: serious_python_linux description: Linux implementations of the serious_python plugin homepage: https://flet.dev repository: https://github.com/flet-dev/serious-python -version: 0.9.4 +version: 0.9.5 environment: sdk: '>=3.1.3 <4.0.0' diff --git a/src/serious_python_platform_interface/CHANGELOG.md b/src/serious_python_platform_interface/CHANGELOG.md index bb1ffc8f..54670e7d 100644 --- a/src/serious_python_platform_interface/CHANGELOG.md +++ b/src/serious_python_platform_interface/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.9.5 + +* Bump `archive` to `^4.0.7`. +* Fixed iOS framework identifier generation. + ## 0.9.4 * 16 KB memory page support for Android 15+ (by [@ReYaNOW](https://github.com/ReYaNOW)). diff --git a/src/serious_python_platform_interface/lib/src/utils.dart b/src/serious_python_platform_interface/lib/src/utils.dart index e364c4e3..a45e7f34 100644 --- a/src/serious_python_platform_interface/lib/src/utils.dart +++ b/src/serious_python_platform_interface/lib/src/utils.dart @@ -60,9 +60,9 @@ Future extractAssetOrFile(String path, archive = ZipDecoder().decodeBytes(data); } else { final inputStream = InputFileStream(path); - archive = ZipDecoder().decodeBuffer(inputStream); + archive = ZipDecoder().decodeStream(inputStream); } - await extractArchiveToDiskAsync(archive, destDir.path, asyncWrite: true); + await extractArchiveToDisk(archive, destDir.path); } catch (e) { debugPrint("Error unpacking archive: $e"); await destDir.delete(recursive: true); diff --git a/src/serious_python_platform_interface/pubspec.yaml b/src/serious_python_platform_interface/pubspec.yaml index a5428de2..d75fe903 100644 --- a/src/serious_python_platform_interface/pubspec.yaml +++ b/src/serious_python_platform_interface/pubspec.yaml @@ -13,7 +13,7 @@ dependencies: sdk: flutter plugin_platform_interface: ^2.1.8 path_provider: ^2.1.3 - archive: ^3.6.1 + archive: ^4.0.7 path: ^1.9.0 dev_dependencies: diff --git a/src/serious_python_windows/CHANGELOG.md b/src/serious_python_windows/CHANGELOG.md index a29364f5..09e5bf91 100644 --- a/src/serious_python_windows/CHANGELOG.md +++ b/src/serious_python_windows/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.9.5 + +* Bump `archive` to `^4.0.7`. +* Fixed iOS framework identifier generation. + ## 0.9.4 * 16 KB memory page support for Android 15+ (by [@ReYaNOW](https://github.com/ReYaNOW)). diff --git a/src/serious_python_windows/pubspec.yaml b/src/serious_python_windows/pubspec.yaml index 823f9799..138323dc 100644 --- a/src/serious_python_windows/pubspec.yaml +++ b/src/serious_python_windows/pubspec.yaml @@ -2,7 +2,7 @@ name: serious_python_windows description: Windows implementations of the serious_python plugin homepage: https://flet.dev repository: https://github.com/flet-dev/serious-python -version: 0.9.4 +version: 0.9.5 environment: sdk: '>=3.1.3 <4.0.0' From 7060029bf47c175e1cd185b1066b0057e80fd2ec Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Mon, 1 Dec 2025 14:01:32 -0800 Subject: [PATCH 2/8] Fix zip directory (#186) * Make zipDirectory call asynchronous Added 'await' to the zipDirectory method to ensure the archive creation completes before proceeding. This change improves reliability when creating app archives. * Bump to 0.9.6 and make zipDirectory asynchronous Updated all platform packages to version 0.9.6. The zipDirectory call is now asynchronous across all implementations for improved performance and consistency. --- src/serious_python/CHANGELOG.md | 4 ++++ src/serious_python/bin/package_command.dart | 2 +- src/serious_python/pubspec.yaml | 2 +- src/serious_python_android/CHANGELOG.md | 4 ++++ src/serious_python_android/android/build.gradle | 4 ++-- src/serious_python_android/pubspec.yaml | 2 +- src/serious_python_darwin/CHANGELOG.md | 9 +++++++++ .../darwin/serious_python_darwin.podspec | 2 +- src/serious_python_darwin/pubspec.yaml | 2 +- src/serious_python_linux/CHANGELOG.md | 4 ++++ src/serious_python_linux/pubspec.yaml | 2 +- src/serious_python_platform_interface/CHANGELOG.md | 4 ++++ src/serious_python_platform_interface/pubspec.yaml | 2 +- src/serious_python_windows/CHANGELOG.md | 4 ++++ src/serious_python_windows/pubspec.yaml | 2 +- 15 files changed, 39 insertions(+), 10 deletions(-) diff --git a/src/serious_python/CHANGELOG.md b/src/serious_python/CHANGELOG.md index 4791e9d0..e0941792 100644 --- a/src/serious_python/CHANGELOG.md +++ b/src/serious_python/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.9.6 + +* Make zipDirectory call asynchronous. + ## 0.9.5 * Bump `archive` to `^4.0.7`. diff --git a/src/serious_python/bin/package_command.dart b/src/serious_python/bin/package_command.dart index f7596bb9..514e54ca 100644 --- a/src/serious_python/bin/package_command.dart +++ b/src/serious_python/bin/package_command.dart @@ -433,7 +433,7 @@ class PackageCommand extends Command { stdout.writeln( "Creating app archive at ${dest.path} from a temp directory"); final encoder = ZipFileEncoder(); - encoder.zipDirectory(tempDir, filename: dest.path); + await encoder.zipDirectory(tempDir, filename: dest.path); // create hash file stdout.writeln("Writing app archive hash to ${dest.path}.hash"); diff --git a/src/serious_python/pubspec.yaml b/src/serious_python/pubspec.yaml index 640186fb..9b5bc1d5 100644 --- a/src/serious_python/pubspec.yaml +++ b/src/serious_python/pubspec.yaml @@ -2,7 +2,7 @@ name: serious_python description: A cross-platform plugin for adding embedded Python runtime to your Flutter apps. homepage: https://flet.dev repository: https://github.com/flet-dev/serious-python -version: 0.9.5 +version: 0.9.6 platforms: ios: diff --git a/src/serious_python_android/CHANGELOG.md b/src/serious_python_android/CHANGELOG.md index 89c435fa..5d4c08f1 100644 --- a/src/serious_python_android/CHANGELOG.md +++ b/src/serious_python_android/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.9.6 + +* Make zipDirectory call asynchronous. + ## 0.9.5 * Bump `archive` to `^4.0.7`. diff --git a/src/serious_python_android/android/build.gradle b/src/serious_python_android/android/build.gradle index 39d1f4d3..d4bc782d 100644 --- a/src/serious_python_android/android/build.gradle +++ b/src/serious_python_android/android/build.gradle @@ -1,6 +1,6 @@ group 'com.flet.serious_python_android' -version '0.9.5' - +version '0.9.6' + def python_version = '3.12' buildscript { diff --git a/src/serious_python_android/pubspec.yaml b/src/serious_python_android/pubspec.yaml index d0291a00..d0eae473 100644 --- a/src/serious_python_android/pubspec.yaml +++ b/src/serious_python_android/pubspec.yaml @@ -2,7 +2,7 @@ name: serious_python_android description: Android implementation of the serious_python plugin homepage: https://flet.dev repository: https://github.com/flet-dev/serious-python -version: 0.9.5 +version: 0.9.6 environment: sdk: ">=3.0.0 <4.0.0" diff --git a/src/serious_python_darwin/CHANGELOG.md b/src/serious_python_darwin/CHANGELOG.md index 330b8328..ef480644 100644 --- a/src/serious_python_darwin/CHANGELOG.md +++ b/src/serious_python_darwin/CHANGELOG.md @@ -1,3 +1,12 @@ +## 0.9.6 + +* Make zipDirectory call asynchronous. + +## 0.9.5 + +* Bump `archive` to `^4.0.7`. +* Fixed iOS framework identifier generation. + ## 0.9.4 * 16 KB memory page support for Android 15+ (by [@ReYaNOW](https://github.com/ReYaNOW)). diff --git a/src/serious_python_darwin/darwin/serious_python_darwin.podspec b/src/serious_python_darwin/darwin/serious_python_darwin.podspec index 5993eac2..96771d89 100644 --- a/src/serious_python_darwin/darwin/serious_python_darwin.podspec +++ b/src/serious_python_darwin/darwin/serious_python_darwin.podspec @@ -4,7 +4,7 @@ # Pod::Spec.new do |s| s.name = 'serious_python_darwin' - s.version = '0.9.5' + s.version = '0.9.6' s.summary = 'A cross-platform plugin for adding embedded Python runtime to your Flutter apps.' s.description = <<-DESC A cross-platform plugin for adding embedded Python runtime to your Flutter apps. diff --git a/src/serious_python_darwin/pubspec.yaml b/src/serious_python_darwin/pubspec.yaml index 284f47c1..a7527666 100644 --- a/src/serious_python_darwin/pubspec.yaml +++ b/src/serious_python_darwin/pubspec.yaml @@ -2,7 +2,7 @@ name: serious_python_darwin description: iOS and macOS implementations of the serious_python plugin homepage: https://flet.dev repository: https://github.com/flet-dev/serious-python -version: 0.9.5 +version: 0.9.6 environment: sdk: ">=3.0.0 <4.0.0" diff --git a/src/serious_python_linux/CHANGELOG.md b/src/serious_python_linux/CHANGELOG.md index 269bbc1f..49f50392 100644 --- a/src/serious_python_linux/CHANGELOG.md +++ b/src/serious_python_linux/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.9.6 + +* Make zipDirectory call asynchronous. + ## 0.9.5 * Bump `archive` to `^4.0.7`. diff --git a/src/serious_python_linux/pubspec.yaml b/src/serious_python_linux/pubspec.yaml index 47f3a8f3..7b9a2aa6 100644 --- a/src/serious_python_linux/pubspec.yaml +++ b/src/serious_python_linux/pubspec.yaml @@ -2,7 +2,7 @@ name: serious_python_linux description: Linux implementations of the serious_python plugin homepage: https://flet.dev repository: https://github.com/flet-dev/serious-python -version: 0.9.5 +version: 0.9.6 environment: sdk: '>=3.1.3 <4.0.0' diff --git a/src/serious_python_platform_interface/CHANGELOG.md b/src/serious_python_platform_interface/CHANGELOG.md index 54670e7d..545a5e03 100644 --- a/src/serious_python_platform_interface/CHANGELOG.md +++ b/src/serious_python_platform_interface/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.9.6 + +* Make zipDirectory call asynchronous. + ## 0.9.5 * Bump `archive` to `^4.0.7`. diff --git a/src/serious_python_platform_interface/pubspec.yaml b/src/serious_python_platform_interface/pubspec.yaml index d75fe903..e8e59615 100644 --- a/src/serious_python_platform_interface/pubspec.yaml +++ b/src/serious_python_platform_interface/pubspec.yaml @@ -2,7 +2,7 @@ name: serious_python_platform_interface description: A common platform interface for the serious_python plugin. homepage: https://flet.dev repository: https://github.com/flet-dev/serious-python -version: 0.9.4 +version: 0.9.6 environment: sdk: ">=3.0.0 <4.0.0" diff --git a/src/serious_python_windows/CHANGELOG.md b/src/serious_python_windows/CHANGELOG.md index 09e5bf91..55054601 100644 --- a/src/serious_python_windows/CHANGELOG.md +++ b/src/serious_python_windows/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.9.6 + +* Make zipDirectory call asynchronous. + ## 0.9.5 * Bump `archive` to `^4.0.7`. diff --git a/src/serious_python_windows/pubspec.yaml b/src/serious_python_windows/pubspec.yaml index 138323dc..87798abd 100644 --- a/src/serious_python_windows/pubspec.yaml +++ b/src/serious_python_windows/pubspec.yaml @@ -2,7 +2,7 @@ name: serious_python_windows description: Windows implementations of the serious_python plugin homepage: https://flet.dev repository: https://github.com/flet-dev/serious-python -version: 0.9.5 +version: 0.9.6 environment: sdk: '>=3.1.3 <4.0.0' From 8d84d6f40c18a5a94a1b1d83834e6fc0b5ec6bdf Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Wed, 10 Dec 2025 13:03:17 -0800 Subject: [PATCH 3/8] Make setenv calls awaitable in Python init Refactored the setenv function to return a Future and updated all calls to setenv to use await. This ensures environment variables are set in the correct order before proceeding. --- .../lib/serious_python_android.dart | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/serious_python_android/lib/serious_python_android.dart b/src/serious_python_android/lib/serious_python_android.dart index a3e84dcf..5c4c7067 100644 --- a/src/serious_python_android/lib/serious_python_android.dart +++ b/src/serious_python_android/lib/serious_python_android.dart @@ -33,10 +33,9 @@ class SeriousPythonAndroid extends SeriousPythonPlatform { List? modulePaths, Map? environmentVariables, bool? sync}) async { - Future setenv(String key, String value) async { - await methodChannel.invokeMethod( - 'setEnvironmentVariable', {'name': key, 'value': value}); - } + Future setenv(String key, String value) => + methodChannel.invokeMethod( + 'setEnvironmentVariable', {'name': key, 'value': value}); // load libpyjni.so to get JNI reference try { @@ -78,18 +77,18 @@ class SeriousPythonAndroid extends SeriousPythonPlatform { moduleSearchPaths.add(sitePackagesPath); } - setenv("PYTHONINSPECT", "1"); - setenv("PYTHONDONTWRITEBYTECODE", "1"); - setenv("PYTHONNOUSERSITE", "1"); - setenv("PYTHONUNBUFFERED", "1"); - setenv("LC_CTYPE", "UTF-8"); - setenv("PYTHONHOME", pythonLibPath); - setenv("PYTHONPATH", moduleSearchPaths.join(":")); + await setenv("PYTHONINSPECT", "1"); + await setenv("PYTHONDONTWRITEBYTECODE", "1"); + await setenv("PYTHONNOUSERSITE", "1"); + await setenv("PYTHONUNBUFFERED", "1"); + await setenv("LC_CTYPE", "UTF-8"); + await setenv("PYTHONHOME", pythonLibPath); + await setenv("PYTHONPATH", moduleSearchPaths.join(":")); // set environment variables if (environmentVariables != null) { for (var v in environmentVariables.entries) { - setenv(v.key, v.value); + await setenv(v.key, v.value); } } From 3f4adc08b82147a46452b19d2a29d6af715a58a0 Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Wed, 10 Dec 2025 17:30:57 -0800 Subject: [PATCH 4/8] Ensure single CPython interpreter per process Introduces a guard to prevent repeated initialization and finalization of the CPython interpreter, addressing crashes on second launch with CPython 3.12. Also ensures the current native thread is registered with the GIL when running Python code, improving stability when re-entering Python from new Dart isolates or threads. --- .../lib/src/cpython.dart | 57 ++++++++++++------- 1 file changed, 35 insertions(+), 22 deletions(-) diff --git a/src/serious_python_android/lib/src/cpython.dart b/src/serious_python_android/lib/src/cpython.dart index 441ad98e..6e18e542 100644 --- a/src/serious_python_android/lib/src/cpython.dart +++ b/src/serious_python_android/lib/src/cpython.dart @@ -11,6 +11,9 @@ import 'gen.dart'; export 'gen.dart'; CPython? _cpython; +// Keep a single interpreter per process; repeated init/finalize of CPython 3.12 +// from an embedder is fragile and was crashing on second launch. +bool _pythonInitialized = false; CPython getCPython(String dynamicLibPath) { return _cpython ??= _cpython = CPython(DynamicLibrary.open(dynamicLibPath)); @@ -51,33 +54,43 @@ Future runPythonProgramInIsolate(List arguments) async { debugPrint("programModuleName: $programModuleName"); final cpython = getCPython(dynamicLibPath); - cpython.Py_Initialize(); - debugPrint("after Py_Initialize()"); + if (!_pythonInitialized) { + cpython.Py_Initialize(); + _pythonInitialized = true; + debugPrint("after Py_Initialize()"); + } else { + debugPrint("Python already initialized; reusing interpreter"); + } var result = ""; - - if (script != "") { - // run script - final scriptPtr = script.toNativeUtf8(); - int sr = cpython.PyRun_SimpleString(scriptPtr.cast()); - debugPrint("PyRun_SimpleString for script result: $sr"); - malloc.free(scriptPtr); - if (sr != 0) { - result = getPythonError(cpython); - } - } else { - // run program - final moduleNamePtr = programModuleName.toNativeUtf8(); - var modulePtr = cpython.PyImport_ImportModule(moduleNamePtr.cast()); - if (modulePtr == nullptr) { - result = getPythonError(cpython); + // Ensure the current native thread is registered with the GIL; this is + // required if we re-enter Python from a new Dart isolate/thread. + final gilState = cpython.PyGILState_Ensure(); + + try { + if (script != "") { + // run script + final scriptPtr = script.toNativeUtf8(); + int sr = cpython.PyRun_SimpleString(scriptPtr.cast()); + debugPrint("PyRun_SimpleString for script result: $sr"); + malloc.free(scriptPtr); + if (sr != 0) { + result = getPythonError(cpython); + } + } else { + // run program + final moduleNamePtr = programModuleName.toNativeUtf8(); + var modulePtr = + cpython.PyImport_ImportModule(moduleNamePtr.cast()); + if (modulePtr == nullptr) { + result = getPythonError(cpython); + } + malloc.free(moduleNamePtr); } - malloc.free(moduleNamePtr); + } finally { + cpython.PyGILState_Release(gilState); } - cpython.Py_Finalize(); - debugPrint("after Py_Finalize()"); - sendPort.send(result); return result; From f31ee2b2dec396553cdaafc8cd49274c9064263f Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Wed, 10 Dec 2025 17:36:38 -0800 Subject: [PATCH 5/8] Remove 'Warning:' prefix from debug message Updated the debugPrint statement to remove the 'Warning:' prefix when unable to load libpyjni.so. This change streamlines log output for consistency. --- src/serious_python_android/lib/serious_python_android.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/serious_python_android/lib/serious_python_android.dart b/src/serious_python_android/lib/serious_python_android.dart index 5c4c7067..0ec59840 100644 --- a/src/serious_python_android/lib/serious_python_android.dart +++ b/src/serious_python_android/lib/serious_python_android.dart @@ -43,7 +43,7 @@ class SeriousPythonAndroid extends SeriousPythonPlatform { .invokeMethod('loadLibrary', {'libname': 'pyjni'}); await setenv("FLET_JNI_READY", "1"); } catch (e) { - debugPrint("Warning: Unable to load libpyjni.so library: $e"); + debugPrint("Unable to load libpyjni.so library: $e"); } // unpack python bundle From e3e46f92ef8c4155acf851240e3c84d139388c7d Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Wed, 10 Dec 2025 23:04:43 -0800 Subject: [PATCH 6/8] Revert "Ensure single CPython interpreter per process" This reverts commit 3f4adc08b82147a46452b19d2a29d6af715a58a0. --- .../lib/src/cpython.dart | 57 +++++++------------ 1 file changed, 22 insertions(+), 35 deletions(-) diff --git a/src/serious_python_android/lib/src/cpython.dart b/src/serious_python_android/lib/src/cpython.dart index 6e18e542..441ad98e 100644 --- a/src/serious_python_android/lib/src/cpython.dart +++ b/src/serious_python_android/lib/src/cpython.dart @@ -11,9 +11,6 @@ import 'gen.dart'; export 'gen.dart'; CPython? _cpython; -// Keep a single interpreter per process; repeated init/finalize of CPython 3.12 -// from an embedder is fragile and was crashing on second launch. -bool _pythonInitialized = false; CPython getCPython(String dynamicLibPath) { return _cpython ??= _cpython = CPython(DynamicLibrary.open(dynamicLibPath)); @@ -54,43 +51,33 @@ Future runPythonProgramInIsolate(List arguments) async { debugPrint("programModuleName: $programModuleName"); final cpython = getCPython(dynamicLibPath); - if (!_pythonInitialized) { - cpython.Py_Initialize(); - _pythonInitialized = true; - debugPrint("after Py_Initialize()"); - } else { - debugPrint("Python already initialized; reusing interpreter"); - } + cpython.Py_Initialize(); + debugPrint("after Py_Initialize()"); var result = ""; - // Ensure the current native thread is registered with the GIL; this is - // required if we re-enter Python from a new Dart isolate/thread. - final gilState = cpython.PyGILState_Ensure(); - - try { - if (script != "") { - // run script - final scriptPtr = script.toNativeUtf8(); - int sr = cpython.PyRun_SimpleString(scriptPtr.cast()); - debugPrint("PyRun_SimpleString for script result: $sr"); - malloc.free(scriptPtr); - if (sr != 0) { - result = getPythonError(cpython); - } - } else { - // run program - final moduleNamePtr = programModuleName.toNativeUtf8(); - var modulePtr = - cpython.PyImport_ImportModule(moduleNamePtr.cast()); - if (modulePtr == nullptr) { - result = getPythonError(cpython); - } - malloc.free(moduleNamePtr); + + if (script != "") { + // run script + final scriptPtr = script.toNativeUtf8(); + int sr = cpython.PyRun_SimpleString(scriptPtr.cast()); + debugPrint("PyRun_SimpleString for script result: $sr"); + malloc.free(scriptPtr); + if (sr != 0) { + result = getPythonError(cpython); + } + } else { + // run program + final moduleNamePtr = programModuleName.toNativeUtf8(); + var modulePtr = cpython.PyImport_ImportModule(moduleNamePtr.cast()); + if (modulePtr == nullptr) { + result = getPythonError(cpython); } - } finally { - cpython.PyGILState_Release(gilState); + malloc.free(moduleNamePtr); } + cpython.Py_Finalize(); + debugPrint("after Py_Finalize()"); + sendPort.send(result); return result; From 6a1181c7bca88c367c5376e52f425c794bd49e37 Mon Sep 17 00:00:00 2001 From: Creeper19472 Date: Fri, 12 Dec 2025 18:20:12 +0800 Subject: [PATCH 7/8] chore: bump python version to 3.14.2 --- src/serious_python/bin/package_command.dart | 4 ++-- src/serious_python_android/android/build.gradle | 2 +- src/serious_python_android/lib/src/gen.dart | 8 ++++---- src/serious_python_android/python_ffigen.yaml | 8 ++++---- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/serious_python/bin/package_command.dart b/src/serious_python/bin/package_command.dart index 9b392da5..e846fa24 100644 --- a/src/serious_python/bin/package_command.dart +++ b/src/serious_python/bin/package_command.dart @@ -18,8 +18,8 @@ const mobilePyPiUrl = "https://pypi.flet.dev"; const pyodideRootUrl = "https://cdn.jsdelivr.net/pyodide/v0.27.7/full"; const pyodideLockFile = "pyodide-lock.json"; -const buildPythonVersion = "3.14.0"; -const buildPythonReleaseDate = "20251007"; +const buildPythonVersion = "3.14.2"; +const buildPythonReleaseDate = "20251209"; const defaultSitePackagesDir = "__pypackages__"; const sitePackagesEnvironmentVariable = "SERIOUS_PYTHON_SITE_PACKAGES"; const flutterPackagesFlutterEnvironmentVariable = diff --git a/src/serious_python_android/android/build.gradle b/src/serious_python_android/android/build.gradle index 40df61f3..7172bfe4 100644 --- a/src/serious_python_android/android/build.gradle +++ b/src/serious_python_android/android/build.gradle @@ -1,7 +1,7 @@ group 'com.flet.serious_python_android' version '0.9.6' -def python_version = '3.14' +def python_version = '3.14.2' buildscript { repositories { diff --git a/src/serious_python_android/lib/src/gen.dart b/src/serious_python_android/lib/src/gen.dart index 9d410f6e..e6132405 100644 --- a/src/serious_python_android/lib/src/gen.dart +++ b/src/serious_python_android/lib/src/gen.dart @@ -25758,17 +25758,17 @@ const int PY_RELEASE_LEVEL_FINAL = 15; const int PY_MAJOR_VERSION = 3; -const int PY_MINOR_VERSION = 12; +const int PY_MINOR_VERSION = 14; -const int PY_MICRO_VERSION = 3; +const int PY_MICRO_VERSION = 2; const int PY_RELEASE_LEVEL = 15; const int PY_RELEASE_SERIAL = 0; -const String PY_VERSION = '3.14.0'; +const String PY_VERSION = '3.14.2'; -const int PY_VERSION_HEX = 51249392; +const int PY_VERSION_HEX = 51249904; const int ALIGNOF_LONG = 8; diff --git a/src/serious_python_android/python_ffigen.yaml b/src/serious_python_android/python_ffigen.yaml index af1efb05..16eebff0 100644 --- a/src/serious_python_android/python_ffigen.yaml +++ b/src/serious_python_android/python_ffigen.yaml @@ -14,11 +14,11 @@ globals: "^class (\\w+) extends ffi.Union": "final class $1 extends ffi.Union" headers: entry-points: - - "/Users/feodor/projects/flet-dev/python-mobile/install/android/arm64-v8a/python-3.12/include/python3.12/Python.h" + - "/Users/feodor/projects/flet-dev/python-mobile/install/android/arm64-v8a/python-3.14/include/python3.14/Python.h" include-directives: - - "/Users/feodor/projects/flet-dev/python-mobile/install/android/arm64-v8a/python-3.12/include/python3.12/*" - - "/Users/feodor/projects/flet-dev/python-mobile/install/android/arm64-v8a/python-3.12/include/python3.12/internal/*" - - "/Users/feodor/projects/flet-dev/python-mobile/install/android/arm64-v8a/python-3.12/include/python3.12/cpython/*" + - "/Users/feodor/projects/flet-dev/python-mobile/install/android/arm64-v8a/python-3.14/include/python3.14/*" + - "/Users/feodor/projects/flet-dev/python-mobile/install/android/arm64-v8a/python-3.14/include/python3.14/internal/*" + - "/Users/feodor/projects/flet-dev/python-mobile/install/android/arm64-v8a/python-3.14/include/python3.14/cpython/*" name: "CPython" llvm-path: - /opt/homebrew/opt/llvm From 16a0ece18f0aac9bc15dca695cd781f1d2dfe33d Mon Sep 17 00:00:00 2001 From: Creeper19472 Date: Mon, 22 Dec 2025 18:25:26 +0800 Subject: [PATCH 8/8] fix python-windows-dart package name --- src/serious_python_android/lib/src/gen.dart | 2 +- src/serious_python_windows/windows/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/serious_python_android/lib/src/gen.dart b/src/serious_python_android/lib/src/gen.dart index e6132405..b0d4458c 100644 --- a/src/serious_python_android/lib/src/gen.dart +++ b/src/serious_python_android/lib/src/gen.dart @@ -25776,7 +25776,7 @@ const int ALIGNOF_MAX_ALIGN_T = 8; const int ALIGNOF_SIZE_T = 8; -const int ANDROID_API_LEVEL = 21; +const int ANDROID_API_LEVEL = 24; const int ENABLE_IPV6 = 1; diff --git a/src/serious_python_windows/windows/CMakeLists.txt b/src/serious_python_windows/windows/CMakeLists.txt index 212b3299..9c9b334f 100644 --- a/src/serious_python_windows/windows/CMakeLists.txt +++ b/src/serious_python_windows/windows/CMakeLists.txt @@ -18,7 +18,7 @@ cmake_policy(SET CMP0063 NEW) set(PLUGIN_NAME "serious_python_windows_plugin") set(PYTHON_PACKAGE ${CMAKE_BINARY_DIR}/python) -set(PYTHON_URL "https://github.com/cfms-dev/python-build/releases/download/v3.14/python-windows-for-dart-3.14.zip") +set(PYTHON_URL "https://github.com/cfms-dev/python-build/releases/download/v3.14.2/python-windows-for-dart-3.14.2.zip") set(PYTHON_FILE ${CMAKE_BINARY_DIR}/python-windows-for-dart.zip) if (NOT EXISTS ${PYTHON_FILE}) file(DOWNLOAD ${PYTHON_URL} ${PYTHON_FILE})