Repository: conda/conda

Issue:
Conda cannot properly export current environment via `conda env export` (without extra args)
## Current Behavior

`conda env export` (without any extra args) is supposed to export the current environment as a yaml. But it does not seem to work well if the current environment's prefix directory is in a custom location. This seems to work only if the parent directory of the prefix is a directory named `envs` . For example - 

This works: 
```
conda activate /tmp/envs/sf_clone
conda env export
```
This fails.
```
conda activate /tmp/foo/sf_clone
conda env export
```

This is very similar to #1935 . Im creating a new bug because the old one is closed without giving any reason.

I would also like to know if it is okay to rely on the fact that envs created under directories like `/something/something_else/envs` dont have this problem.


### Steps to Reproduce
<details> <p>

```sh
(base) >02:01:27 devbox:~$ conda create --clone snowflakes -p /tmp/envs/sf_clone
Source:      /home/sai.suram/anaconda3/envs/snowflakes
Destination: /tmp/envs/sf_clone
Packages: 30
Files: 0
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
#     $ conda activate /tmp/envs/sf_clone
#
# To deactivate an active environment, use
#
#     $ conda deactivate

(base) >02:02:08 devbox:~$ conda create --clone snowflakes -p /tmp/foo/sf_clone
Source:      /home/sai.suram/anaconda3/envs/snowflakes
Destination: /tmp/foo/sf_clone
Packages: 30
Files: 0
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
#     $ conda activate /tmp/foo/sf_clone
#
# To deactivate an active environment, use
#
#     $ conda deactivate
(base) >02:02:27 devbox:~$ conda activate /tmp/foo/sf_clone

(/tmp/foo/sf_clone) >02:02:34 devbox:~$ conda env export
CondaValueError: Invalid environment name: '/tmp/foo/sf_clone'
  Characters not allowed: ('/', ' ', ':', '#')

(/tmp/foo/sf_clone) >02:02:43 devbox:~$ conda activate /tmp/envs/sf_clone
(sf_clone) >02:02:50 devbox:~$ conda env export
name: sf_clone
channels:
  - defaults
prefix: /home/sai.suram/anaconda3/envs/sf_clone
```
</p></details>



## Expected Behavior
`conda env export` should work for all environments.

## Environment Information

<details open><summary><code>`conda info`</code></summary><p>
<!-- between the ticks below, paste the output of 'conda info' -->

```
     active environment : None
            shell level : 0
       user config file : /home/sai.suram/.condarc
 populated config files :
          conda version : 4.7.11
    conda-build version : 3.18.8
         python version : 3.7.3.final.0
       virtual packages :
       base environment : /home/sai.suram/anaconda3  (writable)
           channel URLs : https://repo.anaconda.com/pkgs/main/linux-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/linux-64
                          https://repo.anaconda.com/pkgs/r/noarch
          package cache : /home/sai.suram/anaconda3/pkgs
                          /home/sai.suram/.conda/pkgs
       envs directories : /home/sai.suram/anaconda3/envs
                          /home/sai.suram/.conda/envs
               platform : linux-64
             user-agent : conda/4.7.11 requests/2.22.0 CPython/3.7.3 Linux/4.15.0-58-generic ubuntu/16.04.4 glibc/2.23
                UID:GID : 1000:1000
             netrc file : /home/sai.suram/.netrc
           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' -->

```
(empty)
```
</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' -->

```
# packages in environment at /home/sai.suram/anaconda3/envs/snowflakes:
#
# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                        main    defaults
argcomplete               1.10.0                   py37_0    defaults
biopython                 1.74             py37h7b6447c_0    defaults
blas                      1.0                         mkl    defaults
ca-certificates           2019.5.15                     1    defaults
certifi                   2019.6.16                py37_1    defaults
intel-openmp              2019.4                      243    defaults
libedit                   3.1.20181209         hc058e9b_0    defaults
libffi                    3.2.1                hd88cf55_4    defaults
libgcc-ng                 9.1.0                hdf63c60_0    defaults
libgfortran-ng            7.3.0                hdf63c60_0    defaults
libstdcxx-ng              9.1.0                hdf63c60_0    defaults
mkl                       2019.4                      243    defaults
mkl-service               2.0.2            py37h7b6447c_0    defaults
mkl_fft                   1.0.14           py37ha843d7b_0    defaults
mkl_random                1.0.2            py37hd81dba3_0    defaults
ncurses                   6.1                  he6710b0_1    defaults
numpy                     1.16.4           py37h7e9f1db_0    defaults
numpy-base                1.16.4           py37hde5b4d6_0    defaults
openssl                   1.1.1c               h7b6447c_1    defaults
pip                       19.2.2                   py37_0    defaults
python                    3.7.4                h265db76_1    defaults
readline                  7.0                  h7b6447c_5    defaults
setuptools                41.0.1                   py37_0    defaults
six                       1.12.0                   py37_0    defaults
sqlite                    3.29.0               h7b6447c_0    defaults
tk                        8.6.8                hbc83047_0    defaults
wheel                     0.33.4                   py37_0    defaults
xz                        5.2.4                h14c3975_4    defaults
zlib                      1.2.11               h7b6447c_3    defaults
```
</p></details>


Discussion:
It appears that `conda env export` does not detect when the activate environment is a full path to the prefix rather than a named environment.  Until this is fixed the `-p` argument needs to be passed to export command.
Hey, Thanks for the response :) 

Before the bug is fixed can we bank on the assumption that if the parent directory is `envs` conda env export works without the -p argument?
> Before the bug is fixed can we bank on the assumption that if the parent directory is `envs` conda env export works without the -p argument?

It "works" but the resulting `prefix` entry in the yaml is incorrect, it will start with the main conda environment directory rather than the directory.

```
(base)   ~/workspace/conda$ conda create -p /home/jhelmus/envs/sample_env
Collecting package metadata (current_repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: /home/jhelmus/envs/sample_env



Proceed ([y]/n)? y

Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
#     $ conda activate /home/jhelmus/envs/sample_env
#
# To deactivate an active environment, use
#
#     $ conda deactivate

(base)   ~/workspace/conda$ conda activate /home/jhelmus/envs/sample_env
(sample_env)   ~/workspace/conda$ conda env export
name: sample_env
channels:
  - defaults
prefix: /home/jhelmus/conda/envs/sample_env
```

Notice that the prefix is /home/jhelmus/conda/env/sample_env whereas the actual prefix is /home/jhelmus/env/sample_env (missing the conda).

Resolving patch:
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
@@ -94,7 +94,11 @@ def execute(args, parser):
                 * Re-run this command inside an activated conda environment.""").lstrip()
             # TODO Add json support
             raise CondaEnvException(msg)
-        args.name = name
+        if os.sep in name:
+            # assume "names" with a path seperator are actually paths
+            args.prefix = name
+        else:
+            args.name = name
     else:
         name = args.name
     prefix = get_prefix(args)


Test patch: