Skip to content

Commit c74cf39

Browse files
Add Python output/logging to troubleshoot empty screens on startup of built app (#58)
* Get all output and errors from a python program * More responsive template for Flutter Flet app * Added support for wrapping script * Script running for Windows * Update main.dart * Update main.py * PyRun_SimpleString for Windows * Add web support to flet_example * PyRun_SimpleString in Linux * Simulating error in python script * Fix main.dart for Windows * Fix python app * Use random TCP ports on Windows * Catch exit code * Disable buffering when redirecting output * pyproject.toml support * Added sample pyproject.toml * Handle/bypass if __name__ == "__main__" check * Added SSL config to a template * Version bumped to 0.7.0 * Create _posixsubprocess.py * Fix flet_example
1 parent 0b62af8 commit c74cf39

38 files changed

+627
-167
lines changed

src/serious_python/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 0.7.0
2+
3+
* `runPython()` method to support running Python script.
4+
* Updated `flet_example` to catch program output and errors, `sys.exit()` support.
5+
* `package` command to read dependencies from `pyproject.toml`.
6+
17
## 0.6.1
28

39
* `--exclude` option for `package` command - to exclude directories and files from Python app package.

src/serious_python/bin/package_command.dart

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const webJunkFileExtensions = [
2626
".dll"
2727
];
2828
const junkFilesAndDirectories = ["__pycache__", "bin"];
29+
const tomlIgnoredDeps = ["python"];
2930

3031
class PackageCommand extends Command {
3132
bool _verbose = false;
@@ -158,10 +159,42 @@ class PackageCommand extends Command {
158159
if (depSection is List) {
159160
dependencies = depSection.map((e) => e.toString()).toList();
160161
} else {
161-
stdout.writeln(
162-
"Warning: [dependencies] section of map type is not yet supported.");
163-
// dependencies = List<String>.from(
164-
// depSection.keys.map((key) => '$key=${depSection[key]}'));
162+
dependencies = List<String>.from(depSection.keys.map((key) {
163+
if (tomlIgnoredDeps.contains(key)) {
164+
return "";
165+
}
166+
var value = depSection[key];
167+
var version = "";
168+
var suffix = "";
169+
if (value is Map) {
170+
version = value["version"];
171+
if (value["python"] != null) {
172+
suffix = ";python_version=='${value["python"]}'"
173+
.replaceAll("=='^", ">='")
174+
.replaceAll("=='~", "~='")
175+
.replaceAll("=='<", "<'")
176+
.replaceAll("=='>", ">'")
177+
.replaceAll("=='<=", "<='")
178+
.replaceAll("=='>=", ">='");
179+
} else if (value["markers"] != null) {
180+
suffix = ";${value["markers"]}";
181+
}
182+
} else if (value is String) {
183+
version = value;
184+
}
185+
var sep = "==";
186+
if (version.startsWith("^")) {
187+
sep = ">=";
188+
version = version.replaceAll("^", "");
189+
} else if (version.startsWith("~")) {
190+
sep = "~=";
191+
version = version.replaceAll("~", "");
192+
} else if (version.contains(">") || version.contains("<")) {
193+
sep = "";
194+
version = version.replaceAll(" ", "");
195+
}
196+
return "$key$sep$version$suffix";
197+
})).where((s) => s != "").toList();
165198
}
166199
}
167200
}
@@ -177,7 +210,8 @@ class PackageCommand extends Command {
177210
exit(3);
178211
}
179212
dependencies = dependencies
180-
.map((d) => d.replaceAllMapped(RegExp(mapping[0] + r'(\W{1,}|$)'),
213+
.map((d) => d.replaceAllMapped(
214+
RegExp(mapping[0] + r'([><=]{1,}|$)'),
181215
(match) => '${mapping[1]}${match.group(1)}'))
182216
.toList();
183217
}
@@ -199,6 +233,9 @@ class PackageCommand extends Command {
199233
}
200234
}
201235

236+
// stdout.writeln(dependencies);
237+
// exit(1);
238+
202239
List<String> extraArgs = [];
203240
if (pre) {
204241
extraArgs.add("--pre");

src/serious_python/example/flask_example/macos/Podfile.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ PODS:
55
- path_provider_foundation (0.0.1):
66
- Flutter
77
- FlutterMacOS
8-
- serious_python_darwin (0.6.1):
8+
- serious_python_darwin (0.7.0):
99
- Flutter
1010
- FlutterMacOS
1111

@@ -29,8 +29,8 @@ SPEC CHECKSUMS:
2929
FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24
3030
package_info_plus: 02d7a575e80f194102bef286361c6c326e4c29ce
3131
path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943
32-
serious_python_darwin: 6deda6a52f401fcf7e9b9a83c3a9387a9c08d599
32+
serious_python_darwin: 0a8c46a529057f91064a327d9c4037e773eef339
3333

3434
PODFILE CHECKSUM: 9ebaf0ce3d369aaa26a9ea0e159195ed94724cf3
3535

36-
COCOAPODS: 1.12.1
36+
COCOAPODS: 1.14.3

src/serious_python/example/flask_example/pubspec.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,42 +302,42 @@ packages:
302302
path: "../.."
303303
relative: true
304304
source: path
305-
version: "0.6.1"
305+
version: "0.7.0"
306306
serious_python_android:
307307
dependency: transitive
308308
description:
309309
path: "../../../serious_python_android"
310310
relative: true
311311
source: path
312-
version: "0.6.1"
312+
version: "0.7.0"
313313
serious_python_darwin:
314314
dependency: transitive
315315
description:
316316
path: "../../../serious_python_darwin"
317317
relative: true
318318
source: path
319-
version: "0.6.1"
319+
version: "0.7.0"
320320
serious_python_linux:
321321
dependency: transitive
322322
description:
323323
path: "../../../serious_python_linux"
324324
relative: true
325325
source: path
326-
version: "0.6.1"
326+
version: "0.7.0"
327327
serious_python_platform_interface:
328328
dependency: transitive
329329
description:
330330
path: "../../../serious_python_platform_interface"
331331
relative: true
332332
source: path
333-
version: "0.6.1"
333+
version: "0.7.0"
334334
serious_python_windows:
335335
dependency: transitive
336336
description:
337337
path: "../../../serious_python_windows"
338338
relative: true
339339
source: path
340-
version: "0.6.1"
340+
version: "0.7.0"
341341
sky_engine:
342342
dependency: transitive
343343
description: flutter

src/serious_python/example/flet_example/app/src/main.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
import logging
2+
import sys
3+
import urllib.request
24

35
import flet as ft
46
from flet_core.version import version
57

6-
logging.basicConfig(level=logging.DEBUG)
8+
# logging.basicConfig(level=logging.DEBUG)
9+
10+
print("Hello from Python!")
11+
print(__name__)
12+
13+
# import aaa
714

815

916
def main(page: ft.Page):
@@ -13,13 +20,23 @@ def main(page: ft.Page):
1320
txt_number = ft.TextField(value="0", text_align=ft.TextAlign.RIGHT, width=100)
1421

1522
def minus_click(e):
23+
print("Clicked minus button")
1624
txt_number.value = str(int(txt_number.value) - 1)
1725
page.update()
1826

1927
def plus_click(e):
2028
txt_number.value = str(int(txt_number.value) + 1)
2129
page.update()
2230

31+
def check_ssl(e):
32+
try:
33+
with urllib.request.urlopen("https://google.com") as res:
34+
result = "OK"
35+
except Exception as ex:
36+
result = str(ex)
37+
page.show_dialog(ft.AlertDialog(content=ft.Text(result)))
38+
# print(result)
39+
2340
page.add(
2441
ft.Row(
2542
[
@@ -33,10 +50,18 @@ def plus_click(e):
3350
expand=True,
3451
),
3552
ft.Row(
36-
[ft.Text(f"Flet version: {version}")],
53+
[
54+
ft.Text(f"Flet version: {version}"),
55+
ft.OutlinedButton("Check SSL", on_click=check_ssl),
56+
ft.OutlinedButton("Exit app", on_click=lambda _: sys.exit(100)),
57+
],
58+
wrap=True,
3759
alignment=ft.MainAxisAlignment.CENTER,
3860
),
3961
)
4062

63+
print("This is inside main() method!")
64+
4165

42-
ft.app(main)
66+
if __name__ == "__main__":
67+
ft.app(main)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[tool.poetry]
2+
name = "my_project"
3+
version = "0.1.0"
4+
description = "My Project"
5+
authors = ["Author <[email protected]>"]
6+
license = "MIT"
7+
readme = "README.md"
8+
packages = [{include = "my_project"}]
9+
10+
[tool.poetry.dependencies]
11+
python = "^3.8"
12+
flet = "^0.18.0"
13+
flet-contrib = { "version" = "~2023.8.18", markers = "python_version <= '3.4' or sys_platform == 'win32'" }
14+
flask = { "version" = ">=2.2.5, <3.0", python = "^3.2" }
15+
16+
[tool.poetry.group.dev.dependencies]
17+
uvicorn = "^0.25.0"
18+
flet-fastapi = "^0.18.0"
19+
gunicorn = "^21.2.0"
20+
21+
[build-system]
22+
requires = ["poetry-core"]
23+
build-backend = "poetry.core.masonry.api"

src/serious_python/example/flet_example/ios/Podfile.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ PODS:
4848
- SDWebImage/Core (5.18.5)
4949
- sensors_plus (0.0.1):
5050
- Flutter
51-
- serious_python_darwin (0.6.0):
51+
- serious_python_darwin (0.7.0):
5252
- Flutter
5353
- FlutterMacOS
5454
- shared_preferences_foundation (0.0.1):
@@ -114,13 +114,13 @@ SPEC CHECKSUMS:
114114
package_info_plus: 115f4ad11e0698c8c1c5d8a689390df880f47e85
115115
path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943
116116
SDWebImage: 7ac2b7ddc5e8484c79aa90fc4e30b149d6a2c88f
117-
sensors_plus: 5717760720f7e6acd96fdbd75b7428f5ad755ec2
118-
serious_python_darwin: 0eaf3be753db71ab8f24d80644d5fb291f5968f0
117+
sensors_plus: 42b9de1b8237675fa8d8121e4bb93be0f79fa61d
118+
serious_python_darwin: 0a8c46a529057f91064a327d9c4037e773eef339
119119
shared_preferences_foundation: e2dae3258e06f44cc55f49d42024fd8dd03c590c
120120
SwiftyGif: 93a1cc87bf3a51916001cf8f3d63835fb64c819f
121121
url_launcher_ios: 08a3dfac5fb39e8759aeb0abbd5d9480f30fc8b4
122122
webview_flutter_wkwebview: 2e2d318f21a5e036e2c3f26171342e95908bd60a
123123

124124
PODFILE CHECKSUM: 7be2f5f74864d463a8ad433546ed1de7e0f29aef
125125

126-
COCOAPODS: 1.12.1
126+
COCOAPODS: 1.14.3

0 commit comments

Comments
 (0)