From b3f645433a3b50c776d0a12135a1a2790fa7436f Mon Sep 17 00:00:00 2001 From: Kyle Altendorf Date: Fri, 4 May 2018 16:46:44 -0400 Subject: [PATCH 1/4] Fix grouping of extras requirements in notpip --- pipenv/patched/notpip/index.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/pipenv/patched/notpip/index.py b/pipenv/patched/notpip/index.py index bf1cba9c7f..07881b08c7 100644 --- a/pipenv/patched/notpip/index.py +++ b/pipenv/patched/notpip/index.py @@ -210,20 +210,16 @@ def get_extras_links(self, links): requires = [] extras = {} - current_section = None + current_list = requires for link in links: if not link: - current_section = None - - if not current_section: - if not (link.startswith('[')): - requires.append(link) - else: - current_section = link[1:-1] - extras[current_section] = [] + current_list = requires + if link.startswith('['): + current_list = [] + extras[link[1:-1]] = current_list else: - extras[current_section].append(link) + current_list.append(link) return extras From b53a365a277bcc793a240134144574802a01e8a1 Mon Sep 17 00:00:00 2001 From: Kyle Altendorf Date: Fri, 4 May 2018 22:43:11 -0400 Subject: [PATCH 2/4] Modify existing patch to include this modification --- tasks/vendoring/patches/patched/pip.patch | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tasks/vendoring/patches/patched/pip.patch b/tasks/vendoring/patches/patched/pip.patch index b8555c5b40..9e4b714d63 100644 --- a/tasks/vendoring/patches/patched/pip.patch +++ b/tasks/vendoring/patches/patched/pip.patch @@ -1366,25 +1366,25 @@ index f653f6e..48aaa35 100644 + requires = [] + extras = {} + -+ current_section = None ++ current_list = requires + + for link in links: + if not link: -+ current_section = None -+ -+ if not current_section: -+ if not (link.startswith('[')): -+ requires.append(link) -+ else: -+ current_section = link[1:-1] -+ extras[current_section] = [] ++ current_list = requires ++ if link.startswith('['): ++ current_list = [] ++ extras[link[1:-1]] = current_list + else: -+ extras[current_section].append(link) ++ current_list.append(link) + + return extras + + + ++ ++ ++ ++ + @staticmethod def _sort_locations(locations, expand_dir=False): From 1eb56b458bc0b0333d730121dd464983ddb140c5 Mon Sep 17 00:00:00 2001 From: Kyle Altendorf Date: Wed, 16 May 2018 21:56:49 -0400 Subject: [PATCH 3/4] @classmethod PackageFinder.get_extras_links() until it moves Not that I like @classmethod but it is honest here and lets the function be tested directly. --- pipenv/patched/notpip/index.py | 4 ++-- tasks/vendoring/patches/patched/pip.patch | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pipenv/patched/notpip/index.py b/pipenv/patched/notpip/index.py index 07881b08c7..f452c8c46b 100644 --- a/pipenv/patched/notpip/index.py +++ b/pipenv/patched/notpip/index.py @@ -206,7 +206,8 @@ def add_dependency_links(self, links): ) self.dependency_links.extend(links) - def get_extras_links(self, links): + @staticmethod + def get_extras_links(links): requires = [] extras = {} @@ -225,7 +226,6 @@ def get_extras_links(self, links): - @staticmethod def _sort_locations(locations, expand_dir=False): """ diff --git a/tasks/vendoring/patches/patched/pip.patch b/tasks/vendoring/patches/patched/pip.patch index 9e4b714d63..8e06880677 100644 --- a/tasks/vendoring/patches/patched/pip.patch +++ b/tasks/vendoring/patches/patched/pip.patch @@ -1362,7 +1362,8 @@ index f653f6e..48aaa35 100644 ) self.dependency_links.extend(links) -+ def get_extras_links(self, links): ++ @classmethod ++ def get_extras_links(links): + requires = [] + extras = {} + @@ -1384,7 +1385,6 @@ index f653f6e..48aaa35 100644 + + + -+ + @staticmethod def _sort_locations(locations, expand_dir=False): From 3b7929daa8cd6370ae64b1294d8f0dddb18e4ede Mon Sep 17 00:00:00 2001 From: Kyle Altendorf Date: Wed, 16 May 2018 23:07:09 -0400 Subject: [PATCH 4/4] Add a few test cases for PackageFinder.get_extras_links() --- tests/unit/test_patched.py | 131 +++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 tests/unit/test_patched.py diff --git a/tests/unit/test_patched.py b/tests/unit/test_patched.py new file mode 100644 index 0000000000..8d396539fb --- /dev/null +++ b/tests/unit/test_patched.py @@ -0,0 +1,131 @@ +from __future__ import absolute_import + +import pytest + +from notpip.index import PackageFinder + + +get_extras_links_scenarios = { + 'windows and not windows': ( + [ + 'chardet', + '[:platform_system != "windows"]', + 'twisted', + '[:platform_system == "windows"]', + 'twisted[windows_platform]', + ], + { + ':platform_system != "windows"': [ + 'twisted', + ], + ':platform_system == "windows"': [ + 'twisted[windows_platform]', + ], + }, + ), + 'requests': ( + [ + 'chardet<3.1.0,>=3.0.2', + 'idna<2.7,>=2.5', + 'urllib3<1.23,>=1.21.1', + 'certifi>=2017.4.17', + '[security]', + 'pyOpenSSL>=0.14', + 'cryptography>=1.3.4', + 'idna>=2.0.0', + '[socks]', + 'PySocks!=1.5.7,>=1.5.6', + ( + '[socks:sys_platform == "win32"' + ' and (python_version == "2.7" or python_version == "2.6")]' + ), + 'win_inet_pton', + ], + { + 'security': [ + 'pyOpenSSL>=0.14', + 'cryptography>=1.3.4', + 'idna>=2.0.0', + ], + 'socks': [ + 'PySocks!=1.5.7,>=1.5.6', + ], + 'socks:sys_platform == "win32" ' + 'and (python_version == "2.7" or python_version == "2.6")': [ + 'win_inet_pton', + ], + } + ), + 'attrs': ( + [ + '[dev]', + 'coverage', + 'hypothesis', + 'pympler', + 'pytest', + 'six', + 'zope.interface', + 'sphinx', + 'zope.interface', + '[docs]', + 'sphinx', + 'zope.interface', + '[tests]', + 'coverage', + 'hypothesis', + 'pympler', + 'pytest', + 'six', + 'zope.interface', + ], + { + 'dev': [ + 'coverage', + 'hypothesis', + 'pympler', + 'pytest', + 'six', + 'zope.interface', + 'sphinx', + 'zope.interface', + ], + 'docs': [ + 'sphinx', + 'zope.interface', + ], + 'tests': [ + 'coverage', + 'hypothesis', + 'pympler', + 'pytest', + 'six', + 'zope.interface', + ], + }, + ), + 'misc': ( + [ + 'chardet', + '[:platform_system != "windows"]', + 'attrs', + '[:platform_system == "windows"]', + 'pytz', + ], + { + ':platform_system != "windows"': [ + 'attrs', + ], + ':platform_system == "windows"': [ + 'pytz', + ], + }, + ), +} + +@pytest.mark.parametrize( + 'scenarios,expected', + list(get_extras_links_scenarios.values()), + ids=list(get_extras_links_scenarios.keys()), +) +def test_get_extras_links(scenarios, expected): + assert PackageFinder.get_extras_links(scenarios) == expected