pw_cli: Ignore PW_PLUGINS outside of project

Ignore PW_PLUGINS outside of PW_PROJECT_ROOT. This suppresses errors
when a Pigweed submodule has been bootstrapped inside a larger project
also using Pigweed.

Change-Id: I125216be72a3fc06b922f6c70d92c3459574e506
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/36200
Pigweed-Auto-Submit: Rob Mohr <mohrr@google.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
Reviewed-by: Wyatt Hepler <hepler@google.com>
diff --git a/pw_cli/py/pw_cli/plugins.py b/pw_cli/py/pw_cli/plugins.py
index 687dd01..09ea5d5 100644
--- a/pw_cli/py/pw_cli/plugins.py
+++ b/pw_cli/py/pw_cli/plugins.py
@@ -18,6 +18,7 @@
 import importlib
 import inspect
 import logging
+import os
 from pathlib import Path
 import sys
 from textwrap import TextWrapper
@@ -231,6 +232,13 @@
         if not path.is_file():
             continue
 
+        root = Path(os.environ.get('PW_PROJECT_ROOT', '')).resolve()
+        if root not in path.parents:
+            _LOG.debug(
+                "Skipping plugins file %s because it's outside of "
+                'PW_PROJECT_ROOT (%s)', path, root)
+            continue
+
         _LOG.debug('Found plugins file %s', path)
         _sources.append(path)