Skip to content

Commit

Permalink
make write_json just use write_file(...json.dumps())
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Beck committed Aug 8, 2018
1 parent 7c8260c commit d05173d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
5 changes: 2 additions & 3 deletions dbt/clients/system.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import errno
import fnmatch
import json
import os
import os.path
import shutil
Expand Down Expand Up @@ -119,9 +120,7 @@ def write_file(path, contents=''):


def write_json(path, data):
make_directory(os.path.dirname(path))
dbt.compat.write_json(path, data, cls=dbt.utils.JSONEncoder)
return True
return write_file(path, json.dumps(data, cls=dbt.utils.JSONEncoder))


def _windows_rmdir_readonly(func, path, exc):
Expand Down
18 changes: 5 additions & 13 deletions dbt/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,10 @@ def to_string(s):
return str(s)


def _open(path, mode):
def write_file(path, s):
if WHICH_PYTHON == 2:
return codecs.open(path, mode, encoding='utf-8')
with codecs.open(path, 'w', encoding='utf-8') as f:
return f.write(to_string(s))
else:
return open(path, 'w')


def write_file(path, s):
with _open(path, 'w') as fp:
return fp.write(to_string(s))


def write_json(path, data, **kwargs):
with _open(path, 'w') as fp:
json.dump(data, fp, **kwargs)
with open(path, 'w') as f:
return f.write(to_string(s))

0 comments on commit d05173d

Please sign in to comment.