flet-cli 1.1.1__tar.gz → 1.1.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {flet_cli-1.1.1 → flet_cli-1.1.3}/PKG-INFO +4 -4
- {flet_cli-1.1.1 → flet_cli-1.1.3}/README.md +1 -1
- {flet_cli-1.1.1 → flet_cli-1.1.3}/pyproject.toml +3 -3
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli/__pyinstaller/config.py +6 -1
- flet_cli-1.1.3/src/flet_cli/__pyinstaller/hook-flet.py +23 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli/__pyinstaller/macos_utils.py +2 -44
- flet_cli-1.1.3/src/flet_cli/__pyinstaller/utils.py +351 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli/__pyinstaller/win_utils.py +63 -16
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli/commands/build_base.py +91 -48
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli/commands/pack.py +76 -175
- flet_cli-1.1.3/src/flet_cli/utils/web_fonts.py +64 -0
- flet_cli-1.1.3/src/flet_cli/version.py +1 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli.egg-info/PKG-INFO +4 -4
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli.egg-info/SOURCES.txt +4 -1
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli.egg-info/requires.txt +2 -2
- flet_cli-1.1.3/tests/test_build_icons.py +349 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/tests/test_cli_pass_through_args.py +5 -1
- flet_cli-1.1.3/tests/test_pyinstaller.py +316 -0
- flet_cli-1.1.3/tests/test_web_fonts.py +80 -0
- flet_cli-1.1.1/src/flet_cli/__pyinstaller/hook-flet.py +0 -17
- flet_cli-1.1.1/src/flet_cli/__pyinstaller/utils.py +0 -72
- flet_cli-1.1.1/src/flet_cli/version.py +0 -1
- flet_cli-1.1.1/tests/test_build_icons.py +0 -47
- {flet_cli-1.1.1 → flet_cli-1.1.3}/setup.cfg +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli/__pyinstaller/__init__.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli/__pyinstaller/hook-flet_desktop.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli/__pyinstaller/rthooks/pyi_rth_localhost_fletd.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli/__pyinstaller/rthooks.dat +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli/cli.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli/commands/base.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli/commands/build.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli/commands/clean.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli/commands/create.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli/commands/debug.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli/commands/devices.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli/commands/doctor.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli/commands/emulators.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli/commands/flutter_base.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli/commands/mcp.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli/commands/options.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli/commands/publish.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli/commands/run.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli/commands/serve.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli/commands/test.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli/commands/test_host.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli/utils/android.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli/utils/android_sdk.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli/utils/app_excludes.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli/utils/cli.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli/utils/distros.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli/utils/examples.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli/utils/extension_settings.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli/utils/flutter.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli/utils/hash_stamp.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli/utils/ios_sign.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli/utils/jdk.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli/utils/linux_deps.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli/utils/log_format.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli/utils/macos_sign.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli/utils/merge.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli/utils/plist.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli/utils/processes.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli/utils/project_dependencies.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli/utils/pyodide.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli/utils/pyproject_toml.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli/utils/python_versions.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli/utils/template_cache.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli.egg-info/dependency_links.txt +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli.egg-info/entry_points.txt +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/src/flet_cli.egg-info/top_level.txt +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/tests/test_app_excludes.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/tests/test_build_android.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/tests/test_build_app_path.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/tests/test_build_copy_output.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/tests/test_build_ios.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/tests/test_build_linux.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/tests/test_build_list_options.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/tests/test_build_macos.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/tests/test_build_macos_signing.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/tests/test_build_package_cache.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/tests/test_build_platform_settings.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/tests/test_build_splash.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/tests/test_build_svg.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/tests/test_build_template.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/tests/test_build_version.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/tests/test_build_web_fonts.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/tests/test_build_windows_arm64.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/tests/test_clean.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/tests/test_cli_positionals.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/tests/test_create.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/tests/test_extension_settings.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/tests/test_find_platform_image.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/tests/test_flutter.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/tests/test_linux_desktop_entry.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/tests/test_log_format.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/tests/test_macos_sign.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/tests/test_pack_extensions.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/tests/test_plist.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/tests/test_project_dependencies.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/tests/test_pyodide_runtime.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/tests/test_python_versions.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/tests/test_run_assets_dir.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/tests/test_run_desktop_dependency.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/tests/test_run_script_args.py +0 -0
- {flet_cli-1.1.1 → flet_cli-1.1.3}/tests/test_run_watcher_unavailable.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: flet-cli
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.3
|
|
4
4
|
Summary: Flet CLI
|
|
5
5
|
Author-email: "Appveyor Systems Inc." <hello@flet.dev>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -9,8 +9,8 @@ Project-URL: Repository, https://github.com/flet-dev/flet
|
|
|
9
9
|
Project-URL: Documentation, https://flet.dev/docs
|
|
10
10
|
Requires-Python: >=3.10
|
|
11
11
|
Description-Content-Type: text/markdown
|
|
12
|
-
Requires-Dist: flet==1.1.
|
|
13
|
-
Requires-Dist: flet-platform-assets==1.1.
|
|
12
|
+
Requires-Dist: flet==1.1.3
|
|
13
|
+
Requires-Dist: flet-platform-assets==1.1.3
|
|
14
14
|
Requires-Dist: watchdog>=4.0.0
|
|
15
15
|
Requires-Dist: packaging>=25.0
|
|
16
16
|
Requires-Dist: qrcode>=7.4.2
|
|
@@ -29,7 +29,7 @@ Requires-Dist: flet-mcp; extra == "mcp"
|
|
|
29
29
|
|
|
30
30
|
Flet CLI is a command-line interface tool for Flet, a framework for building interactive multi-platform applications using Python.
|
|
31
31
|
|
|
32
|
-
> **[Try Flet online in Flet Studio](https://studio.flet.dev)**
|
|
32
|
+
> **[Try Flet online in Flet Studio](https://studio.flet.dev/?utm_source=pypi&utm_medium=readme&utm_campaign=flet-cli)**
|
|
33
33
|
>
|
|
34
34
|
> Try an idea in your browser with no installation, then use the Flet CLI locally to develop and package your app. Write your own Python code or get help from the AI agent.
|
|
35
35
|
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
Flet CLI is a command-line interface tool for Flet, a framework for building interactive multi-platform applications using Python.
|
|
7
7
|
|
|
8
|
-
> **[Try Flet online in Flet Studio](https://studio.flet.dev)**
|
|
8
|
+
> **[Try Flet online in Flet Studio](https://studio.flet.dev/?utm_source=pypi&utm_medium=readme&utm_campaign=flet-cli)**
|
|
9
9
|
>
|
|
10
10
|
> Try an idea in your browser with no installation, then use the Flet CLI locally to develop and package your app. Write your own Python code or get help from the AI agent.
|
|
11
11
|
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "flet-cli"
|
|
3
|
-
version = "1.1.
|
|
3
|
+
version = "1.1.3"
|
|
4
4
|
description = "Flet CLI"
|
|
5
5
|
authors = [{ name = "Appveyor Systems Inc.", email = "hello@flet.dev" }]
|
|
6
6
|
license = "Apache-2.0"
|
|
7
7
|
readme = "README.md"
|
|
8
8
|
requires-python = ">=3.10"
|
|
9
9
|
dependencies = [
|
|
10
|
-
"flet==1.1.
|
|
11
|
-
"flet-platform-assets==1.1.
|
|
10
|
+
"flet==1.1.3",
|
|
11
|
+
"flet-platform-assets==1.1.3",
|
|
12
12
|
"watchdog >=4.0.0",
|
|
13
13
|
"packaging >=25.0",
|
|
14
14
|
"qrcode >=7.4.2",
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
from PyInstaller.config import CONF
|
|
4
|
+
from PyInstaller.utils.hooks import collect_data_files
|
|
5
|
+
|
|
6
|
+
import flet_cli.__pyinstaller.config as hook_config
|
|
7
|
+
from flet_cli.__pyinstaller.utils import archive_flet_bin
|
|
8
|
+
|
|
9
|
+
client_files = hook_config.client_files
|
|
10
|
+
if client_files is None:
|
|
11
|
+
# A plain `pyinstaller` run, not `flet pack`: bundle the client archive
|
|
12
|
+
# so the app doesn't download the client on its first start. It is kept
|
|
13
|
+
# in the work directory, next to the cached analysis that lists it.
|
|
14
|
+
client_files = archive_flet_bin(os.path.join(CONF["workpath"], "flet-client"))
|
|
15
|
+
|
|
16
|
+
datas = []
|
|
17
|
+
datas += collect_data_files("flet.controls.material", includes=["icons.json"])
|
|
18
|
+
datas += collect_data_files(
|
|
19
|
+
"flet.controls.cupertino", includes=["cupertino_icons.json"]
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
for path in client_files or []:
|
|
23
|
+
datas.append((path, "flet_desktop/app"))
|
|
@@ -1,37 +1,13 @@
|
|
|
1
|
-
import gzip
|
|
2
1
|
import os
|
|
3
2
|
import plistlib
|
|
4
3
|
import shutil
|
|
5
4
|
import subprocess
|
|
6
|
-
import tarfile
|
|
7
5
|
from pathlib import Path
|
|
8
6
|
from typing import Any, Optional
|
|
9
7
|
|
|
10
8
|
from PyInstaller.building.icon import normalize_icon_type
|
|
11
9
|
|
|
12
10
|
import flet_cli.__pyinstaller.config as hook_config
|
|
13
|
-
from flet.utils import safe_tar_extractall
|
|
14
|
-
from flet_cli.__pyinstaller.utils import normalize_tar_entry
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
def unpack_app_bundle(tar_path: str) -> str:
|
|
18
|
-
"""
|
|
19
|
-
Extract a macOS app bundle archive and remove the source tarball.
|
|
20
|
-
|
|
21
|
-
Args:
|
|
22
|
-
tar_path: Path to a `*.tar.gz` archive containing `Flet.app`.
|
|
23
|
-
|
|
24
|
-
Returns:
|
|
25
|
-
Path to extracted `Flet.app`.
|
|
26
|
-
"""
|
|
27
|
-
|
|
28
|
-
bin_dir = str(Path(tar_path).parent)
|
|
29
|
-
|
|
30
|
-
with tarfile.open(tar_path, "r:gz") as tar_arch:
|
|
31
|
-
safe_tar_extractall(tar_arch, bin_dir)
|
|
32
|
-
os.remove(tar_path)
|
|
33
|
-
|
|
34
|
-
return os.path.join(bin_dir, "Flet.app")
|
|
35
11
|
|
|
36
12
|
|
|
37
13
|
def update_flet_view_icon(app_path: str, icon_path: str) -> None:
|
|
@@ -111,19 +87,17 @@ def update_flet_view_version_info(
|
|
|
111
87
|
return app_path
|
|
112
88
|
|
|
113
89
|
|
|
114
|
-
def
|
|
90
|
+
def sign_app_bundle(app_path: str) -> None:
|
|
115
91
|
"""
|
|
116
|
-
|
|
92
|
+
Ad-hoc code-sign a macOS app bundle, after its icon or metadata changed.
|
|
117
93
|
|
|
118
94
|
Args:
|
|
119
95
|
app_path: Path to app bundle directory.
|
|
120
|
-
tar_path: Destination tar.gz path.
|
|
121
96
|
|
|
122
97
|
Raises:
|
|
123
98
|
SystemError: If `codesign` fails.
|
|
124
99
|
"""
|
|
125
100
|
|
|
126
|
-
# sign app bundle
|
|
127
101
|
hook_config.log_progress(f"Signing file {app_path}")
|
|
128
102
|
cmd_args = [
|
|
129
103
|
"codesign",
|
|
@@ -147,22 +121,6 @@ def assemble_app_bundle(app_path: str, tar_path: str) -> None:
|
|
|
147
121
|
f"error code {p.returncode}!\noutput: {p.stdout}"
|
|
148
122
|
)
|
|
149
123
|
|
|
150
|
-
# Pack tar with fixed timestamps, so archives of identical content are
|
|
151
|
-
# byte-identical and the runtime cache fingerprint stays stable
|
|
152
|
-
with (
|
|
153
|
-
open(tar_path, "wb") as raw,
|
|
154
|
-
gzip.GzipFile(fileobj=raw, mode="wb", mtime=0) as gz,
|
|
155
|
-
tarfile.open(fileobj=gz, mode="w") as tar,
|
|
156
|
-
):
|
|
157
|
-
tar.add(
|
|
158
|
-
app_path,
|
|
159
|
-
arcname=os.path.basename(app_path),
|
|
160
|
-
filter=normalize_tar_entry,
|
|
161
|
-
)
|
|
162
|
-
|
|
163
|
-
# cleanup
|
|
164
|
-
shutil.rmtree(app_path, ignore_errors=True)
|
|
165
|
-
|
|
166
124
|
|
|
167
125
|
def __load_info_plist(app_path: str) -> dict[str, Any]:
|
|
168
126
|
"""
|
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
import gzip
|
|
2
|
+
import hashlib
|
|
3
|
+
import json
|
|
4
|
+
import logging
|
|
5
|
+
import os
|
|
6
|
+
import shutil
|
|
7
|
+
import tarfile
|
|
8
|
+
import tempfile
|
|
9
|
+
import uuid
|
|
10
|
+
import zipfile
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
from typing import Optional
|
|
13
|
+
|
|
14
|
+
from flet.utils import copy_tree, is_macos, is_windows
|
|
15
|
+
from flet_desktop import (
|
|
16
|
+
ensure_client_cached,
|
|
17
|
+
find_macos_app_bundle,
|
|
18
|
+
get_artifact_filename,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
logger = logging.getLogger(__name__)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def get_flet_bin_path() -> Optional[str]:
|
|
25
|
+
"""
|
|
26
|
+
Return path to Flet desktop binaries, if available.
|
|
27
|
+
|
|
28
|
+
Resolution order:
|
|
29
|
+
|
|
30
|
+
1. FLET_VIEW_PATH environment variable.
|
|
31
|
+
2. Cached / downloaded client from ~/.flet/client/.
|
|
32
|
+
|
|
33
|
+
Returns:
|
|
34
|
+
Absolute binaries directory path or `None` when not found.
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
# 1. Check FLET_VIEW_PATH (developer / custom build mode).
|
|
38
|
+
flet_view_path = os.environ.get("FLET_VIEW_PATH")
|
|
39
|
+
if flet_view_path and os.path.exists(flet_view_path):
|
|
40
|
+
return flet_view_path
|
|
41
|
+
|
|
42
|
+
# 2. Fall back to cached / downloaded client.
|
|
43
|
+
cache_dir = ensure_client_cached()
|
|
44
|
+
if cache_dir and cache_dir.exists():
|
|
45
|
+
return str(cache_dir)
|
|
46
|
+
|
|
47
|
+
return None
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def normalize_tar_entry(tarinfo: tarfile.TarInfo) -> tarfile.TarInfo:
|
|
51
|
+
"""
|
|
52
|
+
Normalize a tar entry's metadata (mtime, owner) so that archives built
|
|
53
|
+
from identical content are byte-identical across builds.
|
|
54
|
+
|
|
55
|
+
Args:
|
|
56
|
+
tarinfo: Entry to normalize, as passed by `tarfile.TarFile.add`.
|
|
57
|
+
|
|
58
|
+
Returns:
|
|
59
|
+
The same entry, with mtime and ownership zeroed.
|
|
60
|
+
"""
|
|
61
|
+
|
|
62
|
+
tarinfo.mtime = 0
|
|
63
|
+
tarinfo.uid = tarinfo.gid = 0
|
|
64
|
+
tarinfo.uname = tarinfo.gname = ""
|
|
65
|
+
return tarinfo
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def resolve_flet_client() -> Optional[tuple[str, str]]:
|
|
69
|
+
"""
|
|
70
|
+
Find the Flet desktop client to bundle with the app.
|
|
71
|
+
|
|
72
|
+
The cached client keeps the client in a `flet` subdirectory, while
|
|
73
|
+
`FLET_VIEW_PATH` may name the client directory itself. The client must
|
|
74
|
+
hold its executable (`flet.exe` on Windows, `flet` on Linux, a `.app`
|
|
75
|
+
bundle on macOS): the app trusts a bundled archive and doesn't download
|
|
76
|
+
the client, so an archive without one would fail on every start.
|
|
77
|
+
|
|
78
|
+
Returns:
|
|
79
|
+
`(client_dir, arcname)`: the client directory, and its name in the
|
|
80
|
+
client archive (`flet`, or the `.app` bundle name on macOS). `None`
|
|
81
|
+
when no client is available.
|
|
82
|
+
|
|
83
|
+
Raises:
|
|
84
|
+
RuntimeError: If the client directory holds no client executable.
|
|
85
|
+
"""
|
|
86
|
+
|
|
87
|
+
bin_path = get_flet_bin_path()
|
|
88
|
+
if not bin_path:
|
|
89
|
+
return None
|
|
90
|
+
|
|
91
|
+
if bin_path == os.environ.get("FLET_VIEW_PATH"):
|
|
92
|
+
source = f"FLET_VIEW_PATH ({bin_path})"
|
|
93
|
+
hint = "Point FLET_VIEW_PATH at a Flet client directory, or unset it."
|
|
94
|
+
else:
|
|
95
|
+
source = f"The cached Flet client ({bin_path})"
|
|
96
|
+
hint = "Delete that directory and try again."
|
|
97
|
+
|
|
98
|
+
if is_macos():
|
|
99
|
+
app_path = find_macos_app_bundle(bin_path)
|
|
100
|
+
if app_path is None:
|
|
101
|
+
raise RuntimeError(f"{source} holds no .app bundle. {hint}")
|
|
102
|
+
return str(app_path), app_path.name
|
|
103
|
+
|
|
104
|
+
client_dir = os.path.join(bin_path, "flet")
|
|
105
|
+
src_dir = client_dir if os.path.isdir(client_dir) else bin_path
|
|
106
|
+
exe = "flet.exe" if is_windows() else "flet"
|
|
107
|
+
if not os.path.isfile(os.path.join(src_dir, exe)):
|
|
108
|
+
raise RuntimeError(f"{source} holds no {exe}. {hint}")
|
|
109
|
+
return src_dir, "flet"
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def get_linux_client_flavor(client_dir: str) -> str:
|
|
113
|
+
"""
|
|
114
|
+
Return the flavor of the Linux client in `client_dir`: `"full"` or
|
|
115
|
+
`"light"`.
|
|
116
|
+
|
|
117
|
+
Only the full client includes `media_kit`, which links the `libmpv` of the
|
|
118
|
+
distro it was built on. The runtime runs a light client on any distro with
|
|
119
|
+
a new enough glibc, so a client is called light only when it lacks
|
|
120
|
+
`media_kit`.
|
|
121
|
+
|
|
122
|
+
Args:
|
|
123
|
+
client_dir: Linux client directory, holding `lib/`.
|
|
124
|
+
"""
|
|
125
|
+
|
|
126
|
+
try:
|
|
127
|
+
libs = os.listdir(os.path.join(client_dir, "lib"))
|
|
128
|
+
except OSError:
|
|
129
|
+
libs = []
|
|
130
|
+
return "full" if any(lib.startswith("libmedia_kit") for lib in libs) else "light"
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def get_client_archive_name(client_dir: str) -> Optional[str]:
|
|
134
|
+
"""
|
|
135
|
+
Return the name the runtime looks for the client archive under.
|
|
136
|
+
|
|
137
|
+
On Linux the name holds the flavor of the client in `client_dir`, rather
|
|
138
|
+
than the configured one, since `FLET_VIEW_PATH` may point at either.
|
|
139
|
+
|
|
140
|
+
Args:
|
|
141
|
+
client_dir: Client directory to archive.
|
|
142
|
+
|
|
143
|
+
Returns:
|
|
144
|
+
The archive name, or `None` when no client archive can be named for
|
|
145
|
+
this Linux system: the runtime couldn't pick a client here either.
|
|
146
|
+
"""
|
|
147
|
+
|
|
148
|
+
if is_windows() or is_macos():
|
|
149
|
+
return get_artifact_filename()
|
|
150
|
+
try:
|
|
151
|
+
return get_artifact_filename(get_linux_client_flavor(client_dir))
|
|
152
|
+
except RuntimeError as e:
|
|
153
|
+
logger.warning(f"Not bundling the Flet client: {e}")
|
|
154
|
+
return None
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def copy_flet_bin() -> Optional[str]:
|
|
158
|
+
"""
|
|
159
|
+
Copy the Flet desktop client into a new temporary directory.
|
|
160
|
+
|
|
161
|
+
`flet pack` customizes the copy, then archives it with
|
|
162
|
+
`stage_client_archive()`. The copy holds only the client, as
|
|
163
|
+
`<temp dir>/<arcname>`, whichever layout it was found in.
|
|
164
|
+
|
|
165
|
+
Returns:
|
|
166
|
+
Path to the temporary directory, or `None` when no client is
|
|
167
|
+
available.
|
|
168
|
+
|
|
169
|
+
Raises:
|
|
170
|
+
RuntimeError: If the client directory holds no client executable.
|
|
171
|
+
"""
|
|
172
|
+
|
|
173
|
+
client = resolve_flet_client()
|
|
174
|
+
if not client:
|
|
175
|
+
return None
|
|
176
|
+
src_dir, arcname = client
|
|
177
|
+
temp_bin_dir = Path(tempfile.gettempdir()).joinpath(str(uuid.uuid4()))
|
|
178
|
+
copy_tree(src_dir, str(temp_bin_dir.joinpath(arcname)))
|
|
179
|
+
return str(temp_bin_dir)
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def write_client_archive(src_dir: str, arcname: str, archive_path: str) -> None:
|
|
183
|
+
"""
|
|
184
|
+
Write `src_dir` into a client archive under the top-level name `arcname`.
|
|
185
|
+
|
|
186
|
+
Fixed timestamps and sorted entries make the archive byte-identical for
|
|
187
|
+
identical inputs, so the runtime cache fingerprint (and thus the client
|
|
188
|
+
cache directory) only changes when the content does.
|
|
189
|
+
|
|
190
|
+
Args:
|
|
191
|
+
src_dir: Directory to archive.
|
|
192
|
+
arcname: Name of `src_dir` inside the archive, e.g. `flet` or `Flet.app`.
|
|
193
|
+
archive_path: Archive to create: zip for a `.zip` name, gzipped tar
|
|
194
|
+
otherwise.
|
|
195
|
+
"""
|
|
196
|
+
|
|
197
|
+
if archive_path.endswith(".zip"):
|
|
198
|
+
with zipfile.ZipFile(archive_path, "w", zipfile.ZIP_DEFLATED) as zf:
|
|
199
|
+
for root, dirs, files in os.walk(src_dir):
|
|
200
|
+
dirs.sort()
|
|
201
|
+
for f in sorted(files):
|
|
202
|
+
full = os.path.join(root, f)
|
|
203
|
+
name = os.path.join(arcname, os.path.relpath(full, src_dir))
|
|
204
|
+
zi = zipfile.ZipInfo(
|
|
205
|
+
name.replace(os.sep, "/"), date_time=(1980, 1, 1, 0, 0, 0)
|
|
206
|
+
)
|
|
207
|
+
zi.compress_type = zipfile.ZIP_DEFLATED
|
|
208
|
+
zi.external_attr = (os.stat(full).st_mode & 0xFFFF) << 16
|
|
209
|
+
with open(full, "rb") as src, zf.open(zi, "w") as dest:
|
|
210
|
+
shutil.copyfileobj(src, dest)
|
|
211
|
+
else:
|
|
212
|
+
with (
|
|
213
|
+
open(archive_path, "wb") as raw,
|
|
214
|
+
# No file name in the gzip header, which would differ per path.
|
|
215
|
+
gzip.GzipFile(filename="", fileobj=raw, mode="wb", mtime=0) as gz,
|
|
216
|
+
tarfile.open(fileobj=gz, mode="w") as tar,
|
|
217
|
+
):
|
|
218
|
+
tar.add(src_dir, arcname=arcname, filter=normalize_tar_entry)
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
def write_archive_fingerprint(archive_path: str) -> None:
|
|
222
|
+
"""
|
|
223
|
+
Write a `<archive>.sha256` sidecar holding `<hash> <size>`.
|
|
224
|
+
|
|
225
|
+
`flet_desktop.ensure_client_cached()` uses it at runtime to key the
|
|
226
|
+
client cache directory by content, so a bundled client doesn't collide
|
|
227
|
+
with the downloaded client or other apps' bundled clients. The size lets
|
|
228
|
+
the runtime detect a stale sidecar next to a replaced archive and re-hash
|
|
229
|
+
instead of trusting it.
|
|
230
|
+
|
|
231
|
+
Args:
|
|
232
|
+
archive_path: Path of the client archive to fingerprint.
|
|
233
|
+
"""
|
|
234
|
+
|
|
235
|
+
h = hashlib.sha256()
|
|
236
|
+
with open(archive_path, "rb") as f:
|
|
237
|
+
while chunk := f.read(1024 * 1024):
|
|
238
|
+
h.update(chunk)
|
|
239
|
+
with open(archive_path + ".sha256", "w") as f:
|
|
240
|
+
f.write(f"{h.hexdigest()} {os.path.getsize(archive_path)}")
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
def _get_source_stamp(src_dir: str, arcname: str, archive_name: str) -> str:
|
|
244
|
+
"""
|
|
245
|
+
Return a stamp of the files in `src_dir`, from their names, sizes and
|
|
246
|
+
modification times, to tell cheaply whether an archive of them is current.
|
|
247
|
+
"""
|
|
248
|
+
|
|
249
|
+
entries = []
|
|
250
|
+
for root, dirs, files in os.walk(src_dir):
|
|
251
|
+
dirs.sort()
|
|
252
|
+
for name in sorted(dirs + files):
|
|
253
|
+
path = os.path.join(root, name)
|
|
254
|
+
st = os.lstat(path)
|
|
255
|
+
entries.append([os.path.relpath(path, src_dir), st.st_size, st.st_mtime_ns])
|
|
256
|
+
data = json.dumps([arcname, archive_name, entries])
|
|
257
|
+
return hashlib.sha256(data.encode()).hexdigest()
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
def stage_client_archive(
|
|
261
|
+
src_dir: str, arcname: str, archive_name: str, dest_dir: str
|
|
262
|
+
) -> list[str]:
|
|
263
|
+
"""
|
|
264
|
+
Write the client archive and its fingerprint sidecar into `dest_dir`.
|
|
265
|
+
|
|
266
|
+
`dest_dir` must outlive the build: PyInstaller caches the analysis that
|
|
267
|
+
lists these files and reuses it on the next build when nothing it tracks
|
|
268
|
+
has changed, skipping a missing file with only a warning. So the archive
|
|
269
|
+
is replaced only when its content changes, which also tells PyInstaller,
|
|
270
|
+
through the newer modification time, to analyze again. When the files of
|
|
271
|
+
`src_dir` haven't changed since the last call, the archive isn't even
|
|
272
|
+
rebuilt. Other archives left in `dest_dir` are removed.
|
|
273
|
+
|
|
274
|
+
Args:
|
|
275
|
+
src_dir: Client directory to archive.
|
|
276
|
+
arcname: Name of `src_dir` inside the archive.
|
|
277
|
+
archive_name: Name of the archive, see `get_client_archive_name()`.
|
|
278
|
+
dest_dir: Directory to write the archive into; created if missing.
|
|
279
|
+
|
|
280
|
+
Returns:
|
|
281
|
+
Paths of the archive and its sidecar, the files to bundle.
|
|
282
|
+
"""
|
|
283
|
+
|
|
284
|
+
dest = Path(dest_dir)
|
|
285
|
+
dest.mkdir(parents=True, exist_ok=True)
|
|
286
|
+
archive = dest / archive_name
|
|
287
|
+
sidecar = dest / f"{archive_name}.sha256"
|
|
288
|
+
stamp_file = dest / ".source"
|
|
289
|
+
files = [str(archive), str(sidecar)]
|
|
290
|
+
|
|
291
|
+
stamp = _get_source_stamp(src_dir, arcname, archive_name)
|
|
292
|
+
current = archive.is_file() and sidecar.is_file()
|
|
293
|
+
if current and stamp_file.is_file() and stamp_file.read_text() == stamp:
|
|
294
|
+
return files
|
|
295
|
+
|
|
296
|
+
# The extension picks the archive format, so it stays last.
|
|
297
|
+
temp = dest / f".{uuid.uuid4().hex}.{archive_name}"
|
|
298
|
+
temp_sidecar = Path(f"{temp}.sha256")
|
|
299
|
+
try:
|
|
300
|
+
write_client_archive(src_dir, arcname, str(temp))
|
|
301
|
+
write_archive_fingerprint(str(temp))
|
|
302
|
+
if current and sidecar.read_text() == temp_sidecar.read_text():
|
|
303
|
+
# Same content: keep the files, and their modification times.
|
|
304
|
+
temp.unlink()
|
|
305
|
+
temp_sidecar.unlink()
|
|
306
|
+
else:
|
|
307
|
+
os.replace(temp, archive)
|
|
308
|
+
os.replace(temp_sidecar, sidecar)
|
|
309
|
+
finally:
|
|
310
|
+
for path in (temp, temp_sidecar):
|
|
311
|
+
path.unlink(missing_ok=True)
|
|
312
|
+
|
|
313
|
+
for entry in dest.iterdir():
|
|
314
|
+
if entry not in (archive, sidecar, stamp_file):
|
|
315
|
+
if entry.is_dir() and not entry.is_symlink():
|
|
316
|
+
shutil.rmtree(entry, ignore_errors=True)
|
|
317
|
+
else:
|
|
318
|
+
entry.unlink(missing_ok=True)
|
|
319
|
+
stamp_file.write_text(stamp)
|
|
320
|
+
return files
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
def archive_flet_bin(dest_dir: str) -> Optional[list[str]]:
|
|
324
|
+
"""
|
|
325
|
+
Pack the Flet desktop client into the archive the app unpacks at runtime.
|
|
326
|
+
|
|
327
|
+
`flet_desktop.ensure_client_cached()` looks for this archive in the
|
|
328
|
+
bundled `flet_desktop/app` directory, and downloads the client when it
|
|
329
|
+
isn't there. This is what a plain `pyinstaller` run bundles; `flet pack`
|
|
330
|
+
stages the archive of the client it customizes itself.
|
|
331
|
+
|
|
332
|
+
Args:
|
|
333
|
+
dest_dir: Directory to write the archive into, see
|
|
334
|
+
`stage_client_archive()`.
|
|
335
|
+
|
|
336
|
+
Returns:
|
|
337
|
+
Paths of the archive and its fingerprint sidecar, or `None` when no
|
|
338
|
+
client is available or can be named for this system.
|
|
339
|
+
|
|
340
|
+
Raises:
|
|
341
|
+
RuntimeError: If the client directory holds no client executable.
|
|
342
|
+
"""
|
|
343
|
+
|
|
344
|
+
client = resolve_flet_client()
|
|
345
|
+
if not client:
|
|
346
|
+
return None
|
|
347
|
+
src_dir, arcname = client
|
|
348
|
+
archive_name = get_client_archive_name(src_dir)
|
|
349
|
+
if not archive_name:
|
|
350
|
+
return None
|
|
351
|
+
return stage_client_archive(src_dir, arcname, archive_name, dest_dir)
|
|
@@ -14,6 +14,69 @@ from PyInstaller.utils.win32.icon import IconFile, normalize_icon_type
|
|
|
14
14
|
import flet_cli.__pyinstaller.config as hook_config
|
|
15
15
|
|
|
16
16
|
|
|
17
|
+
def remove_signature(exe_path: str) -> None:
|
|
18
|
+
"""
|
|
19
|
+
Remove the Authenticode signature from a Windows executable.
|
|
20
|
+
|
|
21
|
+
Changing an executable's resources invalidates its signature. Windows then
|
|
22
|
+
drops the signature's bytes but keeps the header entry that points to them,
|
|
23
|
+
which leaves an executable that signing tools reject. Removing both first
|
|
24
|
+
leaves an unsigned executable that can be patched and signed again.
|
|
25
|
+
|
|
26
|
+
Args:
|
|
27
|
+
exe_path: Path to the executable; left unchanged when it isn't signed.
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
with pefile.PE(exe_path, fast_load=True) as pe:
|
|
31
|
+
security = pe.OPTIONAL_HEADER.DATA_DIRECTORY[
|
|
32
|
+
pefile.DIRECTORY_ENTRY["IMAGE_DIRECTORY_ENTRY_SECURITY"]
|
|
33
|
+
]
|
|
34
|
+
if not security.Size:
|
|
35
|
+
return
|
|
36
|
+
|
|
37
|
+
# The entry holds a file offset, not a virtual address.
|
|
38
|
+
start, end = security.VirtualAddress, security.VirtualAddress + security.Size
|
|
39
|
+
image_end = pe.get_overlay_data_start_offset()
|
|
40
|
+
signature_found = (
|
|
41
|
+
image_end is not None
|
|
42
|
+
and image_end <= start < end <= len(pe.__data__)
|
|
43
|
+
and _is_certificate_table(pe.__data__[start:end])
|
|
44
|
+
)
|
|
45
|
+
security.VirtualAddress = security.Size = 0
|
|
46
|
+
pe.OPTIONAL_HEADER.CheckSum = 0
|
|
47
|
+
data = pe.write()
|
|
48
|
+
|
|
49
|
+
if signature_found:
|
|
50
|
+
hook_config.log_progress("Removing the signature of", exe_path)
|
|
51
|
+
data = data[:start] + data[end:]
|
|
52
|
+
else:
|
|
53
|
+
# The entry doesn't point at a signature after the image, e.g. it went
|
|
54
|
+
# stale when an earlier patch dropped the signature's bytes: clear the
|
|
55
|
+
# entry and keep the file's bytes.
|
|
56
|
+
hook_config.log_progress("Clearing a stale signature entry of", exe_path)
|
|
57
|
+
|
|
58
|
+
with open(exe_path, "wb") as f:
|
|
59
|
+
f.write(data)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _is_certificate_table(table: bytes) -> bool:
|
|
63
|
+
"""
|
|
64
|
+
Check that bytes start with a WIN_CERTIFICATE header: a length that fits in
|
|
65
|
+
the table, revision 1.0 or 2.0, and a known certificate type.
|
|
66
|
+
"""
|
|
67
|
+
|
|
68
|
+
if len(table) < 8:
|
|
69
|
+
return False
|
|
70
|
+
length = int.from_bytes(table[0:4], "little")
|
|
71
|
+
revision = int.from_bytes(table[4:6], "little")
|
|
72
|
+
cert_type = int.from_bytes(table[6:8], "little")
|
|
73
|
+
return (
|
|
74
|
+
8 <= length <= len(table)
|
|
75
|
+
and revision in (0x0100, 0x0200)
|
|
76
|
+
and (cert_type in (0x0001, 0x0002, 0x0003, 0x0004))
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
|
|
17
80
|
def update_flet_view_icon(exe_path: str, icon_path: str) -> None:
|
|
18
81
|
"""
|
|
19
82
|
Replace icon resources in a Windows executable.
|
|
@@ -127,26 +190,10 @@ def update_flet_view_version_info(
|
|
|
127
190
|
with open(version_info_path, "w", encoding="utf-8") as f:
|
|
128
191
|
f.write(str(vs))
|
|
129
192
|
|
|
130
|
-
# Remember overlay
|
|
131
|
-
pe = pefile.PE(exe_path, fast_load=True)
|
|
132
|
-
overlay_before = pe.get_overlay()
|
|
133
|
-
pe.close()
|
|
134
|
-
|
|
135
193
|
hdst = win32api.BeginUpdateResource(exe_path, 0)
|
|
136
194
|
win32api.UpdateResource(
|
|
137
195
|
hdst, pefile.RESOURCE_TYPE["RT_VERSION"], 1, vs.toRaw(), 1033
|
|
138
196
|
)
|
|
139
197
|
win32api.EndUpdateResource(hdst, 0)
|
|
140
198
|
|
|
141
|
-
if overlay_before:
|
|
142
|
-
# Check if the overlay is still present
|
|
143
|
-
pe = pefile.PE(exe_path, fast_load=True)
|
|
144
|
-
overlay_after = pe.get_overlay()
|
|
145
|
-
pe.close()
|
|
146
|
-
|
|
147
|
-
# If the update removed the overlay data, re-append it
|
|
148
|
-
if not overlay_after:
|
|
149
|
-
with open(exe_path, "ab", encoding="utf-8") as exef:
|
|
150
|
-
exef.write(overlay_before)
|
|
151
|
-
|
|
152
199
|
return version_info_path
|