We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN 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
```


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `conda/cli/main_info.py`
Content:
```
1 # (c) 2012-2013 Continuum Analytics, Inc. / http://continuum.io
2 # All Rights Reserved
3 #
4 # conda is distributed under the terms of the BSD 3-clause license.
5 # Consult LICENSE.txt or http://opensource.org/licenses/BSD-3-Clause.
6 
7 from __future__ import print_function, division, absolute_import
8 
9 import json
10 import os
11 import re
12 import sys
13 from collections import defaultdict, OrderedDict
14 from itertools import chain
15 from os import listdir
16 from os.path import exists, expanduser, join
17 
18 from conda.cli import common
19 from conda.compat import iteritems
20 
21 help = "Display information about current conda install."
22 
23 example = """
24 
25 Examples:
26 
27     conda info -a
28 """
29 
30 def configure_parser(sub_parsers):
31     p = sub_parsers.add_parser(
32         'info',
33         description=help,
34         help=help,
35         epilog=example,
36     )
37     common.add_parser_json(p)
38     p.add_argument(
39         '-a', "--all",
40         action="store_true",
41         help="Show all information, (environments, license, and system "
42              "information.")
43     p.add_argument(
44         '-e', "--envs",
45         action="store_true",
46         help="List all known conda environments.",
47     )
48     p.add_argument(
49         '-l', "--license",
50         action="store_true",
51         help="Display information about the local conda licenses list.",
52     )
53     p.add_argument(
54         '-s', "--system",
55         action="store_true",
56         help="List environment variables.",
57     )
58     p.add_argument(
59         'packages',
60         action="store",
61         nargs='*',
62         help="Display information about packages.",
63     )
64     p.add_argument(
65         '--root',
66         action='store_true',
67         help='Display root environment path.',
68     )
69     p.add_argument(
70         '--unsafe-channels',
71         action='store_true',
72         help='Display list of channels with tokens exposed.',
73     )
74     p.set_defaults(func=execute)
75 
76 
77 def show_pkg_info(name):
78     from conda.api import get_index
79     from conda.resolve import Resolve
80 
81     index = get_index()
82     r = Resolve(index)
83     print(name)
84     if name in r.groups:
85         for pkg in sorted(r.get_pkgs(name)):
86             print('    %-15s %15s  %s' % (
87                     pkg.version,
88                     pkg.build,
89                     common.disp_features(r.features(pkg.fn))))
90     else:
91         print('    not available')
92     # TODO
93 
94 
95 python_re = re.compile('python\d\.\d')
96 def get_user_site():
97     site_dirs = []
98     if sys.platform != 'win32':
99         if exists(expanduser('~/.local/lib')):
100             for path in listdir(expanduser('~/.local/lib/')):
101                 if python_re.match(path):
102                     site_dirs.append("~/.local/lib/%s" % path)
103     else:
104         if 'APPDATA' not in os.environ:
105             return site_dirs
106         APPDATA = os.environ['APPDATA']
107         if exists(join(APPDATA, 'Python')):
108             site_dirs = [join(APPDATA, 'Python', i) for i in
109                          listdir(join(APPDATA, 'PYTHON'))]
110     return site_dirs
111 
112 
113 def pretty_package(pkg):
114     import conda.config as config
115     from conda.utils import human_bytes
116 
117     d = OrderedDict([
118         ('file name', pkg.fn),
119         ('name', pkg.name),
120         ('version', pkg.version),
121         ('build number', pkg.build_number),
122         ('build string', pkg.build),
123         ('channel', config.canonical_channel_name(pkg.channel)),
124         ('size', human_bytes(pkg.info['size'])),
125         ])
126     rest = pkg.info
127     for key in sorted(rest):
128         if key in {'build', 'depends', 'requires', 'channel', 'name',
129                    'version', 'build_number', 'size'}:
130             continue
131         d[key] = rest[key]
132 
133     print()
134     header = "%s %s %s" % (d['name'], d['version'], d['build string'])
135     print(header)
136     print('-'*len(header))
137     for key in d:
138         print("%-12s: %s" % (key, d[key]))
139     print('dependencies:')
140     for dep in pkg.info['depends']:
141         print('    %s' % dep)
142 
143 def execute(args, parser):
144     import os
145     from os.path import dirname
146 
147     import conda
148     import conda.config as config
149     from conda.resolve import Resolve
150     from conda.cli.main_init import is_initialized
151     from conda.api import get_index, get_package_versions
152 
153     if args.root:
154         if args.json:
155             common.stdout_json({'root_prefix': config.root_dir})
156         else:
157             print(config.root_dir)
158         return
159 
160     if args.packages:
161         if args.json:
162             results = defaultdict(list)
163             for arg in args.packages:
164                 for pkg in get_package_versions(arg):
165                     results[arg].append(pkg._asdict())
166             common.stdout_json(results)
167             return
168         index = get_index()
169         r = Resolve(index)
170         specs = map(common.arg2spec, args.packages)
171 
172         for spec in specs:
173             versions = r.get_pkgs(spec)
174             for pkg in sorted(versions):
175                 pretty_package(pkg)
176         return
177 
178     options = 'envs', 'system', 'license'
179 
180     try:
181         import requests
182         requests_version = requests.__version__
183     except ImportError:
184         requests_version = "could not import"
185     except Exception as e:
186         requests_version = "Error %s" % e
187 
188     try:
189         import conda_build
190     except ImportError:
191         conda_build_version = "not installed"
192     except Exception as e:
193         conda_build_version = "Error %s" % e
194     else:
195         conda_build_version = conda_build.__version__
196 
197     # this is a hack associated with channel weight until we get the package cache reworked
198     #   in a future release
199     # for now, just ordering the channels for display in a semi-plausible way
200     d = defaultdict(list)
201     any(d[v[1]].append(k) for k, v in iteritems(config.get_channel_urls()))
202     channels = list(chain.from_iterable(d[q] for q in sorted(d, reverse=True)))
203 
204     info_dict = dict(
205         platform=config.subdir,
206         conda_version=conda.__version__,
207         conda_build_version=conda_build_version,
208         root_prefix=config.root_dir,
209         root_writable=config.root_writable,
210         pkgs_dirs=config.pkgs_dirs,
211         envs_dirs=config.envs_dirs,
212         default_prefix=config.default_prefix,
213         channels=channels,
214         rc_path=config.rc_path,
215         user_rc_path=config.user_rc_path,
216         sys_rc_path=config.sys_rc_path,
217         is_foreign=bool(config.foreign),
218         envs=[],
219         python_version='.'.join(map(str, sys.version_info)),
220         requests_version=requests_version,
221     )
222 
223     if args.unsafe_channels:
224         if not args.json:
225             print("\n".join(info_dict["channels"]))
226         else:
227             print(json.dumps({"channels": info_dict["channels"]}))
228         return 0
229     else:
230         info_dict['channels'] = [config.hide_binstar_tokens(c) for c in
231                                  info_dict['channels']]
232     if args.all or args.json:
233         for option in options:
234             setattr(args, option, True)
235 
236     if args.all or all(not getattr(args, opt) for opt in options):
237         for key in 'pkgs_dirs', 'envs_dirs', 'channels':
238             info_dict['_' + key] = ('\n' + 24 * ' ').join(info_dict[key])
239         info_dict['_rtwro'] = ('writable' if info_dict['root_writable'] else
240                                'read only')
241         print("""\
242 Current conda install:
243 
244              platform : %(platform)s
245         conda version : %(conda_version)s
246   conda-build version : %(conda_build_version)s
247        python version : %(python_version)s
248      requests version : %(requests_version)s
249      root environment : %(root_prefix)s  (%(_rtwro)s)
250   default environment : %(default_prefix)s
251      envs directories : %(_envs_dirs)s
252         package cache : %(_pkgs_dirs)s
253          channel URLs : %(_channels)s
254           config file : %(rc_path)s
255     is foreign system : %(is_foreign)s
256 """ % info_dict)
257         if not is_initialized():
258             print("""\
259 # NOTE:
260 #     root directory '%s' is uninitialized""" % config.root_dir)
261 
262     if args.envs:
263         common.handle_envs_list(info_dict['envs'], not args.json)
264 
265     if args.system and not args.json:
266         from conda.cli.find_commands import find_commands, find_executable
267 
268         print("sys.version: %s..." % (sys.version[:40]))
269         print("sys.prefix: %s" % sys.prefix)
270         print("sys.executable: %s" % sys.executable)
271         print("conda location: %s" % dirname(conda.__file__))
272         for cmd in sorted(set(find_commands() + ['build'])):
273             print("conda-%s: %s" % (cmd, find_executable('conda-' + cmd)))
274         print("user site dirs: ", end='')
275         site_dirs = get_user_site()
276         if site_dirs:
277             print(site_dirs[0])
278         else:
279             print()
280         for site_dir in site_dirs[1:]:
281             print('                %s' % site_dir)
282         print()
283 
284         evars = ['PATH', 'PYTHONPATH', 'PYTHONHOME', 'CONDA_DEFAULT_ENV',
285                  'CIO_TEST', 'CONDA_ENVS_PATH']
286         if config.platform == 'linux':
287             evars.append('LD_LIBRARY_PATH')
288         elif config.platform == 'osx':
289             evars.append('DYLD_LIBRARY_PATH')
290         for ev in sorted(evars):
291             print("%s: %s" % (ev, os.getenv(ev, '<not set>')))
292         print()
293 
294     if args.license and not args.json:
295         try:
296             from _license import show_info
297             show_info()
298         except ImportError:
299             print("""\
300 WARNING: could not import _license.show_info
301 # try:
302 # $ conda install -n root _license""")
303 
304     if args.json:
305         common.stdout_json(info_dict)
306
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

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 @@
     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 @@
         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'

