diff --git a/Pipfile b/Pipfile index 31cb0e1d..39de0874 100644 --- a/Pipfile +++ b/Pipfile @@ -11,6 +11,9 @@ pew = ">=0.1.26" pep8 = "*" pytest = "*" pip-tools = "*" +background = "*" +semver = "*" +requests = "*" [requires] python_version = "3.6" diff --git a/Pipfile.lock b/Pipfile.lock index ff21f656..73384df5 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,8 +1,9 @@ { "_meta": { "hash": { - "sha256": "76e3894ec377275576c53e478d0ecc005d0886027f0bb2962bc14faee96bb0e1" + "sha256": "f89bcf3e88bd0c33e5a924e59417f55eba7ff56069860f3faf1c57eaf269e979" }, + "pipfile-spec": 1, "requires": { "python_version": "3.6" }, @@ -14,6 +15,9 @@ ] }, "default": { + "background": { + "version": "==0.1.0" + }, "certifi": { "version": "==2017.7.27.1" }, @@ -53,6 +57,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..8e25e564 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', timeout=0.5) + 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: diff --git a/setup.py b/setup.py index 8853bcb1..759e527c 100644 --- a/setup.py +++ b/setup.py @@ -26,7 +26,8 @@ required = [ 'pew>=0.1.26', 'pip', 'pip-tools>=1.9.0', - 'setuptools>=36.3.0' + 'setuptools>=36.3.0', + 'background' ] if sys.version_info < (2, 7):