Repository: pypa/pipenv

Issue:
vcrpy failing in python3
I'm hitting issues when install the latest `vcrpy` under pipenv `11.8.3`. 

##### Expected result

I'm running `pipenv lock -v ` and its barking on `vcrpy` 's dependencies. specifically looks like `yarl` and the `python_version` syntax. It seems like `pipenv` is adding some duplication to what i see in the vcrpy dependency list.

##### Actual result

Here's a dump from my shell:

```bash
$ pipenv lock -v                                                                                                                                                                                                
Locking [dev-packages] dependencies…                                                                                                                                                                               
Using pip: -i https://pypi.python.org/simple                                                                                                                                                                       
                                                                                                                                                                                                                   
                          ROUND 1                                                                                                                                                                                  
Current constraints:                                                                                                                                                                                               
  factory_boy                                                                                                                                                                                                      
  vcrpy==1.10.5                                                                                                                                                                                                    
                                                                                                                                                                                                                   
Finding the best candidates:                                                                                                                                                                                       
  found candidate factory-boy==2.10.0 (constraint was <any>)                                                                                                                                                       
  found candidate vcrpy==1.10.5 (constraint was ==1.10.5)                                                                                                                                                          
                                                                                                                                                                                                                   
Finding secondary dependencies:                                                                                                                                                                                    
  factory-boy==2.10.0       requires Faker>=0.7.0                                                                                                                                                                  
  vcrpy==1.10.5             requires PyYAML, six>=1.5, wrapt, yarl; python_version in "3.4, 3.5, 3.6"; python_version in "3.4, 3.5, 3.6"                                                                           
                                                                                                                                                                                                                   
INFO:pip9._vendor.requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): pypi.python.org                                                                                                      
Traceback (most recent call last):                                                                                                                                                                                 
  File "/home/mike/.local/lib/python2.7/site-packages/pipenv/patched/notpip/_vendor/packaging/markers.py", line 278, in __init__                                                                                   
    self._markers = _coerce_parse_result(MARKER.parseString(marker))                                                                                                                                               
  File "/home/mike/.local/lib/python2.7/site-packages/pipenv/vendor/pip9/_vendor/pyparsing.py", line 1617, in parseString                                                                                          
    raise exc                                                                                                                                                                                                      
  File "/home/mike/.local/lib/python2.7/site-packages/pipenv/vendor/pip9/_vendor/pyparsing.py", line 1607, in parseString                                                                                          
    loc, tokens = self._parse( instring, 0 )                                                                                                                                                                       
  File "/home/mike/.local/lib/python2.7/site-packages/pipenv/vendor/pip9/_vendor/pyparsing.py", line 1379, in _parseNoCache                                                                                        
    loc,tokens = self.parseImpl( instring, preloc, doActions )                                                                                                                                                     
  File "/home/mike/.local/lib/python2.7/site-packages/pipenv/vendor/pip9/_vendor/pyparsing.py", line 3376, in parseImpl                                                                                            
    loc, exprtokens = e._parse( instring, loc, doActions )                                                                                                                                                         
  File "/home/mike/.local/lib/python2.7/site-packages/pipenv/vendor/pip9/_vendor/pyparsing.py", line 1383, in _parseNoCache                                                                                        
    loc,tokens = self.parseImpl( instring, preloc, doActions )                                                                                                                                                     
  File "/home/mike/.local/lib/python2.7/site-packages/pipenv/vendor/pip9/_vendor/pyparsing.py", line 3164, in parseImpl                                                                                            
    raise ParseException(instring, loc, self.errmsg, self)                                                                                                                                                         
pip9._vendor.pyparsing.ParseException: Expected stringEnd (at char 28), (line:1, col:29)                                                                                                                           
                                                                                                                                                                                                                   
During handling of the above exception, another exception occurred:                                                                                                                                                
                                                                                                                                                                                                                   
Traceback (most recent call last):
  File "/home/mike/.local/lib/python2.7/site-packages/pipenv/patched/piptools/resolver.py", line 329, in _iter_dependencies
    yield InstallRequirement.from_line(_dependency_string, constraint=ireq.constraint)
  File "/home/mike/.local/lib/python2.7/site-packages/pipenv/patched/notpip/req/req_install.py", line 181, in from_line
    markers = Marker(markers)
  File "/home/mike/.local/lib/python2.7/site-packages/pipenv/patched/notpip/_vendor/packaging/markers.py", line 282, in __init__
    raise InvalidMarker(err_str)
notpip._vendor.packaging.markers.InvalidMarker: Invalid marker: 'python_version in "3.4, 3.6"; python_version in "3.4', parse error at '; python'


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/mike/.local/lib/python2.7/site-packages/pipenv/patched/notpip/_vendor/packaging/markers.py", line 278, in __init__
    self._markers = _coerce_parse_result(MARKER.parseString(marker))
  File "/home/mike/.local/lib/python2.7/site-packages/pipenv/vendor/pip9/_vendor/pyparsing.py", line 1617, in parseString
    raise exc
  File "/home/mike/.local/lib/python2.7/site-packages/pipenv/vendor/pip9/_vendor/pyparsing.py", line 1607, in parseString
    loc, tokens = self._parse( instring, 0 )
  File "/home/mike/.local/lib/python2.7/site-packages/pipenv/vendor/pip9/_vendor/pyparsing.py", line 1379, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/home/mike/.local/lib/python2.7/site-packages/pipenv/vendor/pip9/_vendor/pyparsing.py", line 3376, in parseImpl
    loc, exprtokens = e._parse( instring, loc, doActions )
  File "/home/mike/.local/lib/python2.7/site-packages/pipenv/vendor/pip9/_vendor/pyparsing.py", line 1383, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/home/mike/.local/lib/python2.7/site-packages/pipenv/vendor/pip9/_vendor/pyparsing.py", line 3164, in parseImpl
    raise ParseException(instring, loc, self.errmsg, self)
pip9._vendor.pyparsing.ParseException: Expected stringEnd (at char 33), (line:1, col:34)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/mike/.local/lib/python2.7/site-packages/pipenv/resolver.py", line 82, in <module>
    main()
  File "/home/mike/.local/lib/python2.7/site-packages/pipenv/resolver.py", line 71, in main
    clear=do_clear,
  File "/home/mike/.local/lib/python2.7/site-packages/pipenv/resolver.py", line 63, in resolve
    verbose=verbose,
  File "/home/mike/.local/lib/python2.7/site-packages/pipenv/utils.py", line 425, in resolve_deps
    pre,
  File "/home/mike/.local/lib/python2.7/site-packages/pipenv/utils.py", line 336, in actually_resolve_reps
    resolved_tree.update(resolver.resolve(max_rounds=PIPENV_MAX_ROUNDS))
  File "/home/mike/.local/lib/python2.7/site-packages/pipenv/patched/piptools/resolver.py", line 102, in resolve
    has_changed, best_matches = self._resolve_one_round()
  File "/home/mike/.local/lib/python2.7/site-packages/pipenv/patched/piptools/resolver.py", line 200, in _resolve_one_round
    for dep in self._iter_dependencies(best_match):
  File "/home/mike/.local/lib/python2.7/site-packages/pipenv/patched/piptools/resolver.py", line 331, in _iter_dependencies
    yield InstallRequirement.from_line(dependency_string, constraint=ireq.constraint)
  File "/home/mike/.local/lib/python2.7/site-packages/pipenv/patched/notpip/req/req_install.py", line 181, in from_line
    markers = Marker(markers)
  File "/home/mike/.local/lib/python2.7/site-packages/pipenv/patched/notpip/_vendor/packaging/markers.py", line 282, in __init__
    raise InvalidMarker(err_str)
notpip._vendor.packaging.markers.InvalidMarker: Invalid marker: 'python_version in "3.4, 3.5, 3.6"; python_version in "3.4, 3.5, 3.6"', parse error at '; python'

```




