Skip to content

Commit

Permalink
replace is_windows() function with attribute in mlog
Browse files Browse the repository at this point in the history
  • Loading branch information
bruchar1 committed Jan 29, 2025
1 parent c2f762d commit 93c19fa
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions mesonbuild/mlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@
TV_Loggable = T.Union[str, 'AnsiDecorator', StringProtocol]
TV_LoggableList = T.List[TV_Loggable]

def is_windows() -> bool:
platname = platform.system().lower()
return platname == 'windows'

def _windows_ansi() -> bool:
# windll only exists on windows, so mypy will get mad
from ctypes import windll, byref # type: ignore
Expand Down Expand Up @@ -77,6 +73,8 @@ class _Logger:

_LOG_FNAME: T.ClassVar[str] = 'meson-log.txt'

is_windows = platform.system().lower() == 'windows'

@contextmanager
def no_logging(self) -> T.Iterator[None]:
self.log_disable_stdout = True
Expand Down Expand Up @@ -121,7 +119,7 @@ def start_pager(self) -> None:
pager_cmd = shlex.split(os.environ['PAGER'])
else:
less = shutil.which('less')
if not less and is_windows():
if not less and self.is_windows:
git = shutil.which('git')
if git:
path = Path(git).parents[1] / 'usr' / 'bin'
Expand Down Expand Up @@ -388,7 +386,7 @@ def colorize_console(self) -> bool:
if _colorize_console is not None:
return _colorize_console
try:
if is_windows():
if self.is_windows:
_colorize_console = os.isatty(output.fileno()) and _windows_ansi()
else:
_colorize_console = os.isatty(output.fileno()) and os.environ.get('TERM', 'dumb') != 'dumb'
Expand All @@ -402,7 +400,7 @@ def setup_console(self) -> None:
# connected to stdout and turn off ANSI escape processing. Call this after
# running a subprocess to ensure we turn it on again.
output = sys.stderr if self.log_to_stderr else sys.stdout
if is_windows():
if self.is_windows:
try:
delattr(output, 'colorize_console')
except AttributeError:
Expand Down

0 comments on commit 93c19fa

Please sign in to comment.