pw_protobuf_compiler: Make pw_cli import optional

Makes pw_cli import optional so the proto_target_invalid.py build error
template can work in early parts of the build.

Change-Id: I45a95b1533045c60f553cb90005bd409b1058536
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/106712
Pigweed-Auto-Submit: Armando Montanez <amontanez@google.com>
Reviewed-by: Anthony DiGirolamo <tonymd@google.com>
Commit-Queue: Armando Montanez <amontanez@google.com>
diff --git a/pw_protobuf_compiler/py/pw_protobuf_compiler/proto_target_invalid.py b/pw_protobuf_compiler/py/pw_protobuf_compiler/proto_target_invalid.py
index 72894b4..48c16e9 100644
--- a/pw_protobuf_compiler/py/pw_protobuf_compiler/proto_target_invalid.py
+++ b/pw_protobuf_compiler/py/pw_protobuf_compiler/proto_target_invalid.py
@@ -19,9 +19,6 @@
 
 from typing import Optional
 
-from pw_cli.color import colors
-import pw_cli.log
-
 _LOG = logging.getLogger(__name__)
 
 
@@ -52,7 +49,7 @@
 
     _LOG.error('')
     _LOG.error('The target %s is not a compiled protobuf library.',
-               colors().bold_white(args.target))
+               args.target)
     _LOG.error('')
     _LOG.error('A different target is generated for each active generator.')
     _LOG.error('Depend on one of the following targets instead:')
@@ -65,5 +62,13 @@
 
 
 if __name__ == '__main__':
-    pw_cli.log.install()
+    try:
+        # If pw_cli is available, use it to initialize logs.
+        from pw_cli import log
+
+        log.install(logging.INFO)
+    except ImportError:
+        # If pw_cli isn't available, display log messages like a simple print.
+        logging.basicConfig(format='%(message)s', level=logging.INFO)
+
     sys.exit(main())