Repository: pypa/pipenv

Issue:
Not able to use a remote url for --requirements
Take this example:

```
# pipenv install -r https://raw.githubusercontent.com/odoo/odoo/10.0/requirements.txt
Creating a virtualenv for this project…
⠋New python executable in /root/.local/share/virtualenvs/app-4PlAip0Q/bin/python
Installing setuptools, pip, wheel...done.

Virtualenv location: /root/.local/share/virtualenvs/app-4PlAip0Q
Creating a Pipfile for this project…
Requirements file provided! Importing into Pipfile…
Traceback (most recent call last):
  File "/usr/local/bin/pipenv", line 11, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python2.7/site-packages/pipenv/vendor/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/pipenv/vendor/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python2.7/site-packages/pipenv/vendor/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python2.7/site-packages/pipenv/vendor/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python2.7/site-packages/pipenv/vendor/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/pipenv/cli.py", line 1744, in install
    import_requirements(r=project.path_to(requirements), dev=dev)
  File "/usr/local/lib/python2.7/site-packages/pipenv/cli.py", line 234, in import_requirements
    assert os.path.isfile(r)
AssertionError
```

However, `pip install -r https://raw.githubusercontent.com/odoo/odoo/10.0/requirements.txt` works perfectly. I'd expect pipenv's version to work fine too.


Discussion:
@Yajo, pipenv does not currently support remote urls. I don't see a particular reason we can't, but it's not a feature that's been added yet. I'll take this as an enhancement for anyone who would like to put a PR for this together.

Resolving patch:
diff --git a/pipenv/cli.py b/pipenv/cli.py
--- a/pipenv/cli.py
+++ b/pipenv/cli.py
@@ -35,7 +35,7 @@
     convert_deps_from_pip, convert_deps_to_pip, is_required_version,
     proper_case, pep423_name, split_vcs, resolve_deps, shellquote, is_vcs,
     python_version, suggest_package, find_windows_executable, is_file,
-    prepare_pip_source_args, temp_environ
+    prepare_pip_source_args, temp_environ, is_valid_url, download_file
 )
 from .__version__ import __version__
 from . import pep508checker, progress
@@ -563,9 +563,9 @@ def ensure_virtualenv(three=None, python=None, site_packages=False):
 
     # If --three, --two, or --python were passed...
     elif (python) or (three is not None) or (site_packages is not False):
-       
+
         USING_DEFAULT_PYTHON = False
-        
+
         # Ensure python is installed before deleting existing virtual env
         ensure_python(three=three, python=python)
 
@@ -1745,9 +1745,27 @@ def install(
     if not pre:
         pre = project.settings.get('allow_prereleases')
 
+    # Using current time to generate a random filename to avoid
+    now = time.localtime()
+    temporary_requirements = "requirments{0}{1}{2}{3}{4}{5}.txt".format(
+        now.tm_year, now.tm_mon, now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec)
+    remote = requirements and is_valid_url(requirements)
+    # Check if the file is remote or not
+    if remote:
+        # Download requirements file
+        click.echo(crayons.normal(u'Remote requirements file provided! Downloading…',bold=True),err=True)
+        download_file(requirements, temporary_requirements)
+        # Replace the url with the temporary requirements file
+        requirements = temporary_requirements
+        remote = True
+
     if requirements:
         click.echo(crayons.normal(u'Requirements file provided! Importing into Pipfile…', bold=True), err=True)
         import_requirements(r=project.path_to(requirements), dev=dev)
+        # If requirements file was provided by remote url delete the temporary file
+
+    if remote:
+        os.remove(project.path_to(temporary_requirements))
 
     if code:
         click.echo(crayons.normal(u'Discovering imports from local codebase…', bold=True))
diff --git a/pipenv/utils.py b/pipenv/utils.py
--- a/pipenv/utils.py
+++ b/pipenv/utils.py
@@ -3,6 +3,7 @@
 import hashlib
 import tempfile
 import sys
+import shutil
 import logging
 
 import click
@@ -532,7 +533,6 @@ def convert_deps_from_pip(dep):
     req = [r for r in requirements.parse(dep)][0]
     extras = {'extras': req.extras}
 
-
     # File installs.
     if (req.uri or (os.path.isfile(req.path) if req.path else False) or
             os.path.isfile(req.name)) and not req.vcs:
@@ -929,3 +929,19 @@ def temp_environ():
     finally:
         os.environ.clear()
         os.environ.update(environ)
+
+def is_valid_url(url):
+    """Checks if a given string is an url"""
+    pieces = urlparse(url)
+    return all([pieces.scheme, pieces.netloc])
+
+
+def download_file(url, filename):
+    """Downloads file from url to a path with filename"""
+    r = requests.get(url, stream=True)
+    if not r.ok:
+        raise IOError('Unable to download file')
+
+    r.raw.decode_content = True
+    with open(filename, 'wb') as f:
+        shutil.copyfileobj(r.raw, f)


Test patch: