Skip to content

Commit 1149141

Browse files
authored
Merge pull request pypa#922 from Dreamersoul/master
fix for pypa#886
2 parents 1b1291f + e3e6495 commit 1149141

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

HISTORY.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
8.3.0:
2+
- Add installation from remote requiments file just like pip
13
8.2.7:
24
- Add update --sequential.
35
- Fix unicode decode error on windows.

pipenv/cli.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
convert_deps_from_pip, convert_deps_to_pip, is_required_version,
3636
proper_case, pep423_name, split_vcs, resolve_deps, shellquote, is_vcs,
3737
python_version, suggest_package, find_windows_executable, is_file,
38-
prepare_pip_source_args, temp_environ
38+
prepare_pip_source_args, temp_environ, is_valid_url, download_file
3939
)
4040
from .__version__ import __version__
4141
from . import pep508checker, progress
@@ -563,9 +563,9 @@ def ensure_virtualenv(three=None, python=None, site_packages=False):
563563

564564
# If --three, --two, or --python were passed...
565565
elif (python) or (three is not None) or (site_packages is not False):
566-
566+
567567
USING_DEFAULT_PYTHON = False
568-
568+
569569
# Ensure python is installed before deleting existing virtual env
570570
ensure_python(three=three, python=python)
571571

@@ -1745,9 +1745,27 @@ def install(
17451745
if not pre:
17461746
pre = project.settings.get('allow_prereleases')
17471747

1748+
# Using current time to generate a random filename to avoid
1749+
now = time.localtime()
1750+
temporary_requirements = "requirments{0}{1}{2}{3}{4}{5}.txt".format(
1751+
now.tm_year, now.tm_mon, now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec)
1752+
remote = requirements and is_valid_url(requirements)
1753+
# Check if the file is remote or not
1754+
if remote:
1755+
# Download requirements file
1756+
click.echo(crayons.normal(u'Remote requirements file provided! Downloading…',bold=True),err=True)
1757+
download_file(requirements, temporary_requirements)
1758+
# Replace the url with the temporary requirements file
1759+
requirements = temporary_requirements
1760+
remote = True
1761+
17481762
if requirements:
17491763
click.echo(crayons.normal(u'Requirements file provided! Importing into Pipfile…', bold=True), err=True)
17501764
import_requirements(r=project.path_to(requirements), dev=dev)
1765+
# If requirements file was provided by remote url delete the temporary file
1766+
1767+
if remote:
1768+
os.remove(project.path_to(temporary_requirements))
17511769

17521770
if code:
17531771
click.echo(crayons.normal(u'Discovering imports from local codebase…', bold=True))

pipenv/utils.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import hashlib
44
import tempfile
55
import sys
6+
import shutil
67
import logging
78

89
import click
@@ -532,7 +533,6 @@ def convert_deps_from_pip(dep):
532533
req = [r for r in requirements.parse(dep)][0]
533534
extras = {'extras': req.extras}
534535

535-
536536
# File installs.
537537
if (req.uri or (os.path.isfile(req.path) if req.path else False) or
538538
os.path.isfile(req.name)) and not req.vcs:
@@ -929,3 +929,19 @@ def temp_environ():
929929
finally:
930930
os.environ.clear()
931931
os.environ.update(environ)
932+
933+
def is_valid_url(url):
934+
"""Checks if a given string is an url"""
935+
pieces = urlparse(url)
936+
return all([pieces.scheme, pieces.netloc])
937+
938+
939+
def download_file(url, filename):
940+
"""Downloads file from url to a path with filename"""
941+
r = requests.get(url, stream=True)
942+
if not r.ok:
943+
raise IOError('Unable to download file')
944+
945+
r.raw.decode_content = True
946+
with open(filename, 'wb') as f:
947+
shutil.copyfileobj(r.raw, f)

0 commit comments

Comments
 (0)