Skip to content

Commit 2b45904

Browse files
committed
Capture Linux dependency failures outside the Flutter runner
1 parent d365513 commit 2b45904

3 files changed

Lines changed: 53 additions & 9 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import 'dart:io';
2+
3+
import 'package:path/path.dart' as p;
4+
import 'package:serious_python_platform_interface/src/dart_bridge_ffi.dart';
5+
6+
// Run against the installed bundle without Flutter's handling of native stderr.
7+
// Like the app, this loads CPython through dart:ffi, rather than starting a
8+
// Python executable (which would expose its symbols globally).
9+
void main(List<String> args) {
10+
final bundle = p.absolute(args.single);
11+
final stdlib = Directory(bundle)
12+
.listSync()
13+
.whereType<Directory>()
14+
.singleWhere((d) => RegExp(r'^python3\.\d+$').hasMatch(p.basename(d.path)))
15+
.path;
16+
final paths = [p.join(bundle, 'site-packages'), stdlib];
17+
final bridge = DartBridge.open(p.join(bundle, 'lib', 'libdart_bridge.so'));
18+
final result = runPython(
19+
bridge: bridge,
20+
script: '''
21+
import sys
22+
print("Bundled Python:", sys.version, flush=True)
23+
print("Module paths:", sys.path, flush=True)
24+
from pydantic import BaseModel
25+
class Probe(BaseModel):
26+
value: int
27+
assert Probe.model_validate({"value": "42"}).value == 42
28+
print("Pydantic validation passed", flush=True)
29+
''',
30+
modulePaths: paths,
31+
environmentVariables: {
32+
'PYTHONHOME': bundle,
33+
'PYTHONPATH': paths.join(':'),
34+
'PYTHONUNBUFFERED': '1',
35+
'PYTHONNOUSERSITE': '1',
36+
},
37+
sync: true,
38+
);
39+
exit(result);
40+
}

‎.github/workflows/ci.yml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,10 @@ jobs:
548548
echo
549549
echo "=== Python stdlib dir ==="
550550
ls -d $DBG_DIR/python3.* 2>/dev/null | head -5
551+
echo "=== Bundled Python dependency probe ==="
552+
LD_LIBRARY_PATH="$PWD/$DBG_DIR/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" \
553+
dart --packages=.dart_tool/package_config.json \
554+
"$SCRIPTS/probe_linux_python.dart" "$DBG_DIR"
551555
publish:
552556
name: Publish to pub.dev
553557
needs:

‎src/serious_python/example/bridge_example/lib/main.dart‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,6 @@ void main() {
7575
BridgeExampleHandle._instance =
7676
BridgeExampleHandle._(control, echo);
7777

78-
// Fire-and-forget: Python's main.py blocks forever waiting for messages.
79-
// Awaiting SeriousPython.run() would deadlock the UI.
80-
unawaited(SeriousPython.run(
81-
environmentVariables: {
82-
_controlPortEnv: '${control.port}',
83-
_echoPortEnv: '${echo.port}',
84-
},
85-
));
86-
8778
runApp(const BridgeExampleApp());
8879
}
8980

@@ -104,6 +95,15 @@ class _BridgeExampleAppState extends State<BridgeExampleApp> {
10495
final handle = BridgeExampleHandle.instance;
10596
_controlSub = handle.controlBridge.messages.listen(_onControl);
10697

98+
// Subscribe before starting Python so even an immediate startup failure
99+
// reaches the test harness. main.py blocks forever, so don't await it.
100+
unawaited(SeriousPython.run(
101+
environmentVariables: {
102+
_controlPortEnv: '${handle.controlBridge.port}',
103+
_echoPortEnv: '${handle.echoBridge.port}',
104+
},
105+
));
106+
107107
// Request the Python version once Python has had a moment to register
108108
// its handler. sendControl() retries internally if the handler isn't
109109
// ready yet, so we can fire immediately.

0 commit comments

Comments
 (0)