Repository: cloud-custodian/cloud-custodian

Issue:
cli version --debug includes dependency package versions
Atm `custodian version --debug` includes the custodian version, python info, sys info, and python path setup. we should include the versions of all dependent packages using the generate_requirements functionality in c7n/mu. additionally it would be nice for anything installed from vcs to include the vcs reference (ie sha / branch), we had used setuptools_scm on trunk for a bit to provide for that but thats going away with the poetry integration.



Discussion:

Resolving patch:
diff --git a/c7n/commands.py b/c7n/commands.py
--- a/c7n/commands.py
+++ b/c7n/commands.py
@@ -19,7 +19,6 @@
 import inspect
 import logging
 import os
-import pprint
 import sys
 
 import six
@@ -554,13 +553,14 @@ def metrics_cmd(options, policies):
 
 def version_cmd(options):
     from c7n.version import version
+    from c7n.resources import load_available
+    from c7n.mu import generate_requirements
 
     if not options.debug:
         print(version)
         return
 
     indent = 13
-    pp = pprint.PrettyPrinter(indent=indent)
 
     print("\nPlease copy/paste the following info along with any bug reports:\n")
     print("Custodian:  ", version)
@@ -571,9 +571,21 @@ def version_cmd(options):
         print("Platform:   ", os.uname())
     except Exception:  # pragma: no cover
         print("Platform:  ", sys.platform)
-    print("Using venv: ", hasattr(sys, 'real_prefix'))
 
+    is_venv = (
+        hasattr(sys, 'real_prefix') or
+        (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix))
+    print("Using venv: ", is_venv)
     in_container = os.path.exists('/.dockerenv')
     print("Docker: %s" % str(bool(in_container)))
-    print("PYTHONPATH: ")
-    pp.pprint(sys.path)
+    print("Installed: \n")
+
+    packages = ['c7n']
+    found = load_available(resources=False)
+    if 'gcp' in found:
+        packages.append('c7n_gcp')
+    if 'azure' in found:
+        packages.append('c7n_azure')
+    if 'k8s' in found:
+        packages.append('c7n_kube')
+    print(generate_requirements(packages))
diff --git a/c7n/resources/__init__.py b/c7n/resources/__init__.py
--- a/c7n/resources/__init__.py
+++ b/c7n/resources/__init__.py
@@ -51,7 +51,7 @@ def should_load_provider(name, provider_types):
     return False
 
 
-def load_available():
+def load_available(resources=True):
     """Load available installed providers
 
     Unlike load_resources() this will catch ImportErrors on uninstalled
@@ -65,7 +65,9 @@ def load_available():
             continue
         else:
             found.append(provider)
-    load_resources(['%s.*' % s for s in found])
+    if resources:
+        load_resources(['%s.*' % s for s in found])
+    return found
 
 
 def load_providers(provider_types):


Test patch:
diff --git a/tests/test_cli.py b/tests/test_cli.py
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -105,12 +105,9 @@ def test_version(self):
 
     def test_debug_version(self):
         output = self.get_output(["custodian", "version", "--debug"])
-        # Among other things, this should print sys.path
-        # Normalize double escaped backslashes for Windows
-        output = output.replace('\\\\', '\\')
-
         self.assertIn(version.version, output)
-        self.assertIn(sys.path[0], output)
+        self.assertIn('botocore==', output)
+        self.assertIn('python-dateutil==', output)
 
 
 class ValidateTest(CliTest):