Skip to content

Commit 5a42c64

Browse files
flet build improvements (#2404)
* `flet build -vv` should run `pip install` with verbose output Close #2351 * `flet build` should raise an error when trying to package an app with native modules for iOS or Android Close #2356 * Generate app asset hash for more effective unpacking Close #2289 * Fix "OSError: [WinError 193] %1 is not a valid Win32 application" error on Windows Fix #2318 * Flet version bumped to 0.19.0 * Replace --windows-tcp-port with a random port
1 parent 1316222 commit 5a42c64

File tree

6 files changed

+87
-22
lines changed

6 files changed

+87
-22
lines changed

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
# Flet changelog
22

3+
# 0.19.0
4+
5+
* `flet build` to apply Python SSL fix when packaging for iOS and Android ([#2349](https://github.com/flet-dev/flet/issues/2349)).
6+
* Upgrade Android Gradle in flet `build app` template ([#2350](https://github.com/flet-dev/flet/issues/2350)).
7+
* `flet build -vv` should run pip install with verbose output ([#2351](https://github.com/flet-dev/flet/issues/2351)).
8+
* Add Python output/logging to troubleshoot empty screens on startup of built app ([#2352](https://github.com/flet-dev/flet/issues/2352)).
9+
* `flet build` should raise an error when trying to package an app with native modules for iOS or Android ([#2356](https://github.com/flet-dev/flet/issues/2356)).
10+
* `flet build` to add timestamp (hash) asset with Flet Python app to re-extract when code changes ([#2289](https://github.com/flet-dev/flet/issues/2289)).
11+
* Handle/bypass `if __name__ == "__main__"` check on Android.
12+
* Support reading dependencies from `pyproject.toml`.
13+
* `flet build` to fix `--base-url` with surrounding slashes ([#2369](https://github.com/flet-dev/flet/issues/2369)).
14+
* `CupertinoAlertDialog`, `CupertinoDialogAction`, adaptive property for `AlertDialog` ([#2365](https://github.com/flet-dev/flet/issues/2365)).
15+
* `Dismissible.confirmDismiss` prop ([#2359](https://github.com/flet-dev/flet/issues/2359)).
16+
* `ListView.reverse` and `GridView.reverse` props ([#2335](https://github.com/flet-dev/flet/issues/2335)).
17+
* `Text.style` type Deprecation warning ([#2286](https://github.com/flet-dev/flet/issues/2286)).
18+
* Add `LineChartData.prevent_curve_over_shooting` and `LineChartData.prevent_curve_over_shooting_threshold` props ([#2354](https://github.com/flet-dev/flet/issues/2354)).
19+
* `flet build` to add checks to allow certain build commands according to "build_on" platform ([#2343](https://github.com/flet-dev/flet/issues/2343)).
20+
* Fixed: `flet build` gives "OSError: [WinError 193] %1 is not a valid Win32 application" for some users ([#2318](https://github.com/flet-dev/flet/issues/2318)).
21+
* Fixed: PubSub is not shared between pages in the same FastAPI app ([#2368](https://github.com/flet-dev/flet/issues/2368)).
22+
* Fixed: check for `DISPLAY` instead of `XDG_CURRENT_DESKTOP` to check if linux machine is GUIless or not ([#2373](https://github.com/flet-dev/flet/issues/2373)).
23+
324
# 0.18.0
425

526
* `flet build` command to package Flet app for any platform ([docs](https://flet.dev/docs/guides/python/packaging-app-for-distribution)).

client/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ packages:
183183
path: "../package"
184184
relative: true
185185
source: path
186-
version: "0.18.0"
186+
version: "0.19.0"
187187
flutter:
188188
dependency: "direct main"
189189
description: flutter

package/CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
# 0.19.0
2+
3+
* `flet build` to apply Python SSL fix when packaging for iOS and Android ([#2349](https://github.com/flet-dev/flet/issues/2349)).
4+
* Upgrade Android Gradle in flet `build app` template ([#2350](https://github.com/flet-dev/flet/issues/2350)).
5+
* `flet build -vv` should run pip install with verbose output ([#2351](https://github.com/flet-dev/flet/issues/2351)).
6+
* Add Python output/logging to troubleshoot empty screens on startup of built app ([#2352](https://github.com/flet-dev/flet/issues/2352)).
7+
* `flet build` should raise an error when trying to package an app with native modules for iOS or Android ([#2356](https://github.com/flet-dev/flet/issues/2356)).
8+
* `flet build` to add timestamp (hash) asset with Flet Python app to re-extract when code changes ([#2289](https://github.com/flet-dev/flet/issues/2289)).
9+
* Handle/bypass `if __name__ == "__main__"` check on Android.
10+
* Support reading dependencies from `pyproject.toml`.
11+
* `flet build` to fix `--base-url` with surrounding slashes ([#2369](https://github.com/flet-dev/flet/issues/2369)).
12+
* `CupertinoAlertDialog`, `CupertinoDialogAction`, adaptive property for `AlertDialog` ([#2365](https://github.com/flet-dev/flet/issues/2365)).
13+
* `Dismissible.confirmDismiss` prop ([#2359](https://github.com/flet-dev/flet/issues/2359)).
14+
* `ListView.reverse` and `GridView.reverse` props ([#2335](https://github.com/flet-dev/flet/issues/2335)).
15+
* `Text.style` type Deprecation warning ([#2286](https://github.com/flet-dev/flet/issues/2286)).
16+
* Add `LineChartData.prevent_curve_over_shooting` and `LineChartData.prevent_curve_over_shooting_threshold` props ([#2354](https://github.com/flet-dev/flet/issues/2354)).
17+
* `flet build` to add checks to allow certain build commands according to "build_on" platform ([#2343](https://github.com/flet-dev/flet/issues/2343)).
18+
* Fixed: `flet build` gives "OSError: [WinError 193] %1 is not a valid Win32 application" for some users ([#2318](https://github.com/flet-dev/flet/issues/2318)).
19+
* Fixed: PubSub is not shared between pages in the same FastAPI app ([#2368](https://github.com/flet-dev/flet/issues/2368)).
20+
* Fixed: check for `DISPLAY` instead of `XDG_CURRENT_DESKTOP` to check if linux machine is GUIless or not ([#2373](https://github.com/flet-dev/flet/issues/2373)).
21+
122
# 0.18.0
223

324
* `flet build` command to package Flet app for any platform ([docs](https://flet.dev/docs/guides/python/packaging-app-for-distribution)).

package/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: flet
22
description: Write entire Flutter app in Python or add server-driven UI experience into existing Flutter app.
33
homepage: https://flet.dev
44
repository: https://github.com/flet-dev/flet
5-
version: 0.18.0
5+
version: 0.19.0
66

77
# This package supports all platforms listed below.
88
platforms:

sdk/python/packages/flet-runtime/src/flet_runtime/utils.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import hashlib
12
import json
23
import os
34
import re
@@ -168,6 +169,17 @@ def get_current_script_dir():
168169
return os.path.abspath(pathname)
169170

170171

172+
def calculate_file_hash(path, blocksize=65536):
173+
h = hashlib.sha256()
174+
with open(path, "rb") as f:
175+
while True:
176+
data = f.read(blocksize)
177+
if not data:
178+
break
179+
h.update(data)
180+
return h.hexdigest()
181+
182+
171183
def patch_index_html(
172184
index_path: str,
173185
base_href: str,

sdk/python/packages/flet/src/flet/cli/commands/build.py

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import yaml
1414
from flet.cli.commands.base import BaseCommand
1515
from flet_core.utils import random_string, slugify
16-
from flet_runtime.utils import copy_tree, is_windows
16+
from flet_runtime.utils import calculate_file_hash, copy_tree, is_windows
1717
from rich import print
1818

1919
if is_windows():
@@ -207,13 +207,6 @@ def add_arguments(self, parser: argparse.ArgumentParser) -> None:
207207
default="path",
208208
help="URL routing strategy (web only)",
209209
)
210-
parser.add_argument(
211-
"--windows-tcp-port",
212-
dest="windows_tcp_port",
213-
type=int,
214-
default=63777,
215-
help="TCP port for Windows app",
216-
)
217210
parser.add_argument(
218211
"--flutter-build-args",
219212
dest="flutter_build_args",
@@ -261,17 +254,9 @@ def add_arguments(self, parser: argparse.ArgumentParser) -> None:
261254
def handle(self, options: argparse.Namespace) -> None:
262255
from cookiecutter.main import cookiecutter
263256

264-
# check if `flutter` executable is available in the path
265-
flutter_exe = shutil.which("flutter")
266-
if not flutter_exe:
267-
print("`flutter` command is not available in PATH. Install Flutter SDK.")
268-
sys.exit(1)
269-
270-
# check if `dart` executable is available in the path
271-
dart_exe = shutil.which("dart")
272-
if not dart_exe:
273-
print("`dart` command is not available in PATH. Install Flutter SDK.")
274-
sys.exit(1)
257+
# get `flutter` and `dart` executables from PATH
258+
flutter_exe = self.find_flutter_batch("flutter")
259+
dart_exe = self.find_flutter_batch("dart")
275260

276261
target_platform = options.target_platform.lower()
277262
# platform check
@@ -351,7 +336,6 @@ def handle(self, options: argparse.Namespace) -> None:
351336
template_data["use_color_emoji"] = (
352337
"true" if options.use_color_emoji else "false"
353338
)
354-
template_data["windows_tcp_port"] = options.windows_tcp_port
355339

356340
# create Flutter project from a template
357341
print("Creating Flutter bootstrap project...", end="")
@@ -590,6 +574,8 @@ def fallback_image(yaml_path: str, images: list):
590574
package_args.extend(
591575
[
592576
"--mobile",
577+
"--platform",
578+
"mobile",
593579
]
594580
)
595581
package_args.extend(
@@ -603,6 +589,9 @@ def fallback_image(yaml_path: str, images: list):
603589
]
604590
)
605591

592+
if self.verbose > 1:
593+
package_args.append("--verbose")
594+
606595
package_result = self.run(package_args, cwd=str(self.flutter_dir))
607596

608597
if package_result.returncode != 0:
@@ -611,6 +600,17 @@ def fallback_image(yaml_path: str, images: list):
611600
if package_result.stderr:
612601
print(package_result.stderr)
613602
self.cleanup(package_result.returncode)
603+
604+
# make sure app/app.zip exists
605+
app_zip_path = self.flutter_dir.joinpath("app", "app.zip")
606+
if not os.path.exists(app_zip_path):
607+
print("Flet app package app/app.zip was not created.")
608+
self.cleanup(1)
609+
610+
# create {flutter_dir}/app/app.hash
611+
app_hash_path = self.flutter_dir.joinpath("app", "app.zip.hash")
612+
with open(app_hash_path, "w") as hf:
613+
hf.write(calculate_file_hash(app_zip_path))
614614
print("[spring_green3]OK[/spring_green3]")
615615

616616
# run `flutter build`
@@ -710,6 +710,17 @@ def copy_icon_image(self, src_path: Path, dest_path: Path, image_name: str):
710710
return Path(images[0]).name
711711
return None
712712

713+
def find_flutter_batch(self, exe_filename: str):
714+
batch_path = shutil.which(exe_filename)
715+
if not batch_path:
716+
print(
717+
f"`{exe_filename}` command is not available in PATH. Install Flutter SDK."
718+
)
719+
sys.exit(1)
720+
if is_windows() and batch_path.endswith(".file"):
721+
return batch_path.replace(".file", ".bat")
722+
return batch_path
723+
713724
def run(self, args, cwd):
714725
if is_windows():
715726
# Source: https://stackoverflow.com/a/77374899/1435891

0 commit comments

Comments
 (0)