Repository: ESSS/conda-devenv

Issue:
Add --version flag

Discussion:

Patch:
diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst
index 2be5977..ddda924 100644
--- a/CONTRIBUTING.rst
+++ b/CONTRIBUTING.rst
@@ -55,9 +55,9 @@ If you are proposing a feature:
 Get Started!
 ------------
 
-Ready to contribute? Here's how to set up `conda-devenv` for local development.
+Ready to contribute? Here's how to set up ``conda-devenv`` for local development.
 
-1. Fork the `conda-devenv` repo on GitHub.
+1. Fork the ``conda-devenv`` repo on GitHub.
 2. Clone your fork locally::
 
     $ git clone git@github.com:your_name_here/conda-devenv.git
@@ -65,7 +65,8 @@ Ready to contribute? Here's how to set up `conda-devenv` for local development.
 3. Create a new conda environment for developing::
 
     $ conda create -n devenv --file requirements_dev.txt
-    $ conda develop conda_devenv
+    $ source activate devenv
+    $ pip install -e .
 
 4. Create a branch for local development::
 
diff --git a/conda_devenv/devenv.py b/conda_devenv/devenv.py
index 8591c61..4e43d3a 100644
--- a/conda_devenv/devenv.py
+++ b/conda_devenv/devenv.py
@@ -48,7 +48,7 @@ def handle_includes(root_filename, root_yaml):
                     ))
             with open(included_filename, "r") as f:
                 jinja_contents = render_jinja(f.read(), included_filename)
-            included_yaml_dict = yaml.load(jinja_contents)
+            included_yaml_dict = yaml.safe_load(jinja_contents)
             if included_yaml_dict is None:
                 raise ValueError("The file '{included_filename}' which was"
                                  " included by '{filename}' is empty."
@@ -329,7 +329,6 @@ def write_activate_deactivate_scripts(args, conda_yaml_dict, environment):
     info = json.loads(info)
     envs = info["envs"]
 
-    env_directory = None
     for env in envs:
         if os.path.basename(env) == env_name:
             env_directory = env
@@ -376,12 +375,21 @@ def main(args=None):
                                              "includes the 'environment' section.", action="store_true")
     parser.add_argument("--no-prune", help="Don't pass --prune flag to conda-env.", action="store_true")
     parser.add_argument("--output-file", nargs="?", help="Output filename.")
-    parser.add_argument("--quiet", action="store_true", default=False)
+    parser.add_argument("--quiet", action="store_true", default=False, help="Do not show progress")
+    parser.add_argument("--version", action="store_true", default=False, help="Show version and exit")
 
     args = parser.parse_args(args)
 
+    if args.version:
+        from ._version import version
+        print('conda-devenv version {0}'.format(version))
+        return 0
+
     filename = args.file
     filename = os.path.abspath(filename)
+    if not os.path.isfile(filename):
+        print('File "{0}" does not exist.'.format(filename), file=sys.stderr)
+        return 1
 
     is_devenv_input_file = filename.endswith('.devenv.yml')
     if is_devenv_input_file:
diff --git a/requirements_dev.txt b/requirements_dev.txt
index a41d034..c2c73e0 100644
--- a/requirements_dev.txt
+++ b/requirements_dev.txt
@@ -8,6 +8,6 @@ coverage
 Sphinx
 cryptography
 PyYAML
-pytest
+pytest >= 3
 pytest-datadir >= 1.0
 pytest-mock
diff --git a/setup.py b/setup.py
index c8e4a86..158e834 100644
--- a/setup.py
+++ b/setup.py
@@ -52,6 +52,7 @@ setup(
         'Programming Language :: Python :: 3',
         'Programming Language :: Python :: 3.4',
         'Programming Language :: Python :: 3.5',
+        'Programming Language :: Python :: 3.6',
     ],
     test_suite='tests',
     tests_require=test_requirements


Test patch:
diff --git a/tests/test_main.py b/tests/test_main.py
index feb2425..f1e1a27 100644
--- a/tests/test_main.py
+++ b/tests/test_main.py
@@ -90,3 +90,27 @@ def test_print_full(tmpdir, capsys):
     assert 'environment:' in out
     assert 'PYTHONPATH:' in out
 
+
+def test_version(capsys):
+    """
+    Test --version flag.
+    """
+    from conda_devenv._version import version
+    assert devenv.main(['--version']) == 0
+    out, err = capsys.readouterr()
+    assert err == ''
+    assert version in out
+
+    import conda_devenv
+    assert conda_devenv.__version__ == version
+
+
+@pytest.mark.parametrize('explicit_file', [True, False])
+def test_error_message_environment_file_not_found(capsys, tmpdir, explicit_file, monkeypatch):
+    monkeypatch.chdir(str(tmpdir))
+    args = ['--file', 'invalid.devenv.yml'] if explicit_file else []
+    expected_name = 'invalid.devenv.yml' if explicit_file else 'environment.devenv.yml'
+    assert devenv.main(args) == 1
+    out, err = capsys.readouterr()
+    assert out == ''
+    assert err == 'File "{0}" does not exist.\n'.format(str(tmpdir / expected_name))