Skip to content

Commit

Permalink
[#2504] Serialize prettytoml ArrayElements as lists
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobHayes committed Jul 11, 2018
1 parent f0a1413 commit 6e05a3e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pipenv/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import six
import toml
import json as simplejson
from prettytoml.elements.array import ArrayElement

from ._compat import Path

Expand Down Expand Up @@ -64,6 +65,12 @@ def _normalized(p):
DEFAULT_NEWLINES = u"\n"


def encode_toml_elements(obj):
if isinstance(obj, ArrayElement):
return obj.primitive_value
raise TypeError(repr(obj) + " is not JSON serializable")


def preferred_newlines(f):
if isinstance(f.newlines, six.text_type):
return f.newlines
Expand Down Expand Up @@ -631,7 +638,8 @@ def write_lockfile(self, content):
"""
newlines = self._lockfile_newlines
s = simplejson.dumps( # Send Unicode in to guarentee Unicode out.
content, indent=4, separators=(u",", u": "), sort_keys=True
content, indent=4, separators=(u",", u": "), sort_keys=True,
default=encode_toml_elements,
)
with atomic_open_for_write(self.lockfile_location, newline=newlines) as f:
f.write(s)
Expand Down

0 comments on commit 6e05a3e

Please sign in to comment.