Checks if the environment.yml file is empty and if it contains a dictionary.
If the environment.yml is empty, an empty dictionary is instantiated.
This will rise an TypeError if the environment.yml file contains a list
or other data structure different than a dictionary.
MODIFY
repo2docker/buildpacks/conda/__init__.py
repo2docker/buildpacks/conda/__init__.py
@@ -136,6 +136,12 @@ class CondaBuildPack(BaseImage):
py_version = None
with open(environment_yml) as f:
env = YAML().load(f)
+ # check if the env file is empty, if so instantiate an empty dictionary.
+ if env is None:
+ env = {}
+ # check if the env file has a dictionary not a list or other data structure.
+ if not isinstance(env, dict):
+ raise TypeError("environment.yml should contain a dictionary. Got %r" % env)
for dep in env.get('dependencies', []):
if not isinstance(dep, str):
continue

ADD
tests/test_env_yml.py
+"""
+Test if the environment.yml is empty or it constains other data structure than a dictionary
+"""
+import os
+import sys
+import pytest
+from repo2docker import buildpacks
+
+#@pytest.mark.xfail(reason="Not yet implemented")
+def test_empty_env_yml(tmpdir):
+ tmpdir.chdir()
+ p = tmpdir.join("environment.yml")
+ bp = buildpacks.CondaBuildPack()
+ with pytest.raises(Exception):
+ py_ver = bp.python_version()
+
+def test_no_dict_env_yml(tmpdir):
+ tmpdir.chdir()
+ q = tmpdir.join("environment.yml")
+ q.write("list/n ,string")
+ bq = buildpacks.CondaBuildPack()
+ with pytest.raises(Exception):
+ py_ver = bq.python_version()
\ No newline at end of file

Checks if the environment.yml file is empty and if it contains a dictionary.

If the environment.yml is empty, an empty dictionary is instantiated.
This will rise an TypeError if the environment.yml file contains a list
or other data structure different than a dictionary.