Skip to content

Commit 827607c

Browse files
author
Mykhailo Androsiuk
committed
Defer pyftdi import: only import when --cpld option is used
Previously, the pyftdi module was imported unconditionally, causing errors even when CPLD functionality was not required. Now the import is performed only if the `--cpld` option is used, avoiding unnecessary failures and improving script flexibility. Signed-off-by: Mykhailo Androsiuk <mykhailo_androsiuk@epam.com>
1 parent c60ae14 commit 827607c

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

rcar_flash/rcar_flash.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,14 @@ def do_flash(conf, args):
197197
if "cpld_profile" not in board:
198198
raise Exception(
199199
"'cpld_profile' is not set for board, can't control CPLD")
200+
if args.cpld:
201+
try:
202+
import pyftdi # noqa: F401
203+
except ModuleNotFoundError:
204+
raise Exception(
205+
"pyftdi module is required for CPLD usage but not found.\n"
206+
"Please install it via 'pip3 install --user pyftdi' or appropriate package manager."
207+
)
200208

201209
# Force enable uploading flash_writer, otherwise it have no sense
202210
# to use CPLD
@@ -381,19 +389,6 @@ def get_srec_load_addr(fname):
381389
raise Exception(f"Could not read srec load address (S3) from {fname}")
382390

383391

384-
# CPLD Code begins there
385-
try:
386-
import pyftdi
387-
cpld_available = True
388-
except ModuleNotFoundError:
389-
log.error("pyftdi module not found. CPLD Functinality is disabled.")
390-
log.error(" Please install the module.")
391-
log.error(" You can try \"pip3 install --user pyftdi\"")
392-
log.error(
393-
" Or use your favourite packet manager (\"apt install python3-ftdi\" perhaps?)"
394-
)
395-
396-
397392
def cpld_determine_serial(cpld_profile, args) -> str:
398393
import pyftdi.usbtools
399394
# Try to determine USB device serial number where CPLD resides

0 commit comments

Comments
 (0)