Repository: common-workflow-language/cwltool

Issue:
bug in cwltool when trying to run a tool with environment modules
Currently trying to use cwltool on our cluster using environment modules (@khillion and me), we have the following issue: the use of modules crashes cwltool, because it tries to store job_description dict and other informations in files opened in binary mode. here's the traceback that comes after trying it:

```pytb
$ cwltool --beta-dependency-resolvers-configuration dependency-resolvers-conf.yml mafft.cwl mafft_solo.yml 
/pasteur/homes/kehillio/cwl/.venv/cwl/bin/cwltool 1.0.20171227212058
Resolved 'mafft.cwl' to 'file:///pasteur/homes/kehillio/cwl/cwl-phylogeny-test/mafft.cwl'
  Field `$schemas` contains undefined reference to `http://schema.org/docs/schema_org_rdfa.html`
mafft.cwl:3:1: unrecognized extension field `http://schema.org/about`.  Did you include a $schemas section?
mafft.cwl:3:1: unrecognized extension field `http://schema.org/keywords`.  Did you include a $schemas section?
mafft.cwl:3:1: unrecognized extension field `http://schema.org/name`.  Did you include a $schemas section?
mafft.cwl:3:1: unrecognized extension field `http://schema.org/publication`.  Did you include a $schemas section?
mafft.cwl:3:1: unrecognized extension field `http://schema.org/url`.  Did you include a $schemas section?
[job mafft.cwl] /local/scratch/tmpui_5lt4a$ mafft \
    --auto \
    /local/scratch/tmplluf2dg6/stg23f8872d-59d9-499b-921e-c89552bf397d/sequences.fa > /local/scratch/tmpui_5lt4a/mafft_alignment.fa
Exception while running job
Traceback (most recent call last):
  File "/pasteur/homes/kehillio/cwl/.venv/cwl/lib/python3.6/site-packages/cwltool/job.py", line 224, in _execute
    job_script_contents=job_script_contents,
  File "/pasteur/homes/kehillio/cwl/.venv/cwl/lib/python3.6/site-packages/cwltool/job.py", line 552, in _job_popen
    json.dump(job_description, f)
  File "/local/gensoft2/exe/Python/3.6.0/lib/python3.6/json/__init__.py", line 180, in dump
    fp.write(chunk)
TypeError: a bytes-like object is required, not 'str'
@hmenager
```

## Your Environment
* cwltool version: 
cwltool 1.0.20180109130208


Discussion:

Resolving patch:
diff --git a/cwltool/job.py b/cwltool/job.py
--- a/cwltool/job.py
+++ b/cwltool/job.py
@@ -1,4 +1,5 @@
 from __future__ import absolute_import
+import codecs
 import functools
 import io
 import json
@@ -549,14 +550,14 @@ def _job_popen(
             stdin_path=stdin_path,
         )
         with open(os.path.join(job_dir, "job.json"), "wb") as f:
-            json.dump(job_description, f)
+            json.dump(job_description, codecs.getwriter('utf-8')(f), ensure_ascii=False) # type: ignore
         try:
             job_script = os.path.join(job_dir, "run_job.bash")
             with open(job_script, "wb") as f:
                 f.write(job_script_contents.encode('utf-8'))
             job_run = os.path.join(job_dir, "run_job.py")
             with open(job_run, "wb") as f:
-                f.write(PYTHON_RUN_SCRIPT)
+                f.write(PYTHON_RUN_SCRIPT.encode('utf-8'))
             sp = subprocess.Popen(
                 ["bash", job_script.encode("utf-8")],
                 shell=False,


Test patch: