From f0a1413c70847c6604f3b9a0a1944f9afa07b704 Mon Sep 17 00:00:00 2001 From: Jacob Hayes Date: Tue, 10 Jul 2018 20:41:34 -0500 Subject: [PATCH 1/5] [#2504] Add test for VCS dep with extras --- tests/integration/test_lock.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/tests/integration/test_lock.py b/tests/integration/test_lock.py index 1ab34f1b..eebfaf39 100644 --- a/tests/integration/test_lock.py +++ b/tests/integration/test_lock.py @@ -1,6 +1,5 @@ import pytest import os -import six from pipenv.utils import temp_environ @@ -348,6 +347,28 @@ requests = {git = "https://github.com/requests/requests.git", ref = "master", ed 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 = ["security"]} + """.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 'cryptography' in p.lockfile['default'] + assert 'pyOpenSSL' in p.lockfile['default'] + 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): From 6e05a3e0d27182b21381455751fcff0ec57f7d53 Mon Sep 17 00:00:00 2001 From: Jacob Hayes Date: Tue, 10 Jul 2018 20:58:57 -0500 Subject: [PATCH 2/5] [#2504] Serialize prettytoml ArrayElements as lists --- pipenv/project.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pipenv/project.py b/pipenv/project.py index 7f40576d..d0d21c3e 100644 --- a/pipenv/project.py +++ b/pipenv/project.py @@ -14,6 +14,7 @@ import pipfile.api import six import toml import json as simplejson +from prettytoml.elements.array import ArrayElement from ._compat import Path @@ -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 @@ -631,7 +638,8 @@ class Project(object): """ 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) From 6de915ab79f5e23383f510ef70b6b389a40e51e8 Mon Sep 17 00:00:00 2001 From: Jacob Hayes Date: Wed, 11 Jul 2018 08:19:42 -0500 Subject: [PATCH 3/5] [#2504] Replace security extra with socks in test --- tests/integration/test_lock.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/integration/test_lock.py b/tests/integration/test_lock.py index eebfaf39..67da46b9 100644 --- a/tests/integration/test_lock.py +++ b/tests/integration/test_lock.py @@ -356,15 +356,14 @@ def test_lock_editable_vcs_with_extras_without_install(PipenvInstance, pypi): with open(p.pipfile_path, 'w') as f: f.write(""" [packages] -requests = {git = "https://github.com/requests/requests.git", editable = true, extras = ["security"]} +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 'cryptography' in p.lockfile['default'] - assert 'pyOpenSSL' in p.lockfile['default'] + assert 'pysocks' in p.lockfile['default'] c = p.pipenv('install') assert c.return_code == 0 From 1ceccb9bdf20d7b54913a886a3b6273c40366e1c Mon Sep 17 00:00:00 2001 From: Jacob Hayes Date: Wed, 11 Jul 2018 23:32:43 -0500 Subject: [PATCH 4/5] Fix extras check in test --- tests/integration/test_lock.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/test_lock.py b/tests/integration/test_lock.py index 67da46b9..25195bfb 100644 --- a/tests/integration/test_lock.py +++ b/tests/integration/test_lock.py @@ -363,7 +363,7 @@ requests = {git = "https://github.com/requests/requests.git", editable = true, e assert 'requests' in p.lockfile['default'] assert 'idna' in p.lockfile['default'] assert 'chardet' in p.lockfile['default'] - assert 'pysocks' in p.lockfile['default'] + assert "socks" in p.lockfile["default"]["requests"]["extras"] c = p.pipenv('install') assert c.return_code == 0 From dbc9008131f5c9684e6b5336a4ca2993f518d9a6 Mon Sep 17 00:00:00 2001 From: Jacob Hayes Date: Thu, 12 Jul 2018 08:05:58 -0500 Subject: [PATCH 5/5] Duck type prettytoml types during serialization --- pipenv/project.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pipenv/project.py b/pipenv/project.py index d0d21c3e..918c7184 100644 --- a/pipenv/project.py +++ b/pipenv/project.py @@ -14,7 +14,6 @@ import pipfile.api import six import toml import json as simplejson -from prettytoml.elements.array import ArrayElement from ._compat import Path @@ -66,7 +65,7 @@ DEFAULT_NEWLINES = u"\n" def encode_toml_elements(obj): - if isinstance(obj, ArrayElement): + if hasattr(obj, 'primitive_value'): return obj.primitive_value raise TypeError(repr(obj) + " is not JSON serializable")