Repository: pypa/pipenv

Issue:
pipenv: error: no such option: --upgrade
Getting an no such option error with every install command.

##### Describe your environment

1. MacOS High Sierra
1. Python version: 2.7
1. Pipenv version: 8.3.2

##### Expected result

Just install the package

##### Actual result

```
$ pipenv install --verbose
Pipfile.lock not found, creating…
Locking [dev-packages] dependencies…
Locking [packages] dependencies…
Usage: pipenv [options]

Traceback (most recent call last):
  File "/Users/aleskocur-rubicoin/Library/Python/2.7/bin/pipenv", line 9, in <module>
    load_entry_point('pipenv==8.3.2', 'console_scripts', 'pipenv')()
  File "/Users/aleskocur-rubicoin/Library/Python/2.7/lib/python/site-packages/pipenv/vendor/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/Users/aleskocur-rubicoin/Library/Python/2.7/lib/python/site-packages/pipenv/vendor/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/Users/aleskocur-rubicoin/Library/Python/2.7/lib/python/site-packages/pipenv/vendor/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/aleskocur-rubicoin/Library/Python/2.7/lib/python/site-packages/pipenv/vendor/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/aleskocur-rubicoin/Library/Python/2.7/lib/python/site-packages/pipenv/vendor/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/Users/aleskocur-rubicoin/Library/Python/2.7/lib/python/site-packages/pipenv/cli.py", line 1866, in install
    do_init(dev=dev, allow_global=system, ignore_pipfile=ignore_pipfile, system=system, skip_lock=skip_lock, verbose=verbose, concurrent=concurrent, deploy=deploy, pre=pre)
  File "/Users/aleskocur-rubicoin/Library/Python/2.7/lib/python/site-packages/pipenv/cli.py", line 1330, in do_init
    do_lock(system=system, pre=pre)
  File "/Users/aleskocur-rubicoin/Library/Python/2.7/lib/python/site-packages/pipenv/cli.py", line 1121, in do_lock
    pre=pre
  File "/Users/aleskocur-rubicoin/Library/Python/2.7/lib/python/site-packages/pipenv/utils.py", line 426, in resolve_deps
    constraint = [c for c in pip.req.parse_requirements(t, session=pip._vendor.requests)][0]
  File "/Users/aleskocur-rubicoin/Library/Python/2.7/lib/python/site-packages/pipenv/patched/pip/req/req_file.py", line 93, in parse_requirements
    for req in req_iter:
  File "/Users/aleskocur-rubicoin/Library/Python/2.7/lib/python/site-packages/pipenv/patched/pip/req/req_file.py", line 140, in process_line
    opts, _ = parser.parse_args(shlex.split(options_str), defaults)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/optparse.py", line 1402, in parse_args
    self.error(str(err))
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/optparse.py", line 1584, in error
    self.exit(2, "%s: error: %s\n" % (self.get_prog_name(), msg))
  File "/Users/aleskocur-rubicoin/Library/Python/2.7/lib/python/site-packages/pipenv/patched/pip/req/req_file.py", line 284, in parser_exit
    raise RequirementsFileParseError(msg)
pip.exceptions.RequirementsFileParseError: pipenv: error: no such option: --upgrade
```

##### Steps to replicate

It started when I run by mistake `pipenv install [package] --upgrade`.



Discussion:
Ah. It added the `--upgrade` into my Pipfile as a dependency…
```
--upgrade = "*"
```
Just deleted it and it works. Weird error though.
yeah it got passed to the requirements parser as a requirement (since you told it to install a package), and the parser failed to parse that option since it isnn't one 

definitely shouldn't have been added to the pipfile though!

Resolving patch:
diff --git a/pipenv/cli.py b/pipenv/cli.py
--- a/pipenv/cli.py
+++ b/pipenv/cli.py
@@ -1352,7 +1352,22 @@ def pip_install(
             f.write(package_name)
 
     # Install dependencies when a package is a VCS dependency.
-    if get_requirement(package_name.split('--hash')[0].split('--trusted-host')[0]).vcs:
+    try:
+        req = get_requirement(package_name.split('--hash')[0].split('--trusted-host')[0]).vcs
+    except (pip._vendor.pyparsing.ParseException, ValueError) as e:
+        click.echo('{0}: {1}'.format(crayons.red('WARNING'), e), err=True)
+        click.echo(
+            '{0}... You will have to reinstall any packages that failed to install.'.format(
+                crayons.red('ABORTING INSTALL')
+            ), err=True
+        )
+        click.echo(
+            'You may have to manually run {0} when you are finished.'.format(
+                crayons.normal('pipenv lock', bold=True)
+            )
+        )
+        sys.exit(1)
+    if req:
         no_deps = False
 
         # Don't specify a source directory when using --system.


Test patch:
diff --git a/tests/test_pipenv.py b/tests/test_pipenv.py
--- a/tests/test_pipenv.py
+++ b/tests/test_pipenv.py
@@ -174,6 +174,16 @@ def test_man(self):
             c = p.pipenv('--man')
             assert c.return_code == 0 or c.err
 
+    @pytest.mark.cli
+    @pytest.mark.install
+    def test_install_parse_error(self):
+        with PipenvInstance() as p:
+            # Make sure unparseable packages don't wind up in the pipfile
+            # Escape $ for shell input
+            c = p.pipenv('install tablib u/\\/p@r\$34b13+pkg')
+            assert c.return_code != 0
+            assert 'u/\\/p@r$34b13+pkg' not in p.pipfile['packages']
+
     @pytest.mark.install
     @pytest.mark.setup
     @pytest.mark.skip(reason="this doesn't work on travis")