Repository: conda/conda

Issue:
conda env create gives confusing message if environment file does not exist
Try executing `conda env create -f does_not_exist.txt`.  The output I get is:

```
Using Anaconda API: https://api.anaconda.org

SpecNotFound: Can't process without a name
```

That is not super useful or meaningful.  I'd suggest it should say something obvious, like:

```
File not found: does_not_exist.txt
```
conda env create gives confusing message if environment file does not exist
Try executing `conda env create -f does_not_exist.txt`.  The output I get is:

```
Using Anaconda API: https://api.anaconda.org

SpecNotFound: Can't process without a name
```

That is not super useful or meaningful.  I'd suggest it should say something obvious, like:

```
File not found: does_not_exist.txt
```


Discussion:
Related: https://github.com/conda/conda/issues/5621
From https://github.com/conda/conda/issues/5621#issue-240019026

> IIUC, the function [build_message()](https://github.com/conda/conda/blob/master/conda_env/specs/__init__.py#L26-L31) gives precedence to binstar spec and over others, which is why this happens.
Related: https://github.com/conda/conda/issues/5621
From https://github.com/conda/conda/issues/5621#issue-240019026

> IIUC, the function [build_message()](https://github.com/conda/conda/blob/master/conda_env/specs/__init__.py#L26-L31) gives precedence to binstar spec and over others, which is why this happens.

Resolving patch:
diff --git a/conda_env/specs/__init__.py b/conda_env/specs/__init__.py
--- a/conda_env/specs/__init__.py
+++ b/conda_env/specs/__init__.py
@@ -1,11 +1,15 @@
 # -*- coding: utf-8 -*-
 # Copyright (C) 2012 Anaconda, Inc
 # SPDX-License-Identifier: BSD-3-Clause
+
+import os
+
 from .binstar import BinstarSpec
-from .yaml_file import YamlFileSpec
 from .notebook import NotebookSpec
 from .requirements import RequirementsSpec
-from ..exceptions import SpecNotFound
+from .yaml_file import YamlFileSpec
+from ..exceptions import EnvironmentFileNotFound, SpecNotFound
+
 
 all_specs = [
     BinstarSpec,
@@ -16,6 +20,12 @@
 
 
 def detect(**kwargs):
+    # Check file existence if --file was provided
+    filename = kwargs.get('filename')
+    if filename and not os.path.isfile(filename):
+        raise EnvironmentFileNotFound(filename=filename)
+
+    # Check specifications
     specs = []
     for SpecClass in all_specs:
         spec = SpecClass(**kwargs)


Test patch:
diff --git a/tests/conda_env/test_cli.py b/tests/conda_env/test_cli.py
--- a/tests/conda_env/test_cli.py
+++ b/tests/conda_env/test_cli.py
@@ -16,7 +16,7 @@
 from conda.exceptions import EnvironmentLocationNotFound
 from conda.install import rm_rf
 from conda_env.cli.main import create_parser, do_call as do_call_conda_env
-from conda_env.exceptions import SpecNotFound
+from conda_env.exceptions import EnvironmentFileNotFound
 from conda_env.yaml import load as yaml_load
 
 environment_1 = '''
@@ -40,10 +40,12 @@
 test_env_name_2 = "snowflakes"
 test_env_name_3 = "env_foo"
 
+
 def escape_for_winpath(p):
     if p:
         return p.replace('\\', '\\\\')
 
+
 class Commands:
     ENV_CREATE = "create"
     ENV_REMOVE = "remove"
@@ -54,6 +56,7 @@ class Commands:
     INFO = "info"
     INSTALL = "install"
 
+
 def run_env_command(command, prefix, *arguments):
     """
         Run conda env commands
@@ -149,7 +152,17 @@ def test_conda_env_create_no_file(self):
         try:
             run_env_command(Commands.ENV_CREATE, None)
         except Exception as e:
-            self.assertIsInstance(e, SpecNotFound)
+            self.assertIsInstance(e, EnvironmentFileNotFound)
+
+    def test_conda_env_create_no_existent_file(self):
+        '''
+        Test `conda env create --file=not_a_file.txt` with a file that does not
+        exist.
+        '''
+        try:
+            run_env_command(Commands.ENV_CREATE, None, '--file not_a_file.txt')
+        except Exception as e:
+            self.assertIsInstance(e, EnvironmentFileNotFound)
 
     def test_create_valid_env(self):
         '''
@@ -164,8 +177,7 @@ def test_create_valid_env(self):
         o, e = run_conda_command(Commands.INFO, None, "--json")
         parsed = json.loads(o)
         self.assertNotEqual(
-            len([env for env in parsed['envs'] if env.endswith(test_env_name_1)]),
-            0
+            len([env for env in parsed['envs'] if env.endswith(test_env_name_1)]), 0
         )
 
     def test_update(self):
@@ -185,7 +197,7 @@ def test_name(self):
         try:
             run_env_command(Commands.ENV_CREATE, test_env_name_1, "create")
         except Exception as e:
-            self.assertIsInstance(e, SpecNotFound, str(e))
+            self.assertIsInstance(e, EnvironmentFileNotFound, str(e))
 
 
 def env_is_created(env_name):
@@ -321,5 +333,6 @@ def test_export_muti_channel(self):
         check2, e = run_conda_command(Commands.LIST, test_env_name_2, "--explicit")
         self.assertEqual(check1, check2)
 
+
 if __name__ == '__main__':
     unittest.main()