Skip to content

Commit

Permalink
add a fallback for the 'coloredlogs' import in 'codegen.py' (#23411)
Browse files Browse the repository at this point in the history
  • Loading branch information
mukifera authored and pull[bot] committed Jan 9, 2024
1 parent 5aaba6a commit 3c4e8e9
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions scripts/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@

import click
import logging
import coloredlogs
import enum
import sys

try:
import coloredlogs
_has_coloredlogs = True
except:
_has_coloredlogs = False

try:
from idl.matter_idl_parser import CreateParser
except:
Expand Down Expand Up @@ -94,8 +99,16 @@ def main(log_level, generator, output_dir, dry_run, name_only, expected_outputs,
Parses MATTER IDL files (.matter) and performs SDK code generation
as set up by the program arguments.
"""
coloredlogs.install(level=__LOG_LEVELS__[
log_level], fmt='%(asctime)s %(levelname)-7s %(message)s')
if _has_coloredlogs:
coloredlogs.install(level=__LOG_LEVELS__[
log_level], fmt='%(asctime)s %(levelname)-7s %(message)s')
else:
logging.basicConfig(
level=__LOG_LEVELS__[log_level],
format='%(asctime)s %(levelname)-7s %(message)s',
datefmt='%Y-%m-%d %H:%M:%S'
)

logging.info("Parsing idl from %s" % idl_path)
idl_tree = CreateParser().parse(open(idl_path, "rt").read())

Expand Down

0 comments on commit 3c4e8e9

Please sign in to comment.