From 62f666c481cda9b9032fa42bc8ae31ae3bcf4224 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Thu, 2 Apr 2020 15:19:13 +0530 Subject: [PATCH] feat: check for newer versions on PyPI --- bench/cli.py | 3 ++- bench/utils.py | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/bench/cli.py b/bench/cli.py index f5891d0a..39b60954 100755 --- a/bench/cli.py +++ b/bench/cli.py @@ -1,6 +1,6 @@ import click import os, sys, logging, json, pwd, subprocess -from bench.utils import is_root, PatchError, drop_privileges, get_env_cmd, get_cmd_output, get_frappe, log, is_dist_editable, find_parent_bench +from bench.utils import is_root, PatchError, drop_privileges, get_env_cmd, get_cmd_output, get_frappe, log, is_dist_editable, find_parent_bench, check_latest_version from bench.app import get_apps from bench.config.common_site_config import get_config from bench.commands import bench_command @@ -42,6 +42,7 @@ def cli(): else: try: # NOTE: this is the main bench command + check_latest_version() bench_command() except PatchError: sys.exit(1) diff --git a/bench/utils.py b/bench/utils.py index 6fb985fc..ec49201f 100755 --- a/bench/utils.py +++ b/bench/utils.py @@ -21,6 +21,7 @@ from distutils.spawn import find_executable # imports - third party imports import click import requests +from semantic_version import Version from six import iteritems from six.moves.urllib.parse import urlparse @@ -80,6 +81,18 @@ def safe_decode(string, encoding = 'utf-8'): return string +def check_latest_version(): + pypi_request = requests.get("https://pypi.org/pypi/frappe-bench/json") + + if pypi_request.status_code == 200: + pypi_version_str = pypi_request.json().get('info').get('version') + pypi_version = Version(pypi_version_str) + local_version = Version(bench.__version__) + + if pypi_version > local_version: + log("A newer version of bench is available: {0} → {1}".format(local_version, pypi_version)) + + def get_frappe(bench_path='.'): frappe = get_env_cmd('frappe', bench_path=bench_path) if not os.path.exists(frappe):