Skip to content

fix: skip running flutter doctor on windows if no_rich_output=True #4108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 22 additions & 27 deletions sdk/python/packages/flet-cli/src/flet_cli/commands/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from flet_core.utils import copy_tree, is_windows, slugify
from flet_core.utils.platform_utils import get_bool_env_var
from packaging import version
from rich import print
from rich.console import Console, Style
from rich.table import Column, Table

Expand Down Expand Up @@ -45,12 +44,14 @@ class Command(BaseCommand):
def __init__(self, parser: argparse.ArgumentParser) -> None:
super().__init__(parser)

self.no_rich_output = None
self.emojis = {}
self.dart_exe = None
self.verbose = False
self.build_dir = None
self.flutter_dir = None
self.flutter_dir: Optional[Path] = None
self.flutter_exe = None
self.current_platform = platform.system()
self.platforms = {
"windows": {
"package_platform": "Windows",
Expand Down Expand Up @@ -483,50 +484,48 @@ def add_arguments(self, parser: argparse.ArgumentParser) -> None:

def handle(self, options: argparse.Namespace) -> None:
self.verbose = options.verbose
self.flutter_dir: Optional[Path] = None

# get `flutter` and `dart` executables from PATH
self.flutter_exe = self.find_flutter_batch("flutter")
self.dart_exe = self.find_flutter_batch("dart")

if self.verbose > 1:
print("Flutter executable:", self.flutter_exe)
print("Dart executable:", self.dart_exe)
console.log("Flutter executable:", self.flutter_exe)
console.log("Dart executable:", self.dart_exe)

self.flutter_dir = None
no_rich_output = options.no_rich_output or get_bool_env_var(
self.no_rich_output = options.no_rich_output or get_bool_env_var(
"FLET_CLI_NO_RICH_OUTPUT"
)
self.emojis = {
"checkmark": "[green]OK[/]" if no_rich_output else "✅",
"loading": "" if no_rich_output else "⏳",
"success": "" if no_rich_output else "🥳",
"directory": "" if no_rich_output else "📁",
"checkmark": "[green]OK[/]" if self.no_rich_output else "✅",
"loading": "" if self.no_rich_output else "⏳",
"success": "" if self.no_rich_output else "🥳",
"directory": "" if self.no_rich_output else "📁",
}
target_platform = options.target_platform.lower()
# platform check
current_platform = platform.system()
if (
current_platform not in self.platforms[target_platform]["can_be_run_on"]
self.current_platform
not in self.platforms[target_platform]["can_be_run_on"]
or options.show_platform_matrix
):
can_build_message = (
"can't"
if current_platform
if self.current_platform
not in self.platforms[target_platform]["can_be_run_on"]
else "can"
)
# replace "Darwin" with "macOS" for user-friendliness
current_platform = (
"macOS" if current_platform == "Darwin" else current_platform
self.current_platform = (
"macOS" if self.current_platform == "Darwin" else self.current_platform
)
# highlight the current platform in the build matrix table
self.platform_matrix_table.rows[
list(self.platforms.keys()).index(target_platform)
].style = "bold red1"
console.log(self.platform_matrix_table)

message = f"You {can_build_message} build [cyan]{target_platform}[/] on [magenta]{current_platform}[/]."
message = f"You {can_build_message} build [cyan]{target_platform}[/] on [magenta]{self.current_platform}[/]."
self.cleanup(1, message)

with console.status(
Expand All @@ -535,14 +534,6 @@ def handle(self, options: argparse.Namespace) -> None:
) as self.status:
from cookiecutter.main import cookiecutter

# get `flutter` and `dart` executables from PATH
self.flutter_exe = self.find_flutter_batch("flutter")
self.dart_exe = self.find_flutter_batch("dart")

if self.verbose > 1:
console.log("Flutter executable:", self.flutter_exe)
console.log("Dart executable:", self.dart_exe)

package_platform = self.platforms[target_platform]["package_platform"]

python_app_path = Path(options.python_app_path).resolve()
Expand Down Expand Up @@ -1486,8 +1477,12 @@ def cleanup(
+ f"You have {flutter_version}."
)
console.log(flutter_msg, style=error_style)
# run flutter doctor
self.run_flutter_doctor(style=error_style)

# windows has been reported to raise encoding errors when running `flutter doctor`
# so skip running `flutter doctor` if no_rich_output is True and platform is Windows
if not (self.no_rich_output and self.current_platform == "Windows"):
self.run_flutter_doctor(style=error_style)

sys.exit(exit_code)

def run_flutter_doctor(self, style: Optional[Union[Style, str]] = None):
Expand Down