Repository: conda/conda

Issue:
conda info --json and package lookup
If you set the `--json` flag for `conda info` when searching for packages, you sometimes get nothing:

``` bash
$ conda info numpy=1.11.0=py35_0
Fetching package metadata: ....

numpy 1.11.0 py35_0
-------------------
file name   : numpy-1.11.0-py35_0.tar.bz2
name        : numpy
version     : 1.11.0
build number: 0
build string: py35_0
channel     : defaults
size        : 6.1 MB
date        : 2016-03-28
license     : BSD
md5         : 1900998c19c5e310687013f95374bba2
installed environments:
dependencies:
    mkl 11.3.1
    python 3.5*
$ conda info --json numpy=1.11.0=py35_0
{}
```

Things work fine for `conda info --json numpy`, so it's something with the spec format.

conda info:

```
             platform : linux-64
        conda version : 4.0.5
  conda-build version : not installed
       python version : 2.7.11.final.0
     requests version : 2.9.1
     root environment : /opt/conda  (writable)
  default environment : /opt/conda
     envs directories : /opt/conda/envs
        package cache : /opt/conda/pkgs
         channel URLs : https://repo.continuum.io/pkgs/free/linux-64/
                        https://repo.continuum.io/pkgs/free/noarch/
                        https://repo.continuum.io/pkgs/pro/linux-64/
                        https://repo.continuum.io/pkgs/pro/noarch/
          config file : None
    is foreign system : False
```



Discussion:

Resolving patch:
diff --git a/conda/cli/main_info.py b/conda/cli/main_info.py
--- a/conda/cli/main_info.py
+++ b/conda/cli/main_info.py
@@ -148,7 +148,7 @@ def execute(args, parser):
     import conda.config as config
     from conda.resolve import Resolve
     from conda.cli.main_init import is_initialized
-    from conda.api import get_index, get_package_versions
+    from conda.api import get_index
 
     if args.root:
         if args.json:
@@ -158,21 +158,19 @@ def execute(args, parser):
         return
 
     if args.packages:
-        if args.json:
-            results = defaultdict(list)
-            for arg in args.packages:
-                for pkg in get_package_versions(arg):
-                    results[arg].append(pkg._asdict())
-            common.stdout_json(results)
-            return
         index = get_index()
         r = Resolve(index)
-        specs = map(common.arg2spec, args.packages)
-
-        for spec in specs:
-            versions = r.get_pkgs(spec)
-            for pkg in sorted(versions):
-                pretty_package(pkg)
+        if args.json:
+            common.stdout_json({
+                package: [p._asdict()
+                          for p in sorted(r.get_pkgs(common.arg2spec(package)))]
+                for package in args.packages
+            })
+        else:
+            for package in args.packages:
+                versions = r.get_pkgs(common.arg2spec(package))
+                for pkg in sorted(versions):
+                    pretty_package(pkg)
         return
 
     options = 'envs', 'system', 'license'


Test patch:
diff --git a/tests/test_info.py b/tests/test_info.py
--- a/tests/test_info.py
+++ b/tests/test_info.py
@@ -1,6 +1,8 @@
 from __future__ import print_function, absolute_import, division
+import json
 
 from conda import config
+from conda.cli import main_info
 
 from tests.helpers import run_conda_command, assert_in, assert_equals
 
@@ -32,3 +34,21 @@ def test_info():
     assert_in(conda_info_out, conda_info_all_out)
     assert_in(conda_info_e_out, conda_info_all_out)
     assert_in(conda_info_s_out, conda_info_all_out)
+
+
+def test_info_package_json():
+    out, err = run_conda_command("info", "--json", "numpy=1.11.0=py35_0")
+    assert err == ""
+
+    out = json.loads(out)
+    assert set(out.keys()) == {"numpy=1.11.0=py35_0"}
+    assert len(out["numpy=1.11.0=py35_0"]) == 1
+    assert isinstance(out["numpy=1.11.0=py35_0"], list)
+
+    out, err = run_conda_command("info", "--json", "numpy")
+    assert err == ""
+
+    out = json.loads(out)
+    assert set(out.keys()) == {"numpy"}
+    assert len(out["numpy"]) > 1
+    assert isinstance(out["numpy"], list)