Repository: conda/conda

Issue:
unexpected issue
Uncaught Exception:
Error: Conda command "info" failed:
command: conda info,--json
output: An unexpected error has occurred.
Please consider posting the following information to the
conda GitHub issue tracker at:

    https://github.com/conda/conda/issues



`$ /Users/tasalta/anaconda/bin/conda info --json`




    Traceback (most recent call last):
      File "/Users/tasalta/anaconda/lib/python2.7/site-packages/conda/exceptions.py", line 573, in conda_exception_handler
        return_value = func(*args, **kwargs)
      File "/Users/tasalta/anaconda/lib/python2.7/site-packages/conda/cli/main.py", line 98, in _main
        imported = importlib.import_module(module)
      File "/Users/tasalta/anaconda/lib/python2.7/importlib/__init__.py", line 37, in import_module
        __import__(name)
      File "/Users/tasalta/anaconda/lib/python2.7/site-packages/conda/cli/main_list.py", line 20, in <module>
        from ..egg_info import get_egg_info
      File "/Users/tasalta/anaconda/lib/python2.7/site-packages/conda/egg_info.py", line 15, in <module>
        from .misc import rel_path
      File "/Users/tasalta/anaconda/lib/python2.7/site-packages/conda/misc.py", line 19, in <module>
        from .core.index import get_index, _supplement_index_with_cache
      File "/Users/tasalta/anaconda/lib/python2.7/site-packages/conda/core/index.py", line 9, in <module>
        from .repodata import collect_all_repodata
      File "/Users/tasalta/anaconda/lib/python2.7/site-packages/conda/core/repodata.py", line 21, in <module>
        from requests.packages.urllib3.exceptions import InsecureRequestWarning
    ImportError: cannot import name InsecureRequestWarning


    at throwCondaError (/Applications/GraphLab Create Launcher.app/Contents/Resources/app.asar/utils/conda.js:117:9)
    at runConda (/Applications/GraphLab Create Launcher.app/Contents/Resources/app.asar/utils/conda.js:146:5)
    at Object.info (/Applications/GraphLab Create Launcher.app/Contents/Resources/app.asar/utils/conda.js:395:10)
    at Object.isGLCLauncherReady (/Applications/GraphLab Create Launcher.app/Contents/Resources/app.asar/utils/systemState.js:207:27)
    at [object Object].onWindowOpen [as _onTimeout] (/Applications/GraphLab Create Launcher.app/Contents/Resources/app.asar/main.js:144:57)
    at Timer.listOnTimeout (timers.js:89:15)


Discussion:

Resolving patch:
diff --git a/conda/cli/main_list.py b/conda/cli/main_list.py
--- a/conda/cli/main_list.py
+++ b/conda/cli/main_list.py
@@ -11,15 +11,6 @@
 from os.path import isdir, isfile
 import re
 
-from .common import (add_parser_help, add_parser_json, add_parser_prefix,
-                     add_parser_show_channel_urls, disp_features, stdout_json)
-from ..base.constants import DEFAULTS_CHANNEL_NAME, UNKNOWN_CHANNEL
-from ..base.context import context
-from ..common.compat import text_type
-from ..core.linked_data import is_linked, linked, linked_data
-from ..egg_info import get_egg_info
-from ..exceptions import CondaEnvironmentNotFoundError, CondaFileNotFoundError
-
 descr = "List linked packages in a conda environment."
 
 # Note, the formatting of this is designed to work well with help2man
@@ -46,6 +37,9 @@
 log = logging.getLogger(__name__)
 
 def configure_parser(sub_parsers):
+    from .common import (add_parser_help, add_parser_json, add_parser_prefix,
+                         add_parser_show_channel_urls)
+
     p = sub_parsers.add_parser(
         'list',
         description=descr,
@@ -105,10 +99,10 @@ def configure_parser(sub_parsers):
     p.set_defaults(func=execute)
 
 
-def print_export_header():
+def print_export_header(subdir):
     print('# This file may be used to create an environment using:')
     print('# $ conda create --name <env> --file <this file>')
-    print('# platform: %s' % context.subdir)
+    print('# platform: %s' % subdir)
 
 
 def get_packages(installed, regex):
@@ -122,7 +116,11 @@ def get_packages(installed, regex):
 
 
 def list_packages(prefix, installed, regex=None, format='human',
-                  show_channel_urls=context.show_channel_urls):
+                  show_channel_urls=None):
+    from .common import disp_features
+    from ..base.constants import DEFAULTS_CHANNEL_NAME
+    from ..base.context import context
+    from ..core.linked_data import is_linked
     res = 0
     result = []
     for dist in get_packages(installed, regex):
@@ -140,6 +138,7 @@ def list_packages(prefix, installed, regex=None, format='human',
             disp = '%(name)-25s %(version)-15s %(build)15s' % info
             disp += '  %s' % disp_features(features)
             schannel = info.get('schannel')
+            show_channel_urls = show_channel_urls or context.show_channel_urls
             if (show_channel_urls or show_channel_urls is None
                     and schannel != DEFAULTS_CHANNEL_NAME):
                 disp += '  %s' % schannel
@@ -152,8 +151,15 @@ def list_packages(prefix, installed, regex=None, format='human',
 
 
 def print_packages(prefix, regex=None, format='human', piplist=False,
-                   json=False, show_channel_urls=context.show_channel_urls):
+                   json=False, show_channel_urls=None):
+    from .common import stdout_json
+    from ..base.context import context
+    from ..common.compat import text_type
+    from ..core.linked_data import linked
+    from ..egg_info import get_egg_info
+
     if not isdir(prefix):
+        from ..exceptions import CondaEnvironmentNotFoundError
         raise CondaEnvironmentNotFoundError(prefix)
 
     if not json:
@@ -161,7 +167,7 @@ def print_packages(prefix, regex=None, format='human', piplist=False,
             print('# packages in environment at %s:' % prefix)
             print('#')
         if format == 'export':
-            print_export_header()
+            print_export_header(context.subdir)
 
     installed = linked(prefix)
     log.debug("installed conda packages:\n%s", installed)
@@ -180,9 +186,13 @@ def print_packages(prefix, regex=None, format='human', piplist=False,
 
 
 def print_explicit(prefix, add_md5=False):
+    from ..base.constants import UNKNOWN_CHANNEL
+    from ..base.context import context
+    from ..core.linked_data import linked_data
     if not isdir(prefix):
+        from ..exceptions import CondaEnvironmentNotFoundError
         raise CondaEnvironmentNotFoundError(prefix)
-    print_export_header()
+    print_export_header(context.subdir)
     print("@EXPLICIT")
     for meta in sorted(linked_data(prefix).values(), key=lambda x: x['name']):
         url = meta.get('url')
@@ -194,6 +204,8 @@ def print_explicit(prefix, add_md5=False):
 
 
 def execute(args, parser):
+    from ..base.context import context
+    from .common import stdout_json
     prefix = context.prefix_w_legacy_search
     regex = args.regex
     if args.full_name:
@@ -208,6 +220,7 @@ def execute(args, parser):
             else:
                 stdout_json(h.object_log())
         else:
+            from ..exceptions import CondaFileNotFoundError
             raise CondaFileNotFoundError(h.path)
         return
 


Test patch: