mirror of
https://github.com/checktheroads/hyperglass
synced 2024-05-11 05:55:08 +00:00
check the NodeJS version on startup, closes #105
This commit is contained in:
2
.flake8
2
.flake8
@@ -16,7 +16,7 @@ per-file-ignores=
|
||||
# Disable unused import warning for modules
|
||||
hyperglass/*/__init__.py:F401
|
||||
hyperglass/models/*/__init__.py:F401
|
||||
ignore=W503,C0330,R504,D202,S403,S301
|
||||
ignore=W503,C0330,R504,D202,S403,S301,S404
|
||||
select=B, BLK, C, D, E, F, I, II, N, P, PIE, S, R, W
|
||||
disable-noqa=False
|
||||
hang-closing=False
|
||||
|
@@ -13,6 +13,8 @@ METADATA = (__name__, __version__, __author__, __copyright__, __license__)
|
||||
|
||||
MIN_PYTHON_VERSION = (3, 6)
|
||||
|
||||
MIN_NODE_VERSION = 14
|
||||
|
||||
TARGET_FORMAT_SPACE = ("huawei", "huawei_vrpv8")
|
||||
|
||||
TARGET_JUNIPER_ASPATH = ("juniper", "juniper_junos")
|
||||
|
@@ -12,18 +12,27 @@ from gunicorn.arbiter import Arbiter
|
||||
from gunicorn.app.base import BaseApplication
|
||||
from gunicorn.glogging import Logger
|
||||
|
||||
# Project
|
||||
from hyperglass.log import log, setup_lib_logging
|
||||
from hyperglass.constants import MIN_PYTHON_VERSION, __version__
|
||||
# Local
|
||||
from .log import log, setup_lib_logging
|
||||
from .constants import MIN_NODE_VERSION, MIN_PYTHON_VERSION, __version__
|
||||
from .util.frontend import get_node_version
|
||||
|
||||
# Ensure the Python version meets the minimum requirements.
|
||||
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.")
|
||||
|
||||
# Project
|
||||
from hyperglass.cache import SyncCache
|
||||
# Ensure the NodeJS version meets the minimum requirements.
|
||||
node_version = get_node_version()
|
||||
|
||||
from hyperglass.configuration import ( # isort:skip
|
||||
if node_version != MIN_NODE_VERSION:
|
||||
raise RuntimeError(f"NodeJS {MIN_NODE_VERSION}+ is required.")
|
||||
|
||||
|
||||
# Local
|
||||
from .cache import SyncCache
|
||||
|
||||
from .configuration import ( # isort:skip
|
||||
params,
|
||||
URL_DEV,
|
||||
URL_PROD,
|
||||
@@ -31,12 +40,14 @@ from hyperglass.configuration import ( # isort:skip
|
||||
REDIS_CONFIG,
|
||||
frontend_params,
|
||||
)
|
||||
from hyperglass.util import ( # isort:skip
|
||||
from .util import ( # isort:skip
|
||||
cpu_count,
|
||||
build_frontend,
|
||||
clear_redis_cache,
|
||||
format_listen_address,
|
||||
)
|
||||
|
||||
|
||||
from hyperglass.compat._asyncio import aiorun # isort:skip
|
||||
|
||||
if params.debug:
|
||||
|
21
hyperglass/util/frontend.py
Normal file
21
hyperglass/util/frontend.py
Normal file
@@ -0,0 +1,21 @@
|
||||
"""Utility functions for frontend-related tasks."""
|
||||
|
||||
# Standard Library
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
|
||||
def get_node_version() -> int:
|
||||
"""Get the system's NodeJS version."""
|
||||
node_path = shutil.which("node")
|
||||
|
||||
raw_version = subprocess.check_output( # noqa: S603
|
||||
[node_path, "--version"]
|
||||
).decode()
|
||||
|
||||
# Node returns the version as 'v14.5.0', for example. Remove the v.
|
||||
version = raw_version.replace("v", "")
|
||||
# Parse the version parts.
|
||||
major, minor, patch = version.split(".")
|
||||
|
||||
return int(major)
|
Reference in New Issue
Block a user