We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
conda 4.4 incorrect activate message
I updated to conda 4.4.0b2 from conda v4.3. I created a new environment and it recommended the following - which I ran and got an error:

To activate this environment, use

    $ conda activate anaconda2

To deactivate an active environment, use

    $ conda deactivate

0288-csoja:scripts csoja$ conda activate anaconda2
Traceback (most recent call last):
  File "/Users/csoja/Desktop/anaconda/lib/python3.5/site-packages/conda/cli/main.py", line 176, in main
    raise CommandNotFoundError(argv1)
conda.exceptions.CommandNotFoundError: 'activate is not a conda command.
Did you mean 'source activate'?


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/csoja/Desktop/anaconda/bin/conda", line 6, in <module>
    sys.exit(conda.cli.main())
  File "/Users/csoja/Desktop/anaconda/lib/python3.5/site-packages/conda/cli/main.py", line 178, in main
    from ..exceptions import handle_exception
ImportError: cannot import name 'handle_exception'

--- 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/install.py`
Content:
```
1 # (c) 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 absolute_import, division, print_function, unicode_literals
8 
9 from logging import getLogger
10 import os
11 from os.path import abspath, basename, exists, isdir
12 
13 from conda.models.match_spec import MatchSpec
14 from . import common
15 from .common import check_non_admin
16 from .._vendor.auxlib.ish import dals
17 from ..base.constants import ROOT_ENV_NAME
18 from ..base.context import context
19 from ..common.compat import text_type
20 from ..core.envs_manager import EnvsDirectory
21 from ..core.index import calculate_channel_urls, get_index
22 from ..core.solve import Solver
23 from ..exceptions import (CondaImportError, CondaOSError, CondaSystemExit, CondaValueError,
24                           DirectoryNotFoundError, DryRunExit, EnvironmentLocationNotFound,
25                           PackagesNotFoundError, TooManyArgumentsError,
26                           UnsatisfiableError)
27 from ..misc import append_env, clone_env, explicit, touch_nonadmin
28 from ..plan import (revert_actions)
29 from ..resolve import ResolvePackageNotFound
30 
31 log = getLogger(__name__)
32 stderrlog = getLogger('conda.stderr')
33 
34 
35 def check_prefix(prefix, json=False):
36     name = basename(prefix)
37     error = None
38     if name == ROOT_ENV_NAME:
39         error = "'%s' is a reserved environment name" % name
40     if exists(prefix):
41         if isdir(prefix) and 'conda-meta' not in os.listdir(prefix):
42             return None
43         error = "prefix already exists: %s" % prefix
44 
45     if error:
46         raise CondaValueError(error, json)
47 
48     if ' ' in prefix:
49         stderrlog.warn("WARNING: A space was detected in your requested environment path\n"
50                        "'%s'\n"
51                        "Spaces in paths can sometimes be problematic." % prefix)
52 
53 
54 def clone(src_arg, dst_prefix, json=False, quiet=False, index_args=None):
55     if os.sep in src_arg:
56         src_prefix = abspath(src_arg)
57         if not isdir(src_prefix):
58             raise DirectoryNotFoundError(src_arg)
59     else:
60         assert context._argparse_args.clone is not None
61         src_prefix = EnvsDirectory.locate_prefix_by_name(context._argparse_args.clone)
62 
63     if not json:
64         print("Source:      %s" % src_prefix)
65         print("Destination: %s" % dst_prefix)
66 
67     actions, untracked_files = clone_env(src_prefix, dst_prefix,
68                                          verbose=not json,
69                                          quiet=quiet,
70                                          index_args=index_args)
71 
72     if json:
73         common.stdout_json_success(
74             actions=actions,
75             untracked_files=list(untracked_files),
76             src_prefix=src_prefix,
77             dst_prefix=dst_prefix
78         )
79 
80 
81 def print_activate(env_name_or_prefix):  # pragma: no cover
82     if not context.quiet and not context.json:
83         message = dals("""
84 
85         To activate this environment, use
86 
87             $ conda activate %s
88 
89         To deactivate an active environment, use
90 
91             $ conda deactivate
92         """) % env_name_or_prefix
93         print(message)  # TODO: use logger
94 
95 
96 def get_revision(arg, json=False):
97     try:
98         return int(arg)
99     except ValueError:
100         CondaValueError("expected revision number, not: '%s'" % arg, json)
101 
102 
103 def install(args, parser, command='install'):
104     """
105     conda install, conda update, and conda create
106     """
107     context.validate_configuration()
108     check_non_admin()
109 
110     newenv = bool(command == 'create')
111     isupdate = bool(command == 'update')
112     isinstall = bool(command == 'install')
113     if newenv:
114         common.ensure_name_or_prefix(args, command)
115     prefix = context.target_prefix
116     if newenv:
117         check_prefix(prefix, json=context.json)
118     if context.force_32bit and prefix == context.root_prefix:
119         raise CondaValueError("cannot use CONDA_FORCE_32BIT=1 in root env")
120     if isupdate and not (args.file or args.all or args.packages):
121         raise CondaValueError("""no package names supplied
122 # If you want to update to a newer version of Anaconda, type:
123 #
124 # $ conda update --prefix %s anaconda
125 """ % prefix)
126 
127     args_packages = [s.strip('"\'') for s in args.packages]
128     if newenv and not args.no_default_packages:
129         # Override defaults if they are specified at the command line
130         # TODO: rework in 4.4 branch using MatchSpec
131         args_packages_names = [pkg.replace(' ', '=').split('=', 1)[0] for pkg in args_packages]
132         for default_pkg in context.create_default_packages:
133             default_pkg_name = default_pkg.replace(' ', '=').split('=', 1)[0]
134             if default_pkg_name not in args_packages_names:
135                 args_packages.append(default_pkg)
136     args_packages.extend(text_type(MatchSpec(provides_features=ft)) for ft in args.features or ())
137 
138     index_args = {
139         'use_cache': args.use_index_cache,
140         'channel_urls': context.channels,
141         'unknown': args.unknown,
142         'prepend': not args.override_channels,
143         'use_local': args.use_local
144     }
145 
146     num_cp = sum(s.endswith('.tar.bz2') for s in args_packages)
147     if num_cp:
148         if num_cp == len(args_packages):
149             explicit(args_packages, prefix, verbose=not context.quiet)
150             return
151         else:
152             raise CondaValueError("cannot mix specifications with conda package"
153                                   " filenames")
154 
155     specs = []
156     if args.file:
157         for fpath in args.file:
158             specs.extend(common.specs_from_url(fpath, json=context.json))
159         if '@EXPLICIT' in specs:
160             explicit(specs, prefix, verbose=not context.quiet, index_args=index_args)
161             return
162     specs.extend(common.specs_from_args(args_packages, json=context.json))
163 
164     if isinstall and args.revision:
165         get_revision(args.revision, json=context.json)
166     elif isinstall and not (args.file or args_packages):
167         raise CondaValueError("too few arguments, "
168                               "must supply command line package specs or --file")
169 
170     if newenv and args.clone:
171         if args.packages:
172             raise TooManyArgumentsError(0, len(args.packages), list(args.packages),
173                                         'did not expect any arguments for --clone')
174 
175         clone(args.clone, prefix, json=context.json, quiet=context.quiet, index_args=index_args)
176         append_env(prefix)
177         touch_nonadmin(prefix)
178         print_activate(args.name if args.name else prefix)
179         return
180 
181     if not isdir(prefix) and not newenv:
182         if args.mkdir:
183             try:
184                 os.makedirs(prefix)
185             except OSError:
186                 raise CondaOSError("Error: could not create directory: %s" % prefix)
187         else:
188             raise EnvironmentLocationNotFound(prefix)
189 
190     try:
191         if isinstall and args.revision:
192             index = get_index(channel_urls=index_args['channel_urls'],
193                               prepend=index_args['prepend'], platform=None,
194                               use_local=index_args['use_local'], use_cache=index_args['use_cache'],
195                               unknown=index_args['unknown'], prefix=prefix)
196             unlink_link_transaction = revert_actions(prefix, get_revision(args.revision), index)
197             progressive_fetch_extract = unlink_link_transaction.get_pfe()
198         else:
199             solver = Solver(prefix, context.channels, context.subdirs, specs_to_add=specs)
200             unlink_link_transaction = solver.solve_for_transaction(
201                 force_reinstall=context.force,
202             )
203             progressive_fetch_extract = unlink_link_transaction.get_pfe()
204 
205     except ResolvePackageNotFound as e:
206         channels_urls = tuple(calculate_channel_urls(
207             channel_urls=index_args['channel_urls'],
208             prepend=index_args['prepend'],
209             platform=None,
210             use_local=index_args['use_local'],
211         ))
212         raise PackagesNotFoundError(e.bad_deps, channels_urls)
213 
214     except (UnsatisfiableError, SystemExit) as e:
215         # Unsatisfiable package specifications/no such revision/import error
216         if e.args and 'could not import' in e.args[0]:
217             raise CondaImportError(text_type(e))
218         raise
219 
220     handle_txn(progressive_fetch_extract, unlink_link_transaction, prefix, args, newenv)
221 
222 
223 def handle_txn(progressive_fetch_extract, unlink_link_transaction, prefix, args, newenv,
224                remove_op=False):
225     if unlink_link_transaction.nothing_to_do:
226         if remove_op:
227             # No packages found to remove from environment
228             raise PackagesNotFoundError(args.package_names)
229         elif not newenv:
230             if context.json:
231                 common.stdout_json_success(message='All requested packages already installed.')
232             else:
233                 print('\n# All requested packages already installed.\n')
234             return
235 
236     if not context.json:
237         unlink_link_transaction.display_actions(progressive_fetch_extract)
238         common.confirm_yn()
239 
240     elif context.dry_run:
241         common.stdout_json_success(unlink_link_transaction=unlink_link_transaction, prefix=prefix,
242                                    dry_run=True)
243         raise DryRunExit()
244 
245     try:
246         progressive_fetch_extract.execute()
247         unlink_link_transaction.execute()
248 
249     except SystemExit as e:
250         raise CondaSystemExit('Exiting', e)
251 
252     if newenv:
253         append_env(prefix)
254         touch_nonadmin(prefix)
255         print_activate(args.name if args.name else prefix)
256 
257     if context.json:
258         actions = unlink_link_transaction.make_legacy_action_groups(progressive_fetch_extract)[0]
259         common.stdout_json_success(actions=actions)
260
```
--- 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/install.py b/conda/cli/install.py
--- a/conda/cli/install.py
+++ b/conda/cli/install.py
@@ -16,7 +16,7 @@
 from .._vendor.auxlib.ish import dals
 from ..base.constants import ROOT_ENV_NAME
 from ..base.context import context
-from ..common.compat import text_type
+from ..common.compat import text_type, on_win
 from ..core.envs_manager import EnvsDirectory
 from ..core.index import calculate_channel_urls, get_index
 from ..core.solve import Solver
@@ -80,16 +80,39 @@
 
 def print_activate(env_name_or_prefix):  # pragma: no cover
     if not context.quiet and not context.json:
-        message = dals("""
-
-        To activate this environment, use
-
-            $ conda activate %s
-
-        To deactivate an active environment, use
-
-            $ conda deactivate
-        """) % env_name_or_prefix
+        if 'CONDA_SHLVL' in os.environ or os.path.split(os.environ.get('SHELL', ''))[-1] == 'fish':
+            message = dals("""
+            #
+            # To activate this environment, use
+            #
+            #     $ conda activate %s
+            #
+            # To deactivate an active environment, use
+            #
+            #     $ conda deactivate
+            """) % env_name_or_prefix
+        elif on_win:
+            message = dals("""
+            #
+            # To activate this environment, use:
+            # > activate %s
+            #
+            # To deactivate an active environment, use:
+            # > deactivate
+            #
+            # * for power-users using bash, you must source
+            #
+            """) % env_name_or_prefix
+        else:
+            message = dals("""
+            #
+            # To activate this environment, use:
+            # > source activate %s
+            #
+            # To deactivate an active environment, use:
+            # > source deactivate
+            #
+            """) % env_name_or_prefix
         print(message)  # TODO: use logger

{"golden_diff": "diff --git a/conda/cli/install.py b/conda/cli/install.py\n--- a/conda/cli/install.py\n+++ b/conda/cli/install.py\n@@ -16,7 +16,7 @@\n from .._vendor.auxlib.ish import dals\n from ..base.constants import ROOT_ENV_NAME\n from ..base.context import context\n-from ..common.compat import text_type\n+from ..common.compat import text_type, on_win\n from ..core.envs_manager import EnvsDirectory\n from ..core.index import calculate_channel_urls, get_index\n from ..core.solve import Solver\n@@ -80,16 +80,39 @@\n \n def print_activate(env_name_or_prefix):  # pragma: no cover\n     if not context.quiet and not context.json:\n-        message = dals(\"\"\"\n-\n-        To activate this environment, use\n-\n-            $ conda activate %s\n-\n-        To deactivate an active environment, use\n-\n-            $ conda deactivate\n-        \"\"\") % env_name_or_prefix\n+        if 'CONDA_SHLVL' in os.environ or os.path.split(os.environ.get('SHELL', ''))[-1] == 'fish':\n+            message = dals(\"\"\"\n+            #\n+            # To activate this environment, use\n+            #\n+            #     $ conda activate %s\n+            #\n+            # To deactivate an active environment, use\n+            #\n+            #     $ conda deactivate\n+            \"\"\") % env_name_or_prefix\n+        elif on_win:\n+            message = dals(\"\"\"\n+            #\n+            # To activate this environment, use:\n+            # > activate %s\n+            #\n+            # To deactivate an active environment, use:\n+            # > deactivate\n+            #\n+            # * for power-users using bash, you must source\n+            #\n+            \"\"\") % env_name_or_prefix\n+        else:\n+            message = dals(\"\"\"\n+            #\n+            # To activate this environment, use:\n+            # > source activate %s\n+            #\n+            # To deactivate an active environment, use:\n+            # > source deactivate\n+            #\n+            \"\"\") % env_name_or_prefix\n         print(message)  # TODO: use logger\n", "issue": "conda 4.4 incorrect activate message\nI updated to conda 4.4.0b2 from conda v4.3. I created a new environment and it recommended the following - which I ran and got an error:\r\n\r\nTo activate this environment, use\r\n\r\n    $ conda activate anaconda2\r\n\r\nTo deactivate an active environment, use\r\n\r\n    $ conda deactivate\r\n\r\n0288-csoja:scripts csoja$ conda activate anaconda2\r\nTraceback (most recent call last):\r\n  File \"/Users/csoja/Desktop/anaconda/lib/python3.5/site-packages/conda/cli/main.py\", line 176, in main\r\n    raise CommandNotFoundError(argv1)\r\nconda.exceptions.CommandNotFoundError: 'activate is not a conda command.\r\nDid you mean 'source activate'?\r\n\r\n\r\nDuring handling of the above exception, another exception occurred:\r\n\r\nTraceback (most recent call last):\r\n  File \"/Users/csoja/Desktop/anaconda/bin/conda\", line 6, in <module>\r\n    sys.exit(conda.cli.main())\r\n  File \"/Users/csoja/Desktop/anaconda/lib/python3.5/site-packages/conda/cli/main.py\", line 178, in main\r\n    from ..exceptions import handle_exception\r\nImportError: cannot import name 'handle_exception'\n", "before_files": [{"content": "# (c) 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 absolute_import, division, print_function, unicode_literals\n\nfrom logging import getLogger\nimport os\nfrom os.path import abspath, basename, exists, isdir\n\nfrom conda.models.match_spec import MatchSpec\nfrom . import common\nfrom .common import check_non_admin\nfrom .._vendor.auxlib.ish import dals\nfrom ..base.constants import ROOT_ENV_NAME\nfrom ..base.context import context\nfrom ..common.compat import text_type\nfrom ..core.envs_manager import EnvsDirectory\nfrom ..core.index import calculate_channel_urls, get_index\nfrom ..core.solve import Solver\nfrom ..exceptions import (CondaImportError, CondaOSError, CondaSystemExit, CondaValueError,\n                          DirectoryNotFoundError, DryRunExit, EnvironmentLocationNotFound,\n                          PackagesNotFoundError, TooManyArgumentsError,\n                          UnsatisfiableError)\nfrom ..misc import append_env, clone_env, explicit, touch_nonadmin\nfrom ..plan import (revert_actions)\nfrom ..resolve import ResolvePackageNotFound\n\nlog = getLogger(__name__)\nstderrlog = getLogger('conda.stderr')\n\n\ndef check_prefix(prefix, json=False):\n    name = basename(prefix)\n    error = None\n    if name == ROOT_ENV_NAME:\n        error = \"'%s' is a reserved environment name\" % name\n    if exists(prefix):\n        if isdir(prefix) and 'conda-meta' not in os.listdir(prefix):\n            return None\n        error = \"prefix already exists: %s\" % prefix\n\n    if error:\n        raise CondaValueError(error, json)\n\n    if ' ' in prefix:\n        stderrlog.warn(\"WARNING: A space was detected in your requested environment path\\n\"\n                       \"'%s'\\n\"\n                       \"Spaces in paths can sometimes be problematic.\" % prefix)\n\n\ndef clone(src_arg, dst_prefix, json=False, quiet=False, index_args=None):\n    if os.sep in src_arg:\n        src_prefix = abspath(src_arg)\n        if not isdir(src_prefix):\n            raise DirectoryNotFoundError(src_arg)\n    else:\n        assert context._argparse_args.clone is not None\n        src_prefix = EnvsDirectory.locate_prefix_by_name(context._argparse_args.clone)\n\n    if not json:\n        print(\"Source:      %s\" % src_prefix)\n        print(\"Destination: %s\" % dst_prefix)\n\n    actions, untracked_files = clone_env(src_prefix, dst_prefix,\n                                         verbose=not json,\n                                         quiet=quiet,\n                                         index_args=index_args)\n\n    if json:\n        common.stdout_json_success(\n            actions=actions,\n            untracked_files=list(untracked_files),\n            src_prefix=src_prefix,\n            dst_prefix=dst_prefix\n        )\n\n\ndef print_activate(env_name_or_prefix):  # pragma: no cover\n    if not context.quiet and not context.json:\n        message = dals(\"\"\"\n\n        To activate this environment, use\n\n            $ conda activate %s\n\n        To deactivate an active environment, use\n\n            $ conda deactivate\n        \"\"\") % env_name_or_prefix\n        print(message)  # TODO: use logger\n\n\ndef get_revision(arg, json=False):\n    try:\n        return int(arg)\n    except ValueError:\n        CondaValueError(\"expected revision number, not: '%s'\" % arg, json)\n\n\ndef install(args, parser, command='install'):\n    \"\"\"\n    conda install, conda update, and conda create\n    \"\"\"\n    context.validate_configuration()\n    check_non_admin()\n\n    newenv = bool(command == 'create')\n    isupdate = bool(command == 'update')\n    isinstall = bool(command == 'install')\n    if newenv:\n        common.ensure_name_or_prefix(args, command)\n    prefix = context.target_prefix\n    if newenv:\n        check_prefix(prefix, json=context.json)\n    if context.force_32bit and prefix == context.root_prefix:\n        raise CondaValueError(\"cannot use CONDA_FORCE_32BIT=1 in root env\")\n    if isupdate and not (args.file or args.all or args.packages):\n        raise CondaValueError(\"\"\"no package names supplied\n# If you want to update to a newer version of Anaconda, type:\n#\n# $ conda update --prefix %s anaconda\n\"\"\" % prefix)\n\n    args_packages = [s.strip('\"\\'') for s in args.packages]\n    if newenv and not args.no_default_packages:\n        # Override defaults if they are specified at the command line\n        # TODO: rework in 4.4 branch using MatchSpec\n        args_packages_names = [pkg.replace(' ', '=').split('=', 1)[0] for pkg in args_packages]\n        for default_pkg in context.create_default_packages:\n            default_pkg_name = default_pkg.replace(' ', '=').split('=', 1)[0]\n            if default_pkg_name not in args_packages_names:\n                args_packages.append(default_pkg)\n    args_packages.extend(text_type(MatchSpec(provides_features=ft)) for ft in args.features or ())\n\n    index_args = {\n        'use_cache': args.use_index_cache,\n        'channel_urls': context.channels,\n        'unknown': args.unknown,\n        'prepend': not args.override_channels,\n        'use_local': args.use_local\n    }\n\n    num_cp = sum(s.endswith('.tar.bz2') for s in args_packages)\n    if num_cp:\n        if num_cp == len(args_packages):\n            explicit(args_packages, prefix, verbose=not context.quiet)\n            return\n        else:\n            raise CondaValueError(\"cannot mix specifications with conda package\"\n                                  \" filenames\")\n\n    specs = []\n    if args.file:\n        for fpath in args.file:\n            specs.extend(common.specs_from_url(fpath, json=context.json))\n        if '@EXPLICIT' in specs:\n            explicit(specs, prefix, verbose=not context.quiet, index_args=index_args)\n            return\n    specs.extend(common.specs_from_args(args_packages, json=context.json))\n\n    if isinstall and args.revision:\n        get_revision(args.revision, json=context.json)\n    elif isinstall and not (args.file or args_packages):\n        raise CondaValueError(\"too few arguments, \"\n                              \"must supply command line package specs or --file\")\n\n    if newenv and args.clone:\n        if args.packages:\n            raise TooManyArgumentsError(0, len(args.packages), list(args.packages),\n                                        'did not expect any arguments for --clone')\n\n        clone(args.clone, prefix, json=context.json, quiet=context.quiet, index_args=index_args)\n        append_env(prefix)\n        touch_nonadmin(prefix)\n        print_activate(args.name if args.name else prefix)\n        return\n\n    if not isdir(prefix) and not newenv:\n        if args.mkdir:\n            try:\n                os.makedirs(prefix)\n            except OSError:\n                raise CondaOSError(\"Error: could not create directory: %s\" % prefix)\n        else:\n            raise EnvironmentLocationNotFound(prefix)\n\n    try:\n        if isinstall and args.revision:\n            index = get_index(channel_urls=index_args['channel_urls'],\n                              prepend=index_args['prepend'], platform=None,\n                              use_local=index_args['use_local'], use_cache=index_args['use_cache'],\n                              unknown=index_args['unknown'], prefix=prefix)\n            unlink_link_transaction = revert_actions(prefix, get_revision(args.revision), index)\n            progressive_fetch_extract = unlink_link_transaction.get_pfe()\n        else:\n            solver = Solver(prefix, context.channels, context.subdirs, specs_to_add=specs)\n            unlink_link_transaction = solver.solve_for_transaction(\n                force_reinstall=context.force,\n            )\n            progressive_fetch_extract = unlink_link_transaction.get_pfe()\n\n    except ResolvePackageNotFound as e:\n        channels_urls = tuple(calculate_channel_urls(\n            channel_urls=index_args['channel_urls'],\n            prepend=index_args['prepend'],\n            platform=None,\n            use_local=index_args['use_local'],\n        ))\n        raise PackagesNotFoundError(e.bad_deps, channels_urls)\n\n    except (UnsatisfiableError, SystemExit) as e:\n        # Unsatisfiable package specifications/no such revision/import error\n        if e.args and 'could not import' in e.args[0]:\n            raise CondaImportError(text_type(e))\n        raise\n\n    handle_txn(progressive_fetch_extract, unlink_link_transaction, prefix, args, newenv)\n\n\ndef handle_txn(progressive_fetch_extract, unlink_link_transaction, prefix, args, newenv,\n               remove_op=False):\n    if unlink_link_transaction.nothing_to_do:\n        if remove_op:\n            # No packages found to remove from environment\n            raise PackagesNotFoundError(args.package_names)\n        elif not newenv:\n            if context.json:\n                common.stdout_json_success(message='All requested packages already installed.')\n            else:\n                print('\\n# All requested packages already installed.\\n')\n            return\n\n    if not context.json:\n        unlink_link_transaction.display_actions(progressive_fetch_extract)\n        common.confirm_yn()\n\n    elif context.dry_run:\n        common.stdout_json_success(unlink_link_transaction=unlink_link_transaction, prefix=prefix,\n                                   dry_run=True)\n        raise DryRunExit()\n\n    try:\n        progressive_fetch_extract.execute()\n        unlink_link_transaction.execute()\n\n    except SystemExit as e:\n        raise CondaSystemExit('Exiting', e)\n\n    if newenv:\n        append_env(prefix)\n        touch_nonadmin(prefix)\n        print_activate(args.name if args.name else prefix)\n\n    if context.json:\n        actions = unlink_link_transaction.make_legacy_action_groups(progressive_fetch_extract)[0]\n        common.stdout_json_success(actions=actions)\n", "path": "conda/cli/install.py"}], "after_files": [{"content": "# (c) 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 absolute_import, division, print_function, unicode_literals\n\nfrom logging import getLogger\nimport os\nfrom os.path import abspath, basename, exists, isdir\n\nfrom conda.models.match_spec import MatchSpec\nfrom . import common\nfrom .common import check_non_admin\nfrom .._vendor.auxlib.ish import dals\nfrom ..base.constants import ROOT_ENV_NAME\nfrom ..base.context import context\nfrom ..common.compat import text_type, on_win\nfrom ..core.envs_manager import EnvsDirectory\nfrom ..core.index import calculate_channel_urls, get_index\nfrom ..core.solve import Solver\nfrom ..exceptions import (CondaImportError, CondaOSError, CondaSystemExit, CondaValueError,\n                          DirectoryNotFoundError, DryRunExit, EnvironmentLocationNotFound,\n                          PackagesNotFoundError, TooManyArgumentsError,\n                          UnsatisfiableError)\nfrom ..misc import append_env, clone_env, explicit, touch_nonadmin\nfrom ..plan import (revert_actions)\nfrom ..resolve import ResolvePackageNotFound\n\nlog = getLogger(__name__)\nstderrlog = getLogger('conda.stderr')\n\n\ndef check_prefix(prefix, json=False):\n    name = basename(prefix)\n    error = None\n    if name == ROOT_ENV_NAME:\n        error = \"'%s' is a reserved environment name\" % name\n    if exists(prefix):\n        if isdir(prefix) and 'conda-meta' not in os.listdir(prefix):\n            return None\n        error = \"prefix already exists: %s\" % prefix\n\n    if error:\n        raise CondaValueError(error, json)\n\n    if ' ' in prefix:\n        stderrlog.warn(\"WARNING: A space was detected in your requested environment path\\n\"\n                       \"'%s'\\n\"\n                       \"Spaces in paths can sometimes be problematic.\" % prefix)\n\n\ndef clone(src_arg, dst_prefix, json=False, quiet=False, index_args=None):\n    if os.sep in src_arg:\n        src_prefix = abspath(src_arg)\n        if not isdir(src_prefix):\n            raise DirectoryNotFoundError(src_arg)\n    else:\n        assert context._argparse_args.clone is not None\n        src_prefix = EnvsDirectory.locate_prefix_by_name(context._argparse_args.clone)\n\n    if not json:\n        print(\"Source:      %s\" % src_prefix)\n        print(\"Destination: %s\" % dst_prefix)\n\n    actions, untracked_files = clone_env(src_prefix, dst_prefix,\n                                         verbose=not json,\n                                         quiet=quiet,\n                                         index_args=index_args)\n\n    if json:\n        common.stdout_json_success(\n            actions=actions,\n            untracked_files=list(untracked_files),\n            src_prefix=src_prefix,\n            dst_prefix=dst_prefix\n        )\n\n\ndef print_activate(env_name_or_prefix):  # pragma: no cover\n    if not context.quiet and not context.json:\n        if 'CONDA_SHLVL' in os.environ or os.path.split(os.environ.get('SHELL', ''))[-1] == 'fish':\n            message = dals(\"\"\"\n            #\n            # To activate this environment, use\n            #\n            #     $ conda activate %s\n            #\n            # To deactivate an active environment, use\n            #\n            #     $ conda deactivate\n            \"\"\") % env_name_or_prefix\n        elif on_win:\n            message = dals(\"\"\"\n            #\n            # To activate this environment, use:\n            # > activate %s\n            #\n            # To deactivate an active environment, use:\n            # > deactivate\n            #\n            # * for power-users using bash, you must source\n            #\n            \"\"\") % env_name_or_prefix\n        else:\n            message = dals(\"\"\"\n            #\n            # To activate this environment, use:\n            # > source activate %s\n            #\n            # To deactivate an active environment, use:\n            # > source deactivate\n            #\n            \"\"\") % env_name_or_prefix\n        print(message)  # TODO: use logger\n\n\ndef get_revision(arg, json=False):\n    try:\n        return int(arg)\n    except ValueError:\n        CondaValueError(\"expected revision number, not: '%s'\" % arg, json)\n\n\ndef install(args, parser, command='install'):\n    \"\"\"\n    conda install, conda update, and conda create\n    \"\"\"\n    context.validate_configuration()\n    check_non_admin()\n\n    newenv = bool(command == 'create')\n    isupdate = bool(command == 'update')\n    isinstall = bool(command == 'install')\n    if newenv:\n        common.ensure_name_or_prefix(args, command)\n    prefix = context.target_prefix\n    if newenv:\n        check_prefix(prefix, json=context.json)\n    if context.force_32bit and prefix == context.root_prefix:\n        raise CondaValueError(\"cannot use CONDA_FORCE_32BIT=1 in root env\")\n    if isupdate and not (args.file or args.all or args.packages):\n        raise CondaValueError(\"\"\"no package names supplied\n# If you want to update to a newer version of Anaconda, type:\n#\n# $ conda update --prefix %s anaconda\n\"\"\" % prefix)\n\n    args_packages = [s.strip('\"\\'') for s in args.packages]\n    if newenv and not args.no_default_packages:\n        # Override defaults if they are specified at the command line\n        # TODO: rework in 4.4 branch using MatchSpec\n        args_packages_names = [pkg.replace(' ', '=').split('=', 1)[0] for pkg in args_packages]\n        for default_pkg in context.create_default_packages:\n            default_pkg_name = default_pkg.replace(' ', '=').split('=', 1)[0]\n            if default_pkg_name not in args_packages_names:\n                args_packages.append(default_pkg)\n    args_packages.extend(text_type(MatchSpec(provides_features=ft)) for ft in args.features or ())\n\n    index_args = {\n        'use_cache': args.use_index_cache,\n        'channel_urls': context.channels,\n        'unknown': args.unknown,\n        'prepend': not args.override_channels,\n        'use_local': args.use_local\n    }\n\n    num_cp = sum(s.endswith('.tar.bz2') for s in args_packages)\n    if num_cp:\n        if num_cp == len(args_packages):\n            explicit(args_packages, prefix, verbose=not context.quiet)\n            return\n        else:\n            raise CondaValueError(\"cannot mix specifications with conda package\"\n                                  \" filenames\")\n\n    specs = []\n    if args.file:\n        for fpath in args.file:\n            specs.extend(common.specs_from_url(fpath, json=context.json))\n        if '@EXPLICIT' in specs:\n            explicit(specs, prefix, verbose=not context.quiet, index_args=index_args)\n            return\n    specs.extend(common.specs_from_args(args_packages, json=context.json))\n\n    if isinstall and args.revision:\n        get_revision(args.revision, json=context.json)\n    elif isinstall and not (args.file or args_packages):\n        raise CondaValueError(\"too few arguments, \"\n                              \"must supply command line package specs or --file\")\n\n    if newenv and args.clone:\n        if args.packages:\n            raise TooManyArgumentsError(0, len(args.packages), list(args.packages),\n                                        'did not expect any arguments for --clone')\n\n        clone(args.clone, prefix, json=context.json, quiet=context.quiet, index_args=index_args)\n        append_env(prefix)\n        touch_nonadmin(prefix)\n        print_activate(args.name if args.name else prefix)\n        return\n\n    if not isdir(prefix) and not newenv:\n        if args.mkdir:\n            try:\n                os.makedirs(prefix)\n            except OSError:\n                raise CondaOSError(\"Error: could not create directory: %s\" % prefix)\n        else:\n            raise EnvironmentLocationNotFound(prefix)\n\n    try:\n        if isinstall and args.revision:\n            index = get_index(channel_urls=index_args['channel_urls'],\n                              prepend=index_args['prepend'], platform=None,\n                              use_local=index_args['use_local'], use_cache=index_args['use_cache'],\n                              unknown=index_args['unknown'], prefix=prefix)\n            unlink_link_transaction = revert_actions(prefix, get_revision(args.revision), index)\n            progressive_fetch_extract = unlink_link_transaction.get_pfe()\n        else:\n            solver = Solver(prefix, context.channels, context.subdirs, specs_to_add=specs)\n            unlink_link_transaction = solver.solve_for_transaction(\n                force_reinstall=context.force,\n            )\n            progressive_fetch_extract = unlink_link_transaction.get_pfe()\n\n    except ResolvePackageNotFound as e:\n        channels_urls = tuple(calculate_channel_urls(\n            channel_urls=index_args['channel_urls'],\n            prepend=index_args['prepend'],\n            platform=None,\n            use_local=index_args['use_local'],\n        ))\n        raise PackagesNotFoundError(e.bad_deps, channels_urls)\n\n    except (UnsatisfiableError, SystemExit) as e:\n        # Unsatisfiable package specifications/no such revision/import error\n        if e.args and 'could not import' in e.args[0]:\n            raise CondaImportError(text_type(e))\n        raise\n\n    handle_txn(progressive_fetch_extract, unlink_link_transaction, prefix, args, newenv)\n\n\ndef handle_txn(progressive_fetch_extract, unlink_link_transaction, prefix, args, newenv,\n               remove_op=False):\n    if unlink_link_transaction.nothing_to_do:\n        if remove_op:\n            # No packages found to remove from environment\n            raise PackagesNotFoundError(args.package_names)\n        elif not newenv:\n            if context.json:\n                common.stdout_json_success(message='All requested packages already installed.')\n            else:\n                print('\\n# All requested packages already installed.\\n')\n            return\n\n    if not context.json:\n        unlink_link_transaction.display_actions(progressive_fetch_extract)\n        common.confirm_yn()\n\n    elif context.dry_run:\n        common.stdout_json_success(unlink_link_transaction=unlink_link_transaction, prefix=prefix,\n                                   dry_run=True)\n        raise DryRunExit()\n\n    try:\n        progressive_fetch_extract.execute()\n        unlink_link_transaction.execute()\n\n    except SystemExit as e:\n        raise CondaSystemExit('Exiting', e)\n\n    if newenv:\n        append_env(prefix)\n        touch_nonadmin(prefix)\n        print_activate(args.name if args.name else prefix)\n\n    if context.json:\n        actions = unlink_link_transaction.make_legacy_action_groups(progressive_fetch_extract)[0]\n        common.stdout_json_success(actions=actions)\n", "path": "conda/cli/install.py"}]}