Repository: conda/conda-pack

Issue:
Properly handle root environment
The root environment is different than sub-environments in a couple key ways:

- The path contains extra directories like the package cache, `conda-bld` directory, etc...
- The environment contains conda itself, and may contain packages that depend on it (these are forbidden in sub-environments)

A few options for handling the root environment:
- Special case the handling to directories/files that shouldn't be packed, and packages that depend on conda
- Error nicely and tell the user to create a sub-environment

I'm not sure which would be more expected. The second is a lot easier to implement.

Discussion:

Patch:
diff --git a/conda_pack/core.py b/conda_pack/core.py
index 12478c2..c2b5655 100644
--- a/conda_pack/core.py
+++ b/conda_pack/core.py
@@ -659,6 +659,10 @@ def load_environment(prefix, unmanaged=True, on_missing_cache='warn'):
     if not os.path.exists(conda_meta):
         raise CondaPackException("Path %r is not a conda environment" % prefix)
 
+    # Check that it's not the root environment
+    if any(os.path.exists(os.path.join(prefix, d)) for d in ['pkgs', 'envs']):
+        raise CondaPackException("Cannot package root environment")
+
     # Find the environment site_packages (if any)
     site_packages = find_site_packages(prefix)
 


Test patch:
diff --git a/conda_pack/tests/test_core.py b/conda_pack/tests/test_core.py
index ccafe44..b2b7306 100644
--- a/conda_pack/tests/test_core.py
+++ b/conda_pack/tests/test_core.py
@@ -1,5 +1,6 @@
 from __future__ import absolute_import, print_function, division
 
+import json
 import os
 import subprocess
 import tarfile
@@ -62,6 +63,16 @@ def test_errors_editable_packages():
     assert "Editable packages found" in str(exc.value)
 
 
+def test_errors_root_environment():
+    info = subprocess.check_output("conda info --json", shell=True).decode()
+    root_prefix = json.loads(info)['root_prefix']
+
+    with pytest.raises(CondaPackException) as exc:
+        CondaEnv.from_prefix(root_prefix)
+
+    assert "Cannot package root environment" in str(exc.value)
+
+
 def test_env_properties(py36_env):
     assert py36_env.name == 'py36'
     assert py36_env.prefix == py36_path