Repository: weecology/retriever

Issue:
Wrap retriever_minimum_version value in str() in compile
On line 241 of `compile.py` the call to `value` should be changed to `str(value)`. It is natural for people to think of version numbers as numbers and if they accidentally enter `2.0` instead of `"2.0"` this causes a type failure.

Stop bad scripts from causing errors
Currently when `compile_json` gets run if something goes wrong the retriever errors out even on commands not running the script (e.g., `retriever ls`). What it should do is ignore the bad script and possibly report back that there is an issue with the script but keep running normally otherwise.



Discussion:

@ethanwhite Can you post an example error trace so I can look into the issue?

To reproduce:
1. Change the `"retriever_minimum_version"` value in `MoM2003.json` to `2.0` from `"2.0.0-dev"`.
2. Run `retriever ls`

```
ethan@croryx:~$ retriever ls
Traceback (most recent call last):
  File "/home/ethan/anaconda/bin/retriever", line 9, in <module>
    load_entry_point('retriever===2.0.0-de', 'console_scripts', 'retriever')()
  File "/home/ethan/anaconda/lib/python2.7/site-packages/setuptools-20.2.2-py2.7.egg/pkg_resources/__init__.py", line 549, in load_entry_point
  File "/home/ethan/anaconda/lib/python2.7/site-packages/setuptools-20.2.2-py2.7.egg/pkg_resources/__init__.py", line 2542, in load_entry_point
  File "/home/ethan/anaconda/lib/python2.7/site-packages/setuptools-20.2.2-py2.7.egg/pkg_resources/__init__.py", line 2202, in load
  File "/home/ethan/anaconda/lib/python2.7/site-packages/setuptools-20.2.2-py2.7.egg/pkg_resources/__init__.py", line 2208, in resolve
  File "/home/ethan/anaconda/lib/python2.7/site-packages/retriever/__main__.py", line 29, in <module>
    from retriever.lib.datapackage import create_json, edit_json
  File "/home/ethan/anaconda/lib/python2.7/site-packages/retriever/lib/datapackage.py", line 8, in <module>
    short_names = [script.shortname.lower() for script in SCRIPT_LIST()]
  File "/home/ethan/anaconda/lib/python2.7/site-packages/retriever/__init__.py", line 111, in SCRIPT_LIST
    return [module.SCRIPT for module in MODULE_LIST(force_compile)]
  File "/home/ethan/anaconda/lib/python2.7/site-packages/retriever/__init__.py", line 78, in MODULE_LIST
    compile_json(join(search_path, script_name))
  File "/home/ethan/anaconda/lib/python2.7/site-packages/retriever/lib/compile.py", line 241, in compile_json
    values["retriever_minimum_version"] = "\"" + value + "\""
TypeError: cannot concatenate 'str' and 'float' objects
```


Resolving patch:
diff --git a/lib/compile.py b/lib/compile.py
--- a/lib/compile.py
+++ b/lib/compile.py
@@ -92,7 +92,7 @@ def compile_script(script_file):
                     tables[last_table][key] = "'" + str(e) + "'"
             else:
                 # general script attributes
-                values[key] = '"' + value + '"'
+                values[key] = '"' + str(value) + '"'
 
     if 'shortname' not in list(values.keys()):
         try:
@@ -216,19 +216,19 @@ def compile_json(json_file):
     for (key, value) in json_object.items():
 
         if key == "title":
-            values["name"] = "\"" + value + "\""
+            values["name"] = "\"" + str(value) + "\""
 
         elif key == "name":
-            values["shortname"] = "\"" + value + "\""
+            values["shortname"] = "\"" + str(value) + "\""
 
         elif key == "description":
-            values["description"] = "\"" + value + "\""
+            values["description"] = "\"" + str(value) + "\""
 
         elif key == "homepage":
-            values["ref"] = "\"" + value + "\""
+            values["ref"] = "\"" + str(value) + "\""
 
         elif key == "citation":
-            values["citation"] = "\"" + value + "\""
+            values["citation"] = "\"" + str(value) + "\""
 
         elif key == "keywords":
             values["tags"] = value


Test patch: