Skip to content

Commit

Permalink
pw_env_setup: Fix banner printing on Windows
Browse files Browse the repository at this point in the history
- Fix colors load import error when runnning activate.bat on windows.
- Load PW_BRANDING_BANNER if it exist in windows_env_start.py
- Always load the branding banner files as utf-8

Bug: b/289008307
Change-Id: Ifada33d65da7cb152172197baedb15f97a09eb5b
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/169172
Commit-Queue: Auto-Submit <[email protected]>
Reviewed-by: Armando Montanez <[email protected]>
Pigweed-Auto-Submit: Anthony DiGirolamo <[email protected]>
  • Loading branch information
AnthonyDiGirolamo authored and CQ Bot Account committed Sep 2, 2023
1 parent b3717b1 commit 9514d6a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pw_cli/py/pw_cli/branding.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def banner() -> str:
# Take the banner from the file PW_BRANDING_BANNER; or use the default.
banner_filename = parsed_env.PW_BRANDING_BANNER
_memoized_banner = (
Path(banner_filename).read_text()
Path(banner_filename).read_text(encoding='utf-8', errors='replace')
if banner_filename
else _PIGWEED_BANNER
)
Expand Down
23 changes: 21 additions & 2 deletions pw_env_setup/py/pw_env_setup/windows_env_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@
import os
import sys

from .colors import Color, enable_colors # type: ignore
try:
from pw_env_setup.colors import Color, enable_colors
except ImportError:
# Load from this directory if pw_env_setup is not available.
from colors import Color, enable_colors # type: ignore


_PIGWEED_BANNER = u'''
▒█████▄ █▓ ▄███▒ ▒█ ▒█ ░▓████▒ ░▓████▒ ▒▓████▄
Expand All @@ -42,7 +47,21 @@ def print_banner(bootstrap, no_shell_file):
enable_colors()

print(Color.green('\n WELCOME TO...'))
print(Color.magenta(_PIGWEED_BANNER))

banner_file = os.environ.get('PW_BRANDING_BANNER', None)
banner_str = None
if banner_file:
try:
banner_str = open(
banner_file, 'r', encoding='utf-8', errors='replace'
).read()
except FileNotFoundError:
pass
if banner_str:
print()
print(banner_str, end='')
else:
print(Color.magenta(_PIGWEED_BANNER), end='')

if bootstrap:
print(
Expand Down

0 comments on commit 9514d6a

Please sign in to comment.