Repository: conda/conda

Issue:
conda create --dry-run still does work
<!--
Hi!  Read this; it's important.

This is an issue tracker for conda -- the package manager.  File feature requests
for conda here, as well as bug reports about something conda has messed up.

If your issue is a bug report or feature request for:
  * a specific conda package from Anaconda ('defaults' channel):
      ==> file at https://github.com/ContinuumIO/anaconda-issues
  * a specific conda package from conda-forge:
      ==> file at the corresponding feedstock under https://github.com/conda-forge
  * repo.anaconda.com access and service:
      ==> file at https://github.com/ContinuumIO/anaconda-issues
  * anaconda.org access and service:
      ==> file at https://anaconda.org/contact/report
  * commands under 'conda build':
      ==> file at https://github.com/conda/conda-build
  * commands under 'conda env':
      ==> please file it here!
  * all other conda commands that start with 'conda':
      ==> please file it here!

If you continue on, and especially if you are submitting a bug report,

   **please include all requested information below.**

If a maintainer determines the  information is required to understand 
your issue, and if it is not provided, your issue may be
closed automatically.

-->

**I'm submitting a...**
  - [x ] bug report
  - [ ] feature request


## Current Behavior

`conda create --dry-run --clone py35 --prefix /home/amartin/.conda/envs/ml35
`
Creates a 7.5GB folder.
```
(py35) amartin@amartin-ai:~/.conda/envs$ ll
total 184
-rw-rw-r--  1 amartin amartin 183438 Mar 27 20:21 conda_clone_ml35.log
drwxrwxr-x 10 amartin amartin   4096 Mar 27 20:20 ml35
(py35) amartin@amartin-ai:~/.conda/envs$ du -sh ml35
7.5G    ml35
```

Also gives an assert error that it apparently doesn't want to be a dry run:
```
# >>>>>>>>>>>>>>>>>>>>>> ERROR REPORT <<<<<<<<<<<<<<<<<<<<<<

    Traceback (most recent call last):
      File "/anaconda/lib/python2.7/site-packages/conda/exceptions.py", line 812, in __call__
        return func(*args, **kwargs)
      File "/anaconda/lib/python2.7/site-packages/conda/cli/main.py", line 78, in _main
        exit_code = do_call(args, p)
      File "/anaconda/lib/python2.7/site-packages/conda/cli/conda_argparse.py", line 77, in do_call
        exit_code = getattr(module, func_name)(args, parser)
      File "/anaconda/lib/python2.7/site-packages/conda/cli/main_create.py", line 11, in execute
        install(args, parser, 'create')
      File "/anaconda/lib/python2.7/site-packages/conda/cli/install.py", line 211, in install
        clone(args.clone, prefix, json=context.json, quiet=context.quiet, index_args=index_args)
      File "/anaconda/lib/python2.7/site-packages/conda/cli/install.py", line 72, in clone
        index_args=index_args)
      File "/anaconda/lib/python2.7/site-packages/conda/misc.py", line 271, in clone_env
        force_extract=False, index_args=index_args)
      File "/anaconda/lib/python2.7/site-packages/conda/misc.py", line 69, in explicit
        pfe.execute()
      File "/anaconda/lib/python2.7/site-packages/conda/core/package_cache_data.py", line 578, in execute
        assert not context.dry_run
    AssertionError
```


### Steps to Reproduce
<!-- If the current behavior is a bug, please provide specific, minimal steps to independently reproduce.
     Include the exact conda commands that reproduce the issue and their output between the ticks below. -->
```
conda create --dry-run --clone py35 --prefix /home/amartin/.conda/envs/ml35
```


## Expected Behavior
<!-- What do you think should happen? -->
It should report actions to be taken without performing any actions

## Environment Information
<details open><summary><code>`conda info`</code></summary><p>
<!-- between the ticks below, paste the output of 'conda info' -->

