flet-cli 0.85.3.dev1__py3-none-any.whl → 0.86.0.dev1__py3-none-any.whl

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/cli.py CHANGED
@@ -1,8 +1,10 @@
1
1
  import argparse
2
+ import json
2
3
  import sys
3
4
 
4
5
  import flet.version
5
6
  import flet_cli.commands.build
7
+ import flet_cli.commands.clean
6
8
  import flet_cli.commands.create
7
9
  import flet_cli.commands.debug
8
10
  import flet_cli.commands.devices
@@ -12,6 +14,29 @@ import flet_cli.commands.pack
12
14
  import flet_cli.commands.publish
13
15
  import flet_cli.commands.run
14
16
  import flet_cli.commands.serve
17
+ import flet_cli.commands.test
18
+ from flet_cli.utils.linux_deps import linux_dependencies
19
+
20
+
21
+ def _version_info() -> dict:
22
+ """Build the machine-readable `flet --version --json` document.
23
+
24
+ Exposes Flet/Flutter versions and the Linux build dependencies. The
25
+ supported Python/Pyodide set is no longer surfaced here — it now comes from
26
+ python-build's manifest (see `flet_cli.utils.python_versions`).
27
+ """
28
+ return {
29
+ "flet": flet.version.flet_version,
30
+ "flutter": flet.version.flutter_version,
31
+ "linux_dependencies": list(linux_dependencies),
32
+ }
33
+
34
+
35
+ def _render_version(as_json: bool) -> str:
36
+ """Render `flet --version` output as JSON or the human-readable text block."""
37
+ if as_json:
38
+ return json.dumps(_version_info(), indent=2)
39
+ return f"Flet: {flet.version.flet_version}\nFlutter: {flet.version.flutter_version}"
15
40
 
16
41
 
17
42
  # Source https://stackoverflow.com/a/26379693
@@ -68,16 +93,17 @@ def get_parser() -> argparse.ArgumentParser:
68
93
  formatter_class=argparse.RawDescriptionHelpFormatter
69
94
  )
70
95
 
71
- # add version flag
96
+ # add version flags
72
97
  parser.add_argument(
73
98
  "--version",
74
99
  "-V",
75
- action="version",
76
- version=(
77
- f"Flet: {flet.version.flet_version}\n"
78
- f"Flutter: {flet.version.flutter_version}\n"
79
- f"Pyodide: {flet.version.pyodide_version}"
80
- ),
100
+ action="store_true",
101
+ help="show version information and exit",
102
+ )
103
+ parser.add_argument(
104
+ "--json",
105
+ action="store_true",
106
+ help="with --version, output version information as JSON",
81
107
  )
82
108
 
83
109
  sp = parser.add_subparsers(dest="command")
@@ -86,7 +112,9 @@ def get_parser() -> argparse.ArgumentParser:
86
112
  flet_cli.commands.create.Command.register_to(sp, "create")
87
113
  flet_cli.commands.run.Command.register_to(sp, "run")
88
114
  flet_cli.commands.build.Command.register_to(sp, "build")
115
+ flet_cli.commands.clean.Command.register_to(sp, "clean")
89
116
  flet_cli.commands.debug.Command.register_to(sp, "debug")
117
+ flet_cli.commands.test.Command.register_to(sp, "test")
90
118
  flet_cli.commands.pack.Command.register_to(sp, "pack")
91
119
  flet_cli.commands.publish.Command.register_to(sp, "publish")
92
120
  flet_cli.commands.serve.Command.register_to(sp, "serve")
@@ -94,6 +122,16 @@ def get_parser() -> argparse.ArgumentParser:
94
122
  flet_cli.commands.devices.Command.register_to(sp, "devices")
95
123
  flet_cli.commands.doctor.Command.register_to(sp, "doctor")
96
124
 
125
+ # Register MCP command only if flet-mcp is installed
126
+ try:
127
+ from importlib import import_module
128
+
129
+ import_module("flet_mcp")
130
+ mcp_cmd = import_module("flet_cli.commands.mcp")
131
+ mcp_cmd.Command.register_to(sp, "mcp")
132
+ except ImportError:
133
+ pass
134
+
97
135
  # set "run" as the default subparser
98
136
  set_default_subparser(parser, name="run", index=1)
99
137
 
@@ -111,6 +149,11 @@ def main():
111
149
  # parse arguments
112
150
  args = parser.parse_args()
113
151
 
152
+ # handle `flet --version [--json]` (no subcommand/handler is set)
153
+ if getattr(args, "version", False):
154
+ print(_render_version(args.json))
155
+ sys.exit(0)
156
+
114
157
  # execute command
115
158
  args.handler(args)
116
159
 
@@ -1,9 +1,13 @@
1
1
  import argparse
2
+ import os
3
+ import shutil
4
+ from pathlib import Path
2
5
 
3
6
  from rich.console import Group
4
7
  from rich.live import Live
5
8
 
6
9
  from flet_cli.commands.build_base import BaseBuildCommand, console
10
+ from flet_cli.utils.android import flutter_target_platforms
7
11
 
8
12
 
9
13
  class Command(BaseBuildCommand):
@@ -116,9 +120,24 @@ class Command(BaseBuildCommand):
116
120
  ["build", self.platforms[self.target_platform]["flutter_build_command"]]
117
121
  )
118
122
 
119
- if self.target_platform in "apk" and self.template_data["split_per_abi"]:
123
+ if self.target_platform == "apk" and self.template_data["split_per_abi"]:
120
124
  args.append("--split-per-abi")
121
125
 
126
+ if (
127
+ self.target_platform in ("apk", "aab")
128
+ and self.template_data["options"]["target_arch"]
129
+ ):
130
+ args.extend(
131
+ [
132
+ "--target-platform",
133
+ ",".join(
134
+ flutter_target_platforms(
135
+ self.template_data["options"]["target_arch"]
136
+ )
137
+ ),
138
+ ]
139
+ )
140
+
122
141
  if self.target_platform in ["ipa"]:
123
142
  if self.template_data["ios_provisioning_profile"]:
124
143
  args.extend(
@@ -166,6 +185,22 @@ class Command(BaseBuildCommand):
166
185
  f"{self.platforms[self.target_platform]['status_text']}[/cyan]..."
167
186
  )
168
187
 
188
+ # Clear the build output directories of artifacts from previous runs. Flutter
189
+ # only ever adds files to them, and copy_build_output harvests them wholesale —
190
+ # so without this, a previous build with different options (e.g. --arch,
191
+ # --split-per-abi, or a renamed product) would leak its artifacts into the
192
+ # user's output directory.
193
+ assert self.flutter_dir
194
+ flutter_dir = self.flutter_dir.resolve()
195
+ for output in self.platforms[self.target_platform]["outputs"]:
196
+ output_dir = Path(
197
+ os.path.dirname(self.resolve_output_path(output))
198
+ ).resolve()
199
+ # only delete directories that are strictly inside the generated Flutter
200
+ # project (and never the project directory itself).
201
+ if output_dir != flutter_dir and output_dir.is_relative_to(flutter_dir):
202
+ shutil.rmtree(output_dir, ignore_errors=True)
203
+
169
204
  self._run_flutter_command()
170
205
 
171
206
  console.log(