Skip to content

Commit

Permalink
Merge branch '2504-fix-array-element-serialization' of https://github…
Browse files Browse the repository at this point in the history
….com/JacobHayes/pipenv into 2504-fix-array-element-serialization
  • Loading branch information
uranusjr committed Jul 13, 2018
2 parents 94fbfe4 + b1ecc68 commit 5cedecd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
9 changes: 8 additions & 1 deletion pipenv/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ def _normalized(p):
DEFAULT_NEWLINES = u"\n"


def encode_toml_elements(obj):
if hasattr(obj, 'primitive_value'):
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 +637,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
22 changes: 21 additions & 1 deletion tests/integration/test_lock.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import pytest
import os
import six

from pipenv.utils import temp_environ

Expand Down Expand Up @@ -348,6 +347,27 @@ def test_lock_editable_vcs_without_install(PipenvInstance, pypi):
assert c.return_code == 0


@pytest.mark.extras
@pytest.mark.lock
@pytest.mark.vcs
@pytest.mark.needs_internet
def test_lock_editable_vcs_with_extras_without_install(PipenvInstance, pypi):
with PipenvInstance(pypi=pypi, chdir=True) as p:
with open(p.pipfile_path, 'w') as f:
f.write("""
[packages]
requests = {git = "https://github.com/requests/requests.git", editable = true, extras = ["socks"]}
""".strip())
c = p.pipenv('lock')
assert c.return_code == 0
assert 'requests' in p.lockfile['default']
assert 'idna' in p.lockfile['default']
assert 'chardet' in p.lockfile['default']
assert "socks" in p.lockfile["default"]["requests"]["extras"]
c = p.pipenv('install')
assert c.return_code == 0


@pytest.mark.lock
@pytest.mark.skip(reason="This doesn't work for some reason.")
def test_lock_respecting_python_version(PipenvInstance, pypi):
Expand Down

0 comments on commit 5cedecd

Please sign in to comment.