Skip to content

Commit f1a20e6

Browse files
mukiferaadbridge
authored andcommitted
add a fallback for the 'coloredlogs' import in 'codegen.py' (project-chip#23411)
1 parent 3dacdb8 commit f1a20e6

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

scripts/codegen.py

+16-3
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,15 @@
1515

1616
import click
1717
import logging
18-
import coloredlogs
1918
import enum
2019
import sys
2120

21+
try:
22+
import coloredlogs
23+
_has_coloredlogs = True
24+
except:
25+
_has_coloredlogs = False
26+
2227
try:
2328
from idl.matter_idl_parser import CreateParser
2429
except:
@@ -94,8 +99,16 @@ def main(log_level, generator, output_dir, dry_run, name_only, expected_outputs,
9499
Parses MATTER IDL files (.matter) and performs SDK code generation
95100
as set up by the program arguments.
96101
"""
97-
coloredlogs.install(level=__LOG_LEVELS__[
98-
log_level], fmt='%(asctime)s %(levelname)-7s %(message)s')
102+
if _has_coloredlogs:
103+
coloredlogs.install(level=__LOG_LEVELS__[
104+
log_level], fmt='%(asctime)s %(levelname)-7s %(message)s')
105+
else:
106+
logging.basicConfig(
107+
level=__LOG_LEVELS__[log_level],
108+
format='%(asctime)s %(levelname)-7s %(message)s',
109+
datefmt='%Y-%m-%d %H:%M:%S'
110+
)
111+
99112
logging.info("Parsing idl from %s" % idl_path)
100113
idl_tree = CreateParser().parse(open(idl_path, "rt").read())
101114

0 commit comments

Comments
 (0)