```
(ml35) amartin@amartin-ai:~/.conda/envs/ml35/lib/python3.5/site-packages$ conda info

     active environment : ml35
    active env location : /home/amartin/.conda/envs/ml35
            shell level : 1
       user config file : /home/amartin/.condarc
 populated config files :
          conda version : 4.5.0
    conda-build version : 3.0.23
         python version : 2.7.11.final.0
       base environment : /anaconda  (writable)
           channel URLs : https://repo.anaconda.com/pkgs/main/linux-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/free/linux-64
                          https://repo.anaconda.com/pkgs/free/noarch
                          https://repo.anaconda.com/pkgs/r/linux-64
                          https://repo.anaconda.com/pkgs/r/noarch
                          https://repo.anaconda.com/pkgs/pro/linux-64
                          https://repo.anaconda.com/pkgs/pro/noarch
          package cache : /anaconda/pkgs
                          /home/amartin/.conda/pkgs
       envs directories : /anaconda/envs
                          /home/amartin/.conda/envs
               platform : linux-64
             user-agent : conda/4.5.0 requests/2.18.4 CPython/2.7.11 Linux/4.13.0-1011-azure ubuntu/16.04 glibc/2.23
                UID:GID : 1003:1003
             netrc file : None
           offline mode : False
```
</p></details>


<details open><summary><code>`conda config --show-sources`</code></summary><p>
<!-- between the ticks below, paste the output of 'conda config --show-sources' -->

```

```
</p></details>


<details><summary><code>`conda list --show-channel-urls`</code></summary><p>
<!-- between the ticks below, paste the output of 'conda list --show-channel-urls' -->

```

```
</p></details>
[conda_clone_ml35.log](https://github.com/conda/conda/files/1853928/conda_clone_ml35.log)



Discussion:
[conda_clone_ml35.log](https://github.com/conda/conda/files/1853929/conda_clone_ml35.log)


Resolving patch:
diff --git a/conda/misc.py b/conda/misc.py
--- a/conda/misc.py
+++ b/conda/misc.py
@@ -18,12 +18,12 @@
 from .core.link import PrefixSetup, UnlinkLinkTransaction
 from .core.package_cache_data import PackageCacheData, ProgressiveFetchExtract
 from .core.prefix_data import PrefixData, linked_data
-from .exceptions import DisallowedPackageError, PackagesNotFoundError, ParseError
+from .exceptions import DisallowedPackageError, DryRunExit, PackagesNotFoundError, ParseError
 from .gateways.disk.delete import rm_rf
 from .gateways.disk.link import islink, readlink, symlink
 from .models.dist import Dist
-from .models.records import PackageRecord
 from .models.match_spec import MatchSpec
+from .models.records import PackageRecord
 from .resolve import Resolve
 
 
@@ -65,6 +65,9 @@ def explicit(specs, prefix, verbose=False, force_extract=True, index_args=None,
 
         fetch_specs.append(MatchSpec(url, md5=md5sum) if md5sum else MatchSpec(url))
 
+    if context.dry_run:
+        raise DryRunExit()
+
     pfe = ProgressiveFetchExtract(fetch_specs)
     pfe.execute()
 
@@ -238,6 +241,9 @@ def clone_env(prefix1, prefix2, verbose=True, quiet=False, index_args=None):
         print('Packages: %d' % len(dists))
         print('Files: %d' % len(untracked_files))
 
+    if context.dry_run:
+        raise DryRunExit()
+
     for f in untracked_files:
         src = join(prefix1, f)
         dst = join(prefix2, f)


Test patch:
diff --git a/tests/test_create.py b/tests/test_create.py
--- a/tests/test_create.py
+++ b/tests/test_create.py
@@ -656,6 +656,10 @@ def test_tarball_install_and_bad_metadata(self):
 
             assert isfile(tar_old_path)
 
+            with pytest.raises(DryRunExit):
+                run_command(Commands.INSTALL, prefix, tar_old_path, "--dry-run")
+                assert not package_is_installed(prefix, 'flask-0.')
+
             # regression test for #2886 (part 1 of 2)
             # install tarball from package cache, default channel
             run_command(Commands.INSTALL, prefix, tar_old_path)