Skip to content

Commit d3e4236

Browse files
committed
Refactor version retrieval and clean up CLI commands
Replaced usage of update_version() with from_git() for dynamic version retrieval throughout CLI and desktop modules. Removed unused imports and obsolete methods from build_base.py. Updated devices.py and emulators.py to import BaseFlutterCommand from flutter_base instead of build_base for better separation of concerns.
1 parent f00d361 commit d3e4236

File tree

7 files changed

+24
-61
lines changed

7 files changed

+24
-61
lines changed

sdk/python/packages/flet-cli/src/flet_cli/cli.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import flet_cli.commands.publish
1313
import flet_cli.commands.run
1414
import flet_cli.commands.serve
15-
from flet.version import update_version
1615

1716

1817
# Source https://stackoverflow.com/a/26379693
@@ -72,7 +71,9 @@ def get_parser() -> argparse.ArgumentParser:
7271
"--version",
7372
"-V",
7473
action="version",
75-
version=flet.version.version if flet.version.version else update_version(),
74+
version=flet.version.version
75+
if flet.version.version
76+
else flet.version.from_git(),
7677
)
7778

7879
sp = parser.add_subparsers(dest="command")

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

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from rich.console import Group
44
from rich.live import Live
5-
from rich.panel import Panel
65

76
from flet_cli.commands.build_base import BaseBuildCommand, console
87

