diff --git a/Pipfile b/Pipfile index 723567f8..a5e48c31 100644 --- a/Pipfile +++ b/Pipfile @@ -12,6 +12,7 @@ pep8 = "*" pytest = "*" pip-tools = "*" background = "*" +semver = "*" [requires] python_version = "3.6" diff --git a/Pipfile.lock b/Pipfile.lock index f1c03154..52f20bd7 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "bd2336c28dabc3c3cadf760e0f49a28b6403e13ff6d2623694879836fe29e56b" + "sha256": "38b59dc070cded14f6a19f827b3423f34761232e0563da9e0c733e650bc0423c" }, "pipfile-spec": 1, "requires": { @@ -72,6 +72,9 @@ "resumable-urlretrieve": { "version": "==0.1.5" }, + "semver": { + "version": "==2.7.8" + }, "six": { "version": "==1.10.0" }, diff --git a/pipenv/cli.py b/pipenv/cli.py index 5b250fb3..b667dfc9 100644 --- a/pipenv/cli.py +++ b/pipenv/cli.py @@ -8,6 +8,7 @@ import distutils.spawn import shutil import signal +import background import click import click_completion import crayons @@ -16,6 +17,7 @@ import parse import pexpect import requests import pipfile +import semver from blindspin import spinner from requests.packages.urllib3.exceptions import InsecureRequestWarning @@ -60,6 +62,21 @@ requests.packages.urllib3.disable_warnings(InsecureRequestWarning) project = Project() +@background.task +def check_for_updates(): + try: + r = requests.get('https://pypi.python.org/pypi/pipenv/json') + latest = sorted([semver.parse_version_info(v) for v in list(r.json()['releases'].keys())])[-1] + current = semver.parse_version_info(__version__) + + if latest > current: + click.echo('{0}: {1} is now available. You get bonus points for upgrading!'.format( + crayons.green('Courtesy Notice'), + crayons.yellow('Pipenv v{v.major}.{v.minor}.{v.patch}'.format(v=latest)), + ), err=True) + except Exception: + pass + def cleanup_virtualenv(bare=True): """Removes the virtualenv directory from the system.""" @@ -790,6 +807,8 @@ def easter_egg(package_name): @click.pass_context def cli(ctx, where=False, venv=False, rm=False, bare=False, three=False, python=False, help=False): + check_for_updates() + if ctx.invoked_subcommand is None: # --where was passed... if where: