Repository: ESSS/conda-devenv

Issue:
0.9.3 broken: no longer generates activate/deactivate scripts
#46 introduced a bug: `conda-devenv` now calls `conda_env.main` directly, which probably calls `sys.exit()`, which skips activate/deactivate scripts generation.

Discussion:

Patch:
diff --git a/HISTORY.rst b/HISTORY.rst
index 796bf32..608aaa0 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -3,6 +3,14 @@ History
 =======
 
 
+0.9.4 (2017-04-20)
+------------------
+
+* Fixed major bug where activate/deactivate scripts were not being generated (`#49`_).
+
+.. _`#49`: https://github.com/ESSS/conda-devenv/issues/49
+
+
 0.9.3 (2017-04-10)
 ------------------
 
diff --git a/conda_devenv/devenv.py b/conda_devenv/devenv.py
index 66b6bf9..16d174c 100644
--- a/conda_devenv/devenv.py
+++ b/conda_devenv/devenv.py
@@ -269,7 +269,10 @@ def __call_conda_env_update(args, output_filename):
     try:
         del command[0]
         sys.argv = command
-        return _call_conda()
+        try:
+            return _call_conda()
+        except SystemExit as e:
+            return e.code
     finally:
         sys.argv = old_argv
 


Test patch:
diff --git a/tests/test_main.py b/tests/test_main.py
index 3fd56e2..4f0db10 100644
--- a/tests/test_main.py
+++ b/tests/test_main.py
@@ -17,19 +17,20 @@ def patch_conda_calls(mocker):
     mocker.patch.object(devenv, 'write_activate_deactivate_scripts', autospec=True)
 
 
-@pytest.mark.parametrize('input_name, expected_output_name', [
-    ('environment.devenv.yml', 'environment.yml'),
-    ('environment.yml', 'environment.yml'),
+@pytest.mark.parametrize('input_name, write_scripts_call_count', [
+    ('environment.devenv.yml', 1),
+    ('environment.yml', 0),
 ])
 @pytest.mark.usefixtures('patch_conda_calls')
-def test_handle_input_file(tmpdir, input_name, expected_output_name):
+def test_handle_input_file(tmpdir, input_name, write_scripts_call_count):
     """
     Test how conda-devenv handles input files: devenv.yml and pure .yml files.
     """
     argv = []
     def call_conda_mock():
         argv[:] = sys.argv[:]
-        return 0
+        # simulate that we actually called conda's main, which calls sys.exit()
+        sys.exit(0)
 
     devenv._call_conda.side_effect = call_conda_mock
     
@@ -41,8 +42,9 @@ def test_handle_input_file(tmpdir, input_name, expected_output_name):
     '''))
     assert devenv.main(['--file', str(filename), '--quiet']) == 0
     assert devenv._call_conda.call_count == 1
-    cmdline = 'env update --file {} --prune --quiet'.format(tmpdir.join(expected_output_name))
+    cmdline = 'env update --file {} --prune --quiet'.format(tmpdir.join('environment.yml'))
     assert argv == cmdline.split()
+    assert devenv.write_activate_deactivate_scripts.call_count == write_scripts_call_count
 
 
 @pytest.mark.parametrize('input_name', ['environment.devenv.yml', 'environment.yml'])