@@ -60,18 +59,16 @@ def handle(self, options: argparse.Namespace) -> None:
6059
self.cleanup(
6160
0,
6261
message=(
63-
Panel(
64-
f"Successfully built your [cyan]"
65-
f"{self.platforms[self.target_platform]['status_text']}"
66-
f"[/cyan]! {self.emojis['success']} "
67-
f"Find it in [cyan]{self.rel_out_dir}[/cyan] directory. "
68-
f"{self.emojis['directory']}"
69-
+ (
70-
"\nRun [cyan]flet serve[/cyan] command to "
71-
"start a web server with your app. "
72-
if self.target_platform == "web"
73-
else ""
74-
)
62+
f"Successfully built your [cyan]"
63+
f"{self.platforms[self.target_platform]['status_text']}"
64+
f"[/cyan]! {self.emojis['success']} "
65+
f"Find it in [cyan]{self.rel_out_dir}[/cyan] directory. "
66+
f"{self.emojis['directory']}"
67+
+ (
68+
"\nRun [cyan]flet serve[/cyan] command to "
69+
"start a web server with your app. "
70+
if self.target_platform == "web"
71+
else ""
7572
)
7673
),
7774
)

sdk/python/packages/flet-cli/src/flet_cli/commands/build_base.py

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414

1515
import flet.version
1616
import flet_cli.utils.processes as processes
17-
from flet.utils import copy_tree, is_windows, slugify
18-
from flet.version import update_version
17+
from flet.utils import copy_tree, slugify
1918
from flet_cli.commands.flutter_base import (
2019
BaseFlutterCommand,
2120
console,
@@ -50,6 +49,7 @@ def __init__(self, parser: argparse.ArgumentParser) -> None:
5049
self.target_platform = None
5150
self.package_platform = None
5251
self.config_platform = None
52+
self.debug_platform = None
5353
self.flutter_dependencies = {}
5454
self.package_app_path = None
5555
self.template_data = None
@@ -1019,7 +1019,7 @@ def create_flutter_project(self, second_pass=False):
10191019
template_ref = (
10201020
version.Version(flet.version.version).base_version
10211021
if flet.version.version
1022-
else update_version()
1022+
else flet.version.from_git()
10231023
)
10241024
hash.update(template_ref)
10251025

@@ -1623,7 +1623,9 @@ def package_python_app(self):
16231623
package_args.extend(["-r", "-r", "-r", str(requirements_txt)])
16241624
else:
16251625
flet_version = (
1626-
flet.version.version if flet.version.version else update_version()
1626+
flet.version.version
1627+
if flet.version.version
1628+
else flet.version.from_git()
16271629
)
16281630
package_args.extend(["-r", f"flet=={flet_version}"])
16291631

@@ -1939,14 +1941,6 @@ def find_platform_image(
19391941
return Path(images[0]).name
19401942
return None
19411943

1942-
def find_flutter_batch(self, exe_filename: str):
1943-
batch_path = shutil.which(exe_filename)
1944-
if not batch_path:
1945-
return None
1946-
if is_windows() and batch_path.endswith(".file"):
1947-
return batch_path.replace(".file", ".bat")
1948-
return batch_path
1949-
19501944
def run(self, args, cwd, env: Optional[dict] = None, capture_output=True):
19511945
if self.verbose > 0:
19521946
console.log(f"Run subprocess: {args}", style=verbose1_style)
@@ -1959,30 +1953,6 @@ def run(self, args, cwd, env: Optional[dict] = None, capture_output=True):
19591953
log=self.log_stdout,
19601954
)
19611955

1962-
def run_flutter_doctor(self):
1963-
flutter_doctor = self.run(
1964-
[self.flutter_exe, "doctor", "--no-version-check", "--suppress-analytics"],
1965-
cwd=os.getcwd(),
1966-
capture_output=True,
1967-
)
1968-
if flutter_doctor.returncode == 0 and flutter_doctor.stdout:
1969-
console.log(flutter_doctor.stdout, style=verbose1_style)
1970-
1971-
def update_status(self, status):
1972-
if self.no_rich_output:
1973-
console.log(status)
1974-
else:
1975-
self.status.update(status)
1976-
1977-
def log_stdout(self, message):
1978-
if self.verbose > 0:
1979-
console.log(
1980-
message,
1981-
end="",
1982-
style=verbose2_style,
1983-
markup=False,
1984-
)
1985-
19861956
def load_yaml(self, path):
19871957
with open(str(path), encoding="utf-8") as f:
19881958
return yaml.safe_load(f)

sdk/python/packages/flet-cli/src/flet_cli/commands/devices.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from rich.panel import Panel
77
from rich.table import Column, Table
88

9-
from flet_cli.commands.build_base import BaseFlutterCommand, console, verbose2_style
9+
from flet_cli.commands.flutter_base import BaseFlutterCommand, console, verbose2_style
1010

1111

1212
class Command(BaseFlutterCommand):
@@ -63,10 +63,6 @@ def handle(self, options: argparse.Namespace) -> None:
6363
)
6464
with Live(Group(self.status, self.progress), console=console) as self.live:
6565
self.initialize_command()
66-
# if self.options.show_devices:
67-
# self.run_flutter_devices()
68-
# self.live.update("", refresh=True)
69-
# return
7066
self.run_flutter_devices()
7167
self.cleanup(0)
7268

sdk/python/packages/flet-cli/src/flet_cli/commands/emulators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from rich.panel import Panel
99
from rich.table import Column, Table
1010

11-
from flet_cli.commands.build_base import BaseFlutterCommand, console, verbose2_style
11+
from flet_cli.commands.flutter_base import BaseFlutterCommand, console, verbose2_style
1212
from flet_cli.utils.android_sdk import AndroidSDK
1313

1414

sdk/python/packages/flet-desktop/src/flet_desktop/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,8 @@ def __download_flet_client(file_name):
210210
ver = flet_desktop.version.version
211211
if not ver:
212212
import flet.version
213-
from flet.version import update_version
214213

215-
ver = flet.version.version or update_version()
214+
ver = flet.version.version or flet.version.from_git()
216215
temp_arch = Path(tempfile.gettempdir()).joinpath(file_name)
217216
flet_url = f"https://github.com/flet-dev/flet/releases/download/v{ver}/{file_name}"
218217
logger.info(f"Downloading Flet v{ver} from {flet_url} to {temp_arch}")

sdk/python/packages/flet/src/flet/version.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
version = ""
1414

1515

16-
def update_version():
16+
def from_git():
1717
"""Try to get the version from Git tags."""
1818
working = Path().absolute()
1919
try:
@@ -64,7 +64,7 @@ def find_repo_root(start_path: Path) -> Path | None:
6464
if not version and not is_mobile():
6565
# Only try to get the version from Git if the pre-set version is empty
6666
# This is more likely to happen in a development/source environment
67-
version = update_version() or DEFAULT_VERSION # Fallback to a default if Git fails
67+
version = from_git() or DEFAULT_VERSION # Fallback to a default if Git fails
6868

6969
# If 'version' is still empty after the above (e.g., in a built package
7070
# where CI didn't replace it), it might be appropriate to have another

0 commit comments

Comments
 (0)