{"golden_diff": "diff --git a/conda/cli/main_info.py b/conda/cli/main_info.py\n--- a/conda/cli/main_info.py\n+++ b/conda/cli/main_info.py\n@@ -148,7 +148,7 @@\n     import conda.config as config\n     from conda.resolve import Resolve\n     from conda.cli.main_init import is_initialized\n-    from conda.api import get_index, get_package_versions\n+    from conda.api import get_index\n \n     if args.root:\n         if args.json:\n@@ -158,21 +158,19 @@\n         return\n \n     if args.packages:\n-        if args.json:\n-            results = defaultdict(list)\n-            for arg in args.packages:\n-                for pkg in get_package_versions(arg):\n-                    results[arg].append(pkg._asdict())\n-            common.stdout_json(results)\n-            return\n         index = get_index()\n         r = Resolve(index)\n-        specs = map(common.arg2spec, args.packages)\n-\n-        for spec in specs:\n-            versions = r.get_pkgs(spec)\n-            for pkg in sorted(versions):\n-                pretty_package(pkg)\n+        if args.json:\n+            common.stdout_json({\n+                package: [p._asdict()\n+                          for p in sorted(r.get_pkgs(common.arg2spec(package)))]\n+                for package in args.packages\n+            })\n+        else:\n+            for package in args.packages:\n+                versions = r.get_pkgs(common.arg2spec(package))\n+                for pkg in sorted(versions):\n+                    pretty_package(pkg)\n         return\n \n     options = 'envs', 'system', 'license'\n", "issue": "conda info --json and package lookup\nIf you set the `--json` flag for `conda info` when searching for packages, you sometimes get nothing:\n\n``` bash\n$ conda info numpy=1.11.0=py35_0\nFetching package metadata: ....\n\nnumpy 1.11.0 py35_0\n-------------------\nfile name   : numpy-1.11.0-py35_0.tar.bz2\nname        : numpy\nversion     : 1.11.0\nbuild number: 0\nbuild string: py35_0\nchannel     : defaults\nsize        : 6.1 MB\ndate        : 2016-03-28\nlicense     : BSD\nmd5         : 1900998c19c5e310687013f95374bba2\ninstalled environments:\ndependencies:\n    mkl 11.3.1\n    python 3.5*\n$ conda info --json numpy=1.11.0=py35_0\n{}\n```\n\nThings work fine for `conda info --json numpy`, so it's something with the spec format.\n\nconda info:\n\n```\n             platform : linux-64\n        conda version : 4.0.5\n  conda-build version : not installed\n       python version : 2.7.11.final.0\n     requests version : 2.9.1\n     root environment : /opt/conda  (writable)\n  default environment : /opt/conda\n     envs directories : /opt/conda/envs\n        package cache : /opt/conda/pkgs\n         channel URLs : https://repo.continuum.io/pkgs/free/linux-64/\n                        https://repo.continuum.io/pkgs/free/noarch/\n                        https://repo.continuum.io/pkgs/pro/linux-64/\n                        https://repo.continuum.io/pkgs/pro/noarch/\n          config file : None\n    is foreign system : False\n```\n\n", "before_files": [{"content": "# (c) 2012-2013 Continuum Analytics, Inc. / http://continuum.io\n# All Rights Reserved\n#\n# conda is distributed under the terms of the BSD 3-clause license.\n# Consult LICENSE.txt or http://opensource.org/licenses/BSD-3-Clause.\n\nfrom __future__ import print_function, division, absolute_import\n\nimport json\nimport os\nimport re\nimport sys\nfrom collections import defaultdict, OrderedDict\nfrom itertools import chain\nfrom os import listdir\nfrom os.path import exists, expanduser, join\n\nfrom conda.cli import common\nfrom conda.compat import iteritems\n\nhelp = \"Display information about current conda install.\"\n\nexample = \"\"\"\n\nExamples:\n\n    conda info -a\n\"\"\"\n\ndef configure_parser(sub_parsers):\n    p = sub_parsers.add_parser(\n        'info',\n        description=help,\n        help=help,\n        epilog=example,\n    )\n    common.add_parser_json(p)\n    p.add_argument(\n        '-a', \"--all\",\n        action=\"store_true\",\n        help=\"Show all information, (environments, license, and system \"\n             \"information.\")\n    p.add_argument(\n        '-e', \"--envs\",\n        action=\"store_true\",\n        help=\"List all known conda environments.\",\n    )\n    p.add_argument(\n        '-l', \"--license\",\n        action=\"store_true\",\n        help=\"Display information about the local conda licenses list.\",\n    )\n    p.add_argument(\n        '-s', \"--system\",\n        action=\"store_true\",\n        help=\"List environment variables.\",\n    )\n    p.add_argument(\n        'packages',\n        action=\"store\",\n        nargs='*',\n        help=\"Display information about packages.\",\n    )\n    p.add_argument(\n        '--root',\n        action='store_true',\n        help='Display root environment path.',\n    )\n    p.add_argument(\n        '--unsafe-channels',\n        action='store_true',\n        help='Display list of channels with tokens exposed.',\n    )\n    p.set_defaults(func=execute)\n\n\ndef show_pkg_info(name):\n    from conda.api import get_index\n    from conda.resolve import Resolve\n\n    index = get_index()\n    r = Resolve(index)\n    print(name)\n    if name in r.groups:\n        for pkg in sorted(r.get_pkgs(name)):\n            print('    %-15s %15s  %s' % (\n                    pkg.version,\n                    pkg.build,\n                    common.disp_features(r.features(pkg.fn))))\n    else:\n        print('    not available')\n    # TODO\n\n\npython_re = re.compile('python\\d\\.\\d')\ndef get_user_site():\n    site_dirs = []\n    if sys.platform != 'win32':\n        if exists(expanduser('~/.local/lib')):\n            for path in listdir(expanduser('~/.local/lib/')):\n                if python_re.match(path):\n                    site_dirs.append(\"~/.local/lib/%s\" % path)\n    else:\n        if 'APPDATA' not in os.environ:\n            return site_dirs\n        APPDATA = os.environ['APPDATA']\n        if exists(join(APPDATA, 'Python')):\n            site_dirs = [join(APPDATA, 'Python', i) for i in\n                         listdir(join(APPDATA, 'PYTHON'))]\n    return site_dirs\n\n\ndef pretty_package(pkg):\n    import conda.config as config\n    from conda.utils import human_bytes\n\n    d = OrderedDict([\n        ('file name', pkg.fn),\n        ('name', pkg.name),\n        ('version', pkg.version),\n        ('build number', pkg.build_number),\n        ('build string', pkg.build),\n        ('channel', config.canonical_channel_name(pkg.channel)),\n        ('size', human_bytes(pkg.info['size'])),\n        ])\n    rest = pkg.info\n    for key in sorted(rest):\n        if key in {'build', 'depends', 'requires', 'channel', 'name',\n                   'version', 'build_number', 'size'}:\n            continue\n        d[key] = rest[key]\n\n    print()\n    header = \"%s %s %s\" % (d['name'], d['version'], d['build string'])\n    print(header)\n    print('-'*len(header))\n    for key in d:\n        print(\"%-12s: %s\" % (key, d[key]))\n    print('dependencies:')\n    for dep in pkg.info['depends']:\n        print('    %s' % dep)\n\ndef execute(args, parser):\n    import os\n    from os.path import dirname\n\n    import conda\n    import conda.config as config\n    from conda.resolve import Resolve\n    from conda.cli.main_init import is_initialized\n    from conda.api import get_index, get_package_versions\n\n    if args.root:\n        if args.json:\n            common.stdout_json({'root_prefix': config.root_dir})\n        else:\n            print(config.root_dir)\n        return\n\n    if args.packages:\n        if args.json:\n            results = defaultdict(list)\n            for arg in args.packages:\n                for pkg in get_package_versions(arg):\n                    results[arg].append(pkg._asdict())\n            common.stdout_json(results)\n            return\n        index = get_index()\n        r = Resolve(index)\n        specs = map(common.arg2spec, args.packages)\n\n        for spec in specs:\n            versions = r.get_pkgs(spec)\n            for pkg in sorted(versions):\n                pretty_package(pkg)\n        return\n\n    options = 'envs', 'system', 'license'\n\n    try:\n        import requests\n        requests_version = requests.__version__\n    except ImportError:\n        requests_version = \"could not import\"\n    except Exception as e:\n        requests_version = \"Error %s\" % e\n\n    try:\n        import conda_build\n    except ImportError:\n        conda_build_version = \"not installed\"\n    except Exception as e:\n        conda_build_version = \"Error %s\" % e\n    else:\n        conda_build_version = conda_build.__version__\n\n    # this is a hack associated with channel weight until we get the package cache reworked\n    #   in a future release\n    # for now, just ordering the channels for display in a semi-plausible way\n    d = defaultdict(list)\n    any(d[v[1]].append(k) for k, v in iteritems(config.get_channel_urls()))\n    channels = list(chain.from_iterable(d[q] for q in sorted(d, reverse=True)))\n\n    info_dict = dict(\n        platform=config.subdir,\n        conda_version=conda.__version__,\n        conda_build_version=conda_build_version,\n        root_prefix=config.root_dir,\n        root_writable=config.root_writable,\n        pkgs_dirs=config.pkgs_dirs,\n        envs_dirs=config.envs_dirs,\n        default_prefix=config.default_prefix,\n        channels=channels,\n        rc_path=config.rc_path,\n        user_rc_path=config.user_rc_path,\n        sys_rc_path=config.sys_rc_path,\n        is_foreign=bool(config.foreign),\n        envs=[],\n        python_version='.'.join(map(str, sys.version_info)),\n        requests_version=requests_version,\n    )\n\n    if args.unsafe_channels:\n        if not args.json:\n            print(\"\\n\".join(info_dict[\"channels\"]))\n        else:\n            print(json.dumps({\"channels\": info_dict[\"channels\"]}))\n        return 0\n    else:\n        info_dict['channels'] = [config.hide_binstar_tokens(c) for c in\n                                 info_dict['channels']]\n    if args.all or args.json:\n        for option in options:\n            setattr(args, option, True)\n\n    if args.all or all(not getattr(args, opt) for opt in options):\n        for key in 'pkgs_dirs', 'envs_dirs', 'channels':\n            info_dict['_' + key] = ('\\n' + 24 * ' ').join(info_dict[key])\n        info_dict['_rtwro'] = ('writable' if info_dict['root_writable'] else\n                               'read only')\n        print(\"\"\"\\\nCurrent conda install:\n\n             platform : %(platform)s\n        conda version : %(conda_version)s\n  conda-build version : %(conda_build_version)s\n       python version : %(python_version)s\n     requests version : %(requests_version)s\n     root environment : %(root_prefix)s  (%(_rtwro)s)\n  default environment : %(default_prefix)s\n     envs directories : %(_envs_dirs)s\n        package cache : %(_pkgs_dirs)s\n         channel URLs : %(_channels)s\n          config file : %(rc_path)s\n    is foreign system : %(is_foreign)s\n\"\"\" % info_dict)\n        if not is_initialized():\n            print(\"\"\"\\\n# NOTE:\n#     root directory '%s' is uninitialized\"\"\" % config.root_dir)\n\n    if args.envs:\n        common.handle_envs_list(info_dict['envs'], not args.json)\n\n    if args.system and not args.json:\n        from conda.cli.find_commands import find_commands, find_executable\n\n        print(\"sys.version: %s...\" % (sys.version[:40]))\n        print(\"sys.prefix: %s\" % sys.prefix)\n        print(\"sys.executable: %s\" % sys.executable)\n        print(\"conda location: %s\" % dirname(conda.__file__))\n        for cmd in sorted(set(find_commands() + ['build'])):\n            print(\"conda-%s: %s\" % (cmd, find_executable('conda-' + cmd)))\n        print(\"user site dirs: \", end='')\n        site_dirs = get_user_site()\n        if site_dirs:\n            print(site_dirs[0])\n        else:\n            print()\n        for site_dir in site_dirs[1:]:\n            print('                %s' % site_dir)\n        print()\n\n        evars = ['PATH', 'PYTHONPATH', 'PYTHONHOME', 'CONDA_DEFAULT_ENV',\n                 'CIO_TEST', 'CONDA_ENVS_PATH']\n        if config.platform == 'linux':\n            evars.append('LD_LIBRARY_PATH')\n        elif config.platform == 'osx':\n            evars.append('DYLD_LIBRARY_PATH')\n        for ev in sorted(evars):\n            print(\"%s: %s\" % (ev, os.getenv(ev, '<not set>')))\n        print()\n\n    if args.license and not args.json:\n        try:\n            from _license import show_info\n            show_info()\n        except ImportError:\n            print(\"\"\"\\\nWARNING: could not import _license.show_info\n# try:\n# $ conda install -n root _license\"\"\")\n\n    if args.json:\n        common.stdout_json(info_dict)\n", "path": "conda/cli/main_info.py"}], "after_files": [{"content": "# (c) 2012-2013 Continuum Analytics, Inc. / http://continuum.io\n# All Rights Reserved\n#\n# conda is distributed under the terms of the BSD 3-clause license.\n# Consult LICENSE.txt or http://opensource.org/licenses/BSD-3-Clause.\n\nfrom __future__ import print_function, division, absolute_import\n\nimport json\nimport os\nimport re\nimport sys\nfrom collections import defaultdict, OrderedDict\nfrom itertools import chain\nfrom os import listdir\nfrom os.path import exists, expanduser, join\n\nfrom conda.cli import common\nfrom conda.compat import iteritems\n\nhelp = \"Display information about current conda install.\"\n\nexample = \"\"\"\n\nExamples:\n\n    conda info -a\n\"\"\"\n\ndef configure_parser(sub_parsers):\n    p = sub_parsers.add_parser(\n        'info',\n        description=help,\n        help=help,\n        epilog=example,\n    )\n    common.add_parser_json(p)\n    p.add_argument(\n        '-a', \"--all\",\n        action=\"store_true\",\n        help=\"Show all information, (environments, license, and system \"\n             \"information.\")\n    p.add_argument(\n        '-e', \"--envs\",\n        action=\"store_true\",\n        help=\"List all known conda environments.\",\n    )\n    p.add_argument(\n        '-l', \"--license\",\n        action=\"store_true\",\n        help=\"Display information about the local conda licenses list.\",\n    )\n    p.add_argument(\n        '-s', \"--system\",\n        action=\"store_true\",\n        help=\"List environment variables.\",\n    )\n    p.add_argument(\n        'packages',\n        action=\"store\",\n        nargs='*',\n        help=\"Display information about packages.\",\n    )\n    p.add_argument(\n        '--root',\n        action='store_true',\n        help='Display root environment path.',\n    )\n    p.add_argument(\n        '--unsafe-channels',\n        action='store_true',\n        help='Display list of channels with tokens exposed.',\n    )\n    p.set_defaults(func=execute)\n\n\ndef show_pkg_info(name):\n    from conda.api import get_index\n    from conda.resolve import Resolve\n\n    index = get_index()\n    r = Resolve(index)\n    print(name)\n    if name in r.groups:\n        for pkg in sorted(r.get_pkgs(name)):\n            print('    %-15s %15s  %s' % (\n                    pkg.version,\n                    pkg.build,\n                    common.disp_features(r.features(pkg.fn))))\n    else:\n        print('    not available')\n    # TODO\n\n\npython_re = re.compile('python\\d\\.\\d')\ndef get_user_site():\n    site_dirs = []\n    if sys.platform != 'win32':\n        if exists(expanduser('~/.local/lib')):\n            for path in listdir(expanduser('~/.local/lib/')):\n                if python_re.match(path):\n                    site_dirs.append(\"~/.local/lib/%s\" % path)\n    else:\n        if 'APPDATA' not in os.environ:\n            return site_dirs\n        APPDATA = os.environ['APPDATA']\n        if exists(join(APPDATA, 'Python')):\n            site_dirs = [join(APPDATA, 'Python', i) for i in\n                         listdir(join(APPDATA, 'PYTHON'))]\n    return site_dirs\n\n\ndef pretty_package(pkg):\n    import conda.config as config\n    from conda.utils import human_bytes\n\n    d = OrderedDict([\n        ('file name', pkg.fn),\n        ('name', pkg.name),\n        ('version', pkg.version),\n        ('build number', pkg.build_number),\n        ('build string', pkg.build),\n        ('channel', config.canonical_channel_name(pkg.channel)),\n        ('size', human_bytes(pkg.info['size'])),\n        ])\n    rest = pkg.info\n    for key in sorted(rest):\n        if key in {'build', 'depends', 'requires', 'channel', 'name',\n                   'version', 'build_number', 'size'}:\n            continue\n        d[key] = rest[key]\n\n    print()\n    header = \"%s %s %s\" % (d['name'], d['version'], d['build string'])\n    print(header)\n    print('-'*len(header))\n    for key in d:\n        print(\"%-12s: %s\" % (key, d[key]))\n    print('dependencies:')\n    for dep in pkg.info['depends']:\n        print('    %s' % dep)\n\ndef execute(args, parser):\n    import os\n    from os.path import dirname\n\n    import conda\n    import conda.config as config\n    from conda.resolve import Resolve\n    from conda.cli.main_init import is_initialized\n    from conda.api import get_index\n\n    if args.root:\n        if args.json:\n            common.stdout_json({'root_prefix': config.root_dir})\n        else:\n            print(config.root_dir)\n        return\n\n    if args.packages:\n        index = get_index()\n        r = Resolve(index)\n        if args.json:\n            common.stdout_json({\n                package: [p._asdict()\n                          for p in sorted(r.get_pkgs(common.arg2spec(package)))]\n                for package in args.packages\n            })\n        else:\n            for package in args.packages:\n                versions = r.get_pkgs(common.arg2spec(package))\n                for pkg in sorted(versions):\n                    pretty_package(pkg)\n        return\n\n    options = 'envs', 'system', 'license'\n\n    try:\n        import requests\n        requests_version = requests.__version__\n    except ImportError:\n        requests_version = \"could not import\"\n    except Exception as e:\n        requests_version = \"Error %s\" % e\n\n    try:\n        import conda_build\n    except ImportError:\n        conda_build_version = \"not installed\"\n    except Exception as e:\n        conda_build_version = \"Error %s\" % e\n    else:\n        conda_build_version = conda_build.__version__\n\n    # this is a hack associated with channel weight until we get the package cache reworked\n    #   in a future release\n    # for now, just ordering the channels for display in a semi-plausible way\n    d = defaultdict(list)\n    any(d[v[1]].append(k) for k, v in iteritems(config.get_channel_urls()))\n    channels = list(chain.from_iterable(d[q] for q in sorted(d, reverse=True)))\n\n    info_dict = dict(\n        platform=config.subdir,\n        conda_version=conda.__version__,\n        conda_build_version=conda_build_version,\n        root_prefix=config.root_dir,\n        root_writable=config.root_writable,\n        pkgs_dirs=config.pkgs_dirs,\n        envs_dirs=config.envs_dirs,\n        default_prefix=config.default_prefix,\n        channels=channels,\n        rc_path=config.rc_path,\n        user_rc_path=config.user_rc_path,\n        sys_rc_path=config.sys_rc_path,\n        is_foreign=bool(config.foreign),\n        envs=[],\n        python_version='.'.join(map(str, sys.version_info)),\n        requests_version=requests_version,\n    )\n\n    if args.unsafe_channels:\n        if not args.json:\n            print(\"\\n\".join(info_dict[\"channels\"]))\n        else:\n            print(json.dumps({\"channels\": info_dict[\"channels\"]}))\n        return 0\n    else:\n        info_dict['channels'] = [config.hide_binstar_tokens(c) for c in\n                                 info_dict['channels']]\n    if args.all or args.json:\n        for option in options:\n            setattr(args, option, True)\n\n    if args.all or all(not getattr(args, opt) for opt in options):\n        for key in 'pkgs_dirs', 'envs_dirs', 'channels':\n            info_dict['_' + key] = ('\\n' + 24 * ' ').join(info_dict[key])\n        info_dict['_rtwro'] = ('writable' if info_dict['root_writable'] else\n                               'read only')\n        print(\"\"\"\\\nCurrent conda install:\n\n             platform : %(platform)s\n        conda version : %(conda_version)s\n  conda-build version : %(conda_build_version)s\n       python version : %(python_version)s\n     requests version : %(requests_version)s\n     root environment : %(root_prefix)s  (%(_rtwro)s)\n  default environment : %(default_prefix)s\n     envs directories : %(_envs_dirs)s\n        package cache : %(_pkgs_dirs)s\n         channel URLs : %(_channels)s\n          config file : %(rc_path)s\n    is foreign system : %(is_foreign)s\n\"\"\" % info_dict)\n        if not is_initialized():\n            print(\"\"\"\\\n# NOTE:\n#     root directory '%s' is uninitialized\"\"\" % config.root_dir)\n\n    if args.envs:\n        common.handle_envs_list(info_dict['envs'], not args.json)\n\n    if args.system and not args.json:\n        from conda.cli.find_commands import find_commands, find_executable\n\n        print(\"sys.version: %s...\" % (sys.version[:40]))\n        print(\"sys.prefix: %s\" % sys.prefix)\n        print(\"sys.executable: %s\" % sys.executable)\n        print(\"conda location: %s\" % dirname(conda.__file__))\n        for cmd in sorted(set(find_commands() + ['build'])):\n            print(\"conda-%s: %s\" % (cmd, find_executable('conda-' + cmd)))\n        print(\"user site dirs: \", end='')\n        site_dirs = get_user_site()\n        if site_dirs:\n            print(site_dirs[0])\n        else:\n            print()\n        for site_dir in site_dirs[1:]:\n            print('                %s' % site_dir)\n        print()\n\n        evars = ['PATH', 'PYTHONPATH', 'PYTHONHOME', 'CONDA_DEFAULT_ENV',\n                 'CIO_TEST', 'CONDA_ENVS_PATH']\n        if config.platform == 'linux':\n            evars.append('LD_LIBRARY_PATH')\n        elif config.platform == 'osx':\n            evars.append('DYLD_LIBRARY_PATH')\n        for ev in sorted(evars):\n            print(\"%s: %s\" % (ev, os.getenv(ev, '<not set>')))\n        print()\n\n    if args.license and not args.json:\n        try:\n            from _license import show_info\n            show_info()\n        except ImportError:\n            print(\"\"\"\\\nWARNING: could not import _license.show_info\n# try:\n# $ conda install -n root _license\"\"\")\n\n    if args.json:\n        common.stdout_json(info_dict)\n", "path": "conda/cli/main_info.py"}]}