Make pyqrcode optional

This commit is contained in:
Ian McEwen
2024-12-12 21:01:38 -07:00
parent 31f322f1c2
commit d87eddfd33
3 changed files with 13 additions and 6 deletions

View File

@@ -13,7 +13,11 @@ import sys
import time
from typing import List, Optional
import pyqrcode # type: ignore[import-untyped]
try:
import pyqrcode # type: ignore[import-untyped]
except ImportError as e:
pyqrcode = None
import yaml
from google.protobuf.json_format import MessageToDict
from pubsub import pub # type: ignore[import-untyped]
@@ -896,8 +900,11 @@ def onConnected(interface):
else:
urldesc = "Primary channel URL"
print(f"{urldesc}: {url}")
qr = pyqrcode.create(url)
print(qr.terminal())
if pyqrcode is not None:
qr = pyqrcode.create(url)
print(qr.terminal())
else:
print("Install pyqrcode to view a QR code printed to terminal.")
log_set: Optional = None # type: ignore[annotation-unchecked]
# we need to keep a reference to the logset so it doesn't get GCed early