Repository: conda/conda

Issue:
Add --json flag on conda-env that works!
The json flag seems to be there, but it is not working.

With a file that looks like

```yaml
# environment.yaml
name: test_env_1
channels:
- defaults
dependencies:
- python
- pytest-cov
```

```
(root) $ conda-env create --json
Using Anaconda API: http s://api.anaconda.org
(root) $
```

So two problems here:
1.) No json output on the create process
2.) `Using Anaconda API: https://api.anaconda.org`


Discussion:

Resolving patch:
diff --git a/conda/cli/main.py b/conda/cli/main.py
--- a/conda/cli/main.py
+++ b/conda/cli/main.py
@@ -80,12 +80,24 @@ def generate_parser():
     return p, sub_parsers
 
 
+def init_loggers(context):
+    from ..gateways.logging import set_all_logger_level, set_verbosity
+    if not context.json:
+        # Silence logging info to avoid interfering with JSON output
+        for logger in ('print', 'dotupdate', 'stdoutlog', 'stderrlog'):
+            getLogger(logger).setLevel(CRITICAL + 1)
+
+    if context.debug:
+        set_all_logger_level(DEBUG)
+    elif context.verbosity:
+        set_verbosity(context.verbosity)
+        log.debug("verbosity set to %s", context.verbosity)
+
+
 def _main(*args):
     from ..base.constants import SEARCH_PATH
     from ..base.context import context
 
-    from ..gateways.logging import set_all_logger_level, set_verbosity
-
     if len(args) == 1:
         args = args + ('-h',)
 
@@ -119,17 +131,7 @@ def completer(prefix, **kwargs):
     args = p.parse_args(args)
 
     context.__init__(SEARCH_PATH, 'conda', args)
-
-    if getattr(args, 'json', False):
-        # Silence logging info to avoid interfering with JSON output
-        for logger in ('print', 'dotupdate', 'stdoutlog', 'stderrlog'):
-            getLogger(logger).setLevel(CRITICAL + 1)
-
-    if context.debug:
-        set_all_logger_level(DEBUG)
-    elif context.verbosity:
-        set_verbosity(context.verbosity)
-        log.debug("verbosity set to %s", context.verbosity)
+    init_loggers(context)
 
     exit_code = args.func(args, p)
     if isinstance(exit_code, int):
diff --git a/conda_env/cli/main.py b/conda_env/cli/main.py
--- a/conda_env/cli/main.py
+++ b/conda_env/cli/main.py
@@ -1,10 +1,13 @@
-from __future__ import print_function, division, absolute_import
-
-from logging import getLogger, CRITICAL
+from __future__ import absolute_import, division, print_function
 
 import os
 import sys
 
+from conda.base.constants import SEARCH_PATH
+from conda.base.context import context
+from conda.cli.conda_argparse import ArgumentParser
+from conda.cli.main import init_loggers
+
 try:
     from conda.exceptions import conda_exception_handler
 except ImportError as e:
@@ -30,8 +33,6 @@
     else:
         raise e
 
-from conda.cli.conda_argparse import ArgumentParser
-
 from . import main_attach
 from . import main_create
 from . import main_export
@@ -39,7 +40,7 @@
 from . import main_remove
 from . import main_upload
 from . import main_update
-from conda.base.context import context
+
 
 # TODO: This belongs in a helper library somewhere
 # Note: This only works with `conda-env` as a sub-command.  If this gets
@@ -68,15 +69,8 @@ def create_parser():
 def main():
     parser = create_parser()
     args = parser.parse_args()
-    context._set_argparse_args(args)
-    if getattr(args, 'json', False):
-        # # Silence logging info to avoid interfering with JSON output
-        # for logger in Logger.manager.loggerDict:
-        #     if logger not in ('fetch', 'progress'):
-        #         getLogger(logger).setLevel(CRITICAL + 1)
-        for logger in ('print', 'dotupdate', 'stdoutlog', 'stderrlog'):
-            getLogger(logger).setLevel(CRITICAL + 1)
-
+    context.__init__(SEARCH_PATH, 'conda', args)
+    init_loggers(context)
     return conda_exception_handler(args.func, args, parser)
 
 
diff --git a/conda_env/cli/main_export.py b/conda_env/cli/main_export.py
--- a/conda_env/cli/main_export.py
+++ b/conda_env/cli/main_export.py
@@ -4,7 +4,7 @@
 import os
 import textwrap
 
-from conda.cli.common import add_parser_prefix
+from conda.cli.common import add_parser_json, add_parser_prefix
 # conda env import
 from .common import get_prefix
 from ..env import from_environment
@@ -63,7 +63,7 @@ def configure_parser(sub_parsers):
         action='store_true',
         required=False,
         help='Do not include channel names with package names.')
-
+    add_parser_json(p)
     p.set_defaults(func=execute)
 
 


Test patch:
diff --git a/tests/test_create.py b/tests/test_create.py
--- a/tests/test_create.py
+++ b/tests/test_create.py
@@ -65,6 +65,18 @@
 except ImportError:
     from mock import patch
 
+
+def get_win_locations():
+    try:
+        from menuinst.win32 import dirs_src as win_locations
+    except ImportError:
+        try:
+            from menuinst.win32 import dirs as win_locations
+        except ImportError:
+            win_locations = {}
+    return win_locations
+
+
 log = getLogger(__name__)
 TRACE, DEBUG = TRACE, DEBUG  # these are so the imports aren't cleared, but it's easy to switch back and forth
 TEST_LOG_LEVEL = DEBUG
@@ -623,7 +635,7 @@ def test_update_deps_flag_present(self):
     @pytest.mark.skipif(not on_win, reason="shortcuts only relevant on Windows")
     def test_shortcut_not_attempted_with_no_shortcuts_arg(self):
         prefix = make_temp_prefix("_" + str(uuid4())[:7])
-        from menuinst.win32 import dirs as win_locations
+        win_locations = get_win_locations()
         user_mode = 'user' if exists(join(sys.prefix, u'.nonadmin')) else 'system'
         shortcut_dir = win_locations[user_mode]["start"]
         shortcut_file = join(shortcut_dir, "Anaconda Prompt ({0}).lnk".format(basename(prefix)))
@@ -636,7 +648,7 @@ def test_shortcut_not_attempted_with_no_shortcuts_arg(self):
 
     @pytest.mark.skipif(not on_win, reason="shortcuts only relevant on Windows")
     def test_shortcut_creation_installs_shortcut(self):
-        from menuinst.win32 import dirs as win_locations
+        win_locations = get_win_locations()
         user_mode = 'user' if exists(join(sys.prefix, u'.nonadmin')) else 'system'
         shortcut_dir = win_locations[user_mode]["start"]
         shortcut_dir = join(shortcut_dir, "Anaconda{0} ({1}-bit)"
@@ -662,7 +674,7 @@ def test_shortcut_creation_installs_shortcut(self):
 
     @pytest.mark.skipif(not on_win, reason="shortcuts only relevant on Windows")
     def test_shortcut_absent_does_not_barf_on_uninstall(self):
-        from menuinst.win32 import dirs as win_locations
+        win_locations = get_win_locations()
 
         user_mode = 'user' if exists(join(sys.prefix, u'.nonadmin')) else 'system'
         shortcut_dir = win_locations[user_mode]["start"]
@@ -690,7 +702,7 @@ def test_shortcut_absent_does_not_barf_on_uninstall(self):
 
     @pytest.mark.skipif(not on_win, reason="shortcuts only relevant on Windows")
     def test_shortcut_absent_when_condarc_set(self):
-        from menuinst.win32 import dirs as win_locations
+        win_locations = get_win_locations()
         user_mode = 'user' if exists(join(sys.prefix, u'.nonadmin')) else 'system'
         shortcut_dir = win_locations[user_mode]["start"]
         shortcut_dir = join(shortcut_dir, "Anaconda{0} ({1}-bit)"