##### Steps to replicate

See my `Pipfile` output below in the system debug. This doesn't seem to be an error when I remove the python requirements in the Pipfile and it uses my system default (python2).


Here's my system debug output.
------------
<details><summary>$ python -m pipenv.help output</summary>

Pipenv version: `'11.8.3'`

Pipenv location: `'/home/mike/.local/lib/python2.7/site-packages/pipenv'`

Python location: `'/usr/bin/python'`

Other Python installations in `PATH`:

  - `2.7`: `/usr/bin/python2.7`
  - `2.7`: `/usr/bin/python2.7`
  - `3.5`: `/usr/bin/python3.5m`
  - `3.5`: `/usr/bin/python3.5`

  - `2.7.13`: `/usr/bin/python`
  - `2.7.13`: `/usr/bin/python2`
  - `3.5.3`: `/usr/bin/python3`

PEP 508 Information:

```
{'implementation_name': 'cpython',
 'implementation_version': '0',
 'os_name': 'posix',
 'platform_machine': 'x86_64',
 'platform_python_implementation': 'CPython',
 'platform_release': '4.14.24-grsec',
 'platform_system': 'Linux',
 'platform_version': '#1 SMP Sun Mar 4 20:08:15 UTC 2018',
 'python_full_version': '2.7.13',
 'python_version': '2.7',
 'sys_platform': 'linux2'}
```

System environment variables:

  - `SVN_EDITOR`
  - `_ZSH_TMUX_FIXED_CONFIG`
  - `LESS`
  - `GNOME_DESKTOP_SESSION_ID`
  - `ZSH_TMUX_AUTOSTART`
  - `GJS_DEBUG_OUTPUT`
  - `LC_CTYPE`
  - `WINDOWPATH`
  - `XDG_CURRENT_DESKTOP`
  - `XDG_SESSION_TYPE`
  - `LOGNAME`
  - `USER`
  - `HOME`
  - `XDG_VTNR`
  - `PATH`
  - `PYTHONUNBUFFERED`
  - `VIRTUALENVWRAPPER_SCRIPT`
  - `ZSH`
  - `DISPLAY`
  - `XDG_SESSION_DESKTOP`
  - `LANG`
  - `TERM`
  - `SHELL`
  - `SSH_AGENT_PID`
  - `XAUTHORITY`
  - `JOURNAL_STREAM`
  - `SESSION_MANAGER`
  - `SHLVL`
  - `QT_LINUX_ACCESSIBILITY_ALWAYS_ON`
  - `QT_QPA_PLATFORMTHEME`
  - `ZSH_TMUX_AUTOQUIT`
  - `QT_ACCESSIBILITY`
  - `WINDOWID`
  - `AUTO_NTFY_DONE_LONGER_THAN`
  - `EDITOR`
  - `ZSH_TMUX_AUTOSTARTED`
  - `AND_SDK`
  - `_VIRTUALENVWRAPPER_API`
  - `GPG_AGENT_INFO`
  - `ZSH_TMUX_TERM`
  - `USERNAME`
  - `WORKON_HOME`
  - `XDG_RUNTIME_DIR`
  - `AND_ADT`
  - `VIRTUALENVWRAPPER_PROJECT_FILENAME`
  - `SSH_AUTH_SOCK`
  - `VTE_VERSION`
  - `TMUX`
  - `GDMSESSION`
  - `PS1`
  - `PYTHONDONTWRITEBYTECODE`
  - `PIPENV_ACTIVE`
  - `PIP_PYTHON_PATH`
  - `XDG_SESSION_ID`
  - `DBUS_SESSION_BUS_ADDRESS`
  - `_`
  - `VIRTUALENVWRAPPER_HOOK_DIR`
  - `ANSIBLE_NOCOWS`
  - `DESKTOP_SESSION`
  - `LSCOLORS`
  - `GTK_MODULES`
  - `AUTO_NTFY_DONE_IGNORE`
  - `OLDPWD`
  - `GDM_LANG`
  - `GEM_HOME`
  - `XDG_DATA_DIRS`
  - `PWD`
  - `COLORTERM`
  - `XDG_MENU_PREFIX`
  - `LS_COLORS`
  - `PAGER`
  - `GJS_DEBUG_TOPICS`
  - `TMUX_PANE`
  - `XDG_SEAT`


Pipenv–specific environment variables:                                                                                                                                                                             
                                                                                                                                                                                                                   
 - `PIPENV_ACTIVE`: `1`                                                                                                                                                                                            
                                                                                                                                                                                                                   
Debug–specific environment variables:                                                                                                                                                                              
                                                                                                                                                                                                                   
  - `PATH`: `/home/mike/.gem/ruby/2.3.0/bin:/home/mike/.local/bin:/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games`                                                         
  - `SHELL`: `/usr/bin/zsh`                                                                                                                                                                                        
  - `EDITOR`: `vim`                                                                                                                                                                                                
  - `LANG`: `en_US.UTF-8`                                                                                                                                                                                          
  - `PWD`: `/home/mike/Documents/Gits/securedrop.org`                                                                                                                                                              


---------------------------

Contents of `Pipfile` ('/home/mike/Documents/Gits/securedrop.org/Pipfile'):

```toml
[[source]]

verify_ssl = true
url = "https://pypi.python.org/simple"
name = "pypi"

[requires]
python_version = "3"


[packages]

wagtail = "<1.13"
zxcvbn-python = "*"


[dev-packages]

factory_boy = "*"
# https://github.com/kevin1024/vcrpy/issues/342
vcrpy = "==1.10.5"

```

</details>




Discussion:
Hm, I think this is related to #1624. 

Resolving patch:
diff --git a/pipenv/patched/piptools/resolver.py b/pipenv/patched/piptools/resolver.py
--- a/pipenv/patched/piptools/resolver.py
+++ b/pipenv/patched/piptools/resolver.py
@@ -310,7 +310,9 @@ def _iter_dependencies(self, ireq):
         for dependency_string in dependency_strings:
 
             try:
-                individual_dependencies = [dep.strip() for dep in dependency_string.split(', ')]
+                split_deps = dependency_string.split(';')
+                dependencies, markers = split_deps[0], '; '.join(list(set([marker.strip() for marker in split_deps[1:]])))
+                individual_dependencies = [dep.strip() for dep in dependencies.split(', ')]
                 cleaned_deps = []
                 for dep in individual_dependencies:
                     tokens = [token.strip() for token in dep.split(';')]
@@ -325,6 +327,7 @@ def _iter_dependencies(self, ireq):
                         cleaned_tokens.extend(markers)
                     cleaned_deps.append('; '.join(cleaned_tokens))
                 _dependency_string = ', '.join(set(cleaned_deps))
+                _dependency_string += '; {0}'.format(markers)
 
                 yield InstallRequirement.from_line(_dependency_string, constraint=ireq.constraint)
             except InvalidMarker:


Test patch: