pw_protobuf_compiler: Don't require pw_cli

Since generate_protos.py might be run during the GN Python installation
process, it shouldn't depend on Python packages having been installed.

Change-Id: I898f501f9f84414dd118b5785f7f78412257fe7a
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/27181
Reviewed-by: Rob Mohr <mohrr@google.com>
Reviewed-by: Alexei Frolov <frolv@google.com>
Commit-Queue: Wyatt Hepler <hepler@google.com>
diff --git a/pw_protobuf_compiler/py/pw_protobuf_compiler/generate_protos.py b/pw_protobuf_compiler/py/pw_protobuf_compiler/generate_protos.py
index 0b2bbb8..5c07d2c 100644
--- a/pw_protobuf_compiler/py/pw_protobuf_compiler/generate_protos.py
+++ b/pw_protobuf_compiler/py/pw_protobuf_compiler/generate_protos.py
@@ -17,13 +17,18 @@
 import logging
 import os
 from pathlib import Path
+import subprocess
 import sys
 import tempfile
 
 from typing import Callable, Dict, List, Optional
 
-import pw_cli.log
-import pw_cli.process
+# Make sure dependencies are optional, since this script may be run when
+# installing Python package dependencies through GN.
+try:
+    from pw_cli.log import install as setup_logging
+except ImportError:
+    from logging import basicConfig as setup_logging  # type: ignore
 
 _LOG = logging.getLogger(__name__)
 
@@ -158,23 +163,28 @@
             _LOG.debug('Using generated plugin wrapper %s', args.plugin_path)
 
     try:
-        process = pw_cli.process.run(
-            'protoc',
-            f'-I{args.module_path}',
-            *include_paths,
-            *DEFAULT_PROTOC_ARGS[args.language](args),
-            *args.protos,
+        process = subprocess.run(
+            [
+                'protoc',
+                f'-I{args.module_path}',
+                *include_paths,
+                *DEFAULT_PROTOC_ARGS[args.language](args),
+                *args.protos,
+            ],
+            stdout=subprocess.PIPE,
+            stderr=subprocess.STDOUT,
         )
     finally:
         if wrapper_script:
             wrapper_script.unlink()
 
     if process.returncode != 0:
-        print(process.output.decode(), file=sys.stderr)
+        sys.stderr.buffer.write(process.stdout)
+        sys.stderr.flush()
 
     return process.returncode
 
 
 if __name__ == '__main__':
-    pw_cli.log.install()
+    setup_logging()
     sys.exit(main())