Skip to content
Merged
2 changes: 2 additions & 0 deletions src/lightning_app/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

- Fixed an issue where custom property setters were not being used `LightningWork` class. ([#14259](https://github.com/Lightning-AI/lightning/pull/14259))

- Fixed an issue where some terminals would display broken icons in the PL app CLI. ([#14226](https://github.com/Lightning-AI/lightning/issues/14226))


## [0.6.0] - 2022-09-08

Expand Down
12 changes: 12 additions & 0 deletions src/lightning_app/cli/cmd_pl_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import re
import shutil
import subprocess
import sys
import tarfile
import urllib.request
from pathlib import Path
Expand Down Expand Up @@ -149,10 +150,21 @@ def print_pretty_report(
text_pathname.append(f" {padding} {help_text}", "blue")

icon = "📂 " if path.is_dir() else "📄 "
icon = icon if _can_encode_icon(icon) else ""

tree.add(Text(icon) + text_pathname)

print("\n")
print("Done. The app is ready here:\n")
print(tree)
print("\nRun it:\n")
print(Panel(f"[red]lightning run app {directory.relative_to(Path.cwd()) / 'app.py'}"))


def _can_encode_icon(icon: str) -> bool:
"""Helper function to check whether an icon can be encoded."""
try:
icon.encode(sys.stdout.encoding)
return True
except UnicodeEncodeError:
return False
17 changes: 16 additions & 1 deletion tests/tests_app/cli/test_cmd_pl_init.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import os
import sys
from unittest import mock
from unittest.mock import Mock

import pytest
from click.testing import CliRunner

from lightning_app.cli import lightning_cli
from lightning_app.cli.cmd_pl_init import download_frontend, pl_app
from lightning_app.cli.cmd_pl_init import _can_encode_icon, download_frontend, pl_app


def test_pl_app_input_paths_do_not_exist(tmp_path):
Expand Down Expand Up @@ -84,6 +86,19 @@ def test_pl_app_download_frontend(tmp_path):
assert "static" in contents


def test_pl_app_encode_icon(monkeypatch):
stdout_mock = Mock(wraps=sys.stdout)
monkeypatch.setattr(sys, "stdout", stdout_mock)

stdout_mock.encoding = "utf-8"
assert _can_encode_icon("📂")
assert _can_encode_icon("📄")

stdout_mock.encoding = "ascii"
assert not _can_encode_icon("📂")
assert not _can_encode_icon("📄")


@pytest.mark.parametrize(
"cwd, source_dir, script_path",
[
Expand Down