From 8d19cf159f19a6b02c66badc9eab39d451934f75 Mon Sep 17 00:00:00 2001 From: checktheroads Date: Mon, 30 Dec 2019 23:00:53 -0700 Subject: [PATCH] bump min Python version to 3.7; check python version at start --- hyperglass/constants.py | 2 ++ hyperglass/hyperglass.py | 8 ++++++++ hyperglass/util.py | 18 ++++++++++++++++++ setup.py | 6 +++--- 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/hyperglass/constants.py b/hyperglass/constants.py index 84e0f58..b24db16 100644 --- a/hyperglass/constants.py +++ b/hyperglass/constants.py @@ -2,6 +2,8 @@ # Standard Library Imports import sys +MIN_PYTHON_VERSION = (3, 7) + protocol_map = {80: "http", 8080: "http", 443: "https", 8443: "https"} target_format_space = ("huawei", "huawei_vrpv8") diff --git a/hyperglass/hyperglass.py b/hyperglass/hyperglass.py index a78a00f..0458bd6 100644 --- a/hyperglass/hyperglass.py +++ b/hyperglass/hyperglass.py @@ -39,9 +39,17 @@ from hyperglass.exceptions import ResponseEmpty from hyperglass.exceptions import RestError from hyperglass.exceptions import ScrapeError from hyperglass.render import render_html +from hyperglass.util import check_python from hyperglass.util import cpu_count from hyperglass.util import log +# Verify Python version meets minimum requirement +try: + python_version = check_python() + log.info(f"Python {python_version} detected.") +except RuntimeError as r: + raise HyperglassError(str(r), alert="danger") from None + log.debug(f"Configuration Parameters: {params.dict(by_alias=True)}") tempdir = tempfile.TemporaryDirectory(prefix="hyperglass_") diff --git a/hyperglass/util.py b/hyperglass/util.py index 02a921c..a582003 100644 --- a/hyperglass/util.py +++ b/hyperglass/util.py @@ -24,4 +24,22 @@ def cpu_count(): return multiprocessing.cpu_count() +def check_python(): + """Verify Python Version. + + Raises: + RuntimeError: Raised if running Python version is invalid. + + Returns: + {str} -- Python version + """ + import sys + from hyperglass.constants import MIN_PYTHON_VERSION + + pretty_version = ".".join(tuple(str(v) for v in MIN_PYTHON_VERSION)) + if sys.version_info < MIN_PYTHON_VERSION: + raise RuntimeError(f"Python {pretty_version}+ is required.") + return pretty_version + + log = _logger() diff --git a/setup.py b/setup.py index c545a1d..3ef1b3b 100644 --- a/setup.py +++ b/setup.py @@ -2,8 +2,8 @@ import sys from distutils.core import setup -if sys.version_info < (3, 6): - sys.exit("Python 3.6+ is required.") +if sys.version_info < (3, 7): + sys.exit("Python 3.7+ is required.") with open("README.md", "r") as ld: @@ -21,7 +21,7 @@ setup( author_email="matt@hyperglass.io", description=desc, url="https://github.com/checktheroads/hyperglass", - python_requires=">=3.6", + python_requires=">=3.7", packages=["hyperglass"], install_requires=requirements, license="BSD 3-Clause Clear License",