diff --git a/hyperglass/__init__.py b/hyperglass/__init__.py index 196c842..96d45a2 100644 --- a/hyperglass/__init__.py +++ b/hyperglass/__init__.py @@ -47,6 +47,7 @@ from hyperglass.util import set_app_path from hyperglass.constants import METADATA try: + # Third Party import stackprinter except ImportError: pass diff --git a/hyperglass/api/__init__.py b/hyperglass/api/__init__.py index a172c0c..d2a8a96 100644 --- a/hyperglass/api/__init__.py +++ b/hyperglass/api/__init__.py @@ -262,6 +262,7 @@ app.mount("/", StaticFiles(directory=UI_DIR, html=True), name="ui") def start(**kwargs): """Start the web server with Uvicorn ASGI.""" + # Third Party import uvicorn try: diff --git a/hyperglass/api/models/query.py b/hyperglass/api/models/query.py index 10c69cb..8ed0a3e 100644 --- a/hyperglass/api/models/query.py +++ b/hyperglass/api/models/query.py @@ -7,7 +7,7 @@ import secrets from datetime import datetime # Third Party -from pydantic import BaseModel, StrictStr, validator, constr +from pydantic import BaseModel, StrictStr, constr, validator # Project from hyperglass.exceptions import InputInvalid diff --git a/hyperglass/api/models/rfc8522.py b/hyperglass/api/models/rfc8522.py index 9d55dd1..b546e85 100644 --- a/hyperglass/api/models/rfc8522.py +++ b/hyperglass/api/models/rfc8522.py @@ -10,7 +10,6 @@ from datetime import datetime # Third Party from pydantic import BaseModel, StrictInt, StrictStr, StrictFloat, constr, validator - """Patterns: GET /.well-known/looking-glass/v1/ping/2001:DB8::35?protocol=2,1 GET /.well-known/looking-glass/v1/traceroute/192.0.2.8?routerindex=5 diff --git a/hyperglass/cli/commands.py b/hyperglass/cli/commands.py index 383cce0..6d641e7 100644 --- a/hyperglass/cli/commands.py +++ b/hyperglass/cli/commands.py @@ -23,6 +23,7 @@ supports_color = "utf" in sys.getfilesystemencoding().lower() def _print_version(ctx, param, value): + # Project from hyperglass import __version__ if not value or ctx.resilient_parsing: @@ -96,8 +97,9 @@ def build_frontend(): def start(build, direct, workers): """Start web server and optionally build frontend assets.""" try: - from hyperglass.main import start + # Project from hyperglass.api import start as uvicorn_start + from hyperglass.main import start except ImportError as e: error("Error importing hyperglass: {}", str(e)) @@ -139,6 +141,7 @@ def generate_secret(length): Arguments: length {int} -- Length of secret """ + # Standard Library import secrets gen_secret = secrets.token_urlsafe(length) @@ -161,13 +164,14 @@ def generate_secret(length): ) def setup(unattended): """Define application directory, move example files, generate systemd service.""" + # Project from hyperglass.cli.util import ( create_dir, move_files, make_systemd, write_to_file, - migrate_static_assets, install_systemd, + migrate_static_assets, ) user_path = Path.home() / "hyperglass" @@ -242,6 +246,7 @@ def setup(unattended): ) def get_system_info(): """Get CPU, Memory, Disk, Python, & hyperglass version.""" + # Project from hyperglass.cli.util import system_info system_info() diff --git a/hyperglass/cli/util.py b/hyperglass/cli/util.py index f164491..5eca9ad 100644 --- a/hyperglass/cli/util.py +++ b/hyperglass/cli/util.py @@ -17,6 +17,7 @@ PROJECT_ROOT = Path(__file__).parent.parent def async_command(func): """Decororator for to make async functions runable from synchronous code.""" + # Standard Library import asyncio from functools import update_wrapper @@ -31,9 +32,10 @@ def async_command(func): def fix_ownership(user, group, directory): """Make user & group the owner of the directory.""" + # Standard Library + import os import grp import pwd - import os uid = pwd.getpwnam(user).pw_uid gid = grp.getgrnam(group).gr_gid @@ -54,6 +56,7 @@ def fix_ownership(user, group, directory): def fix_permissions(directory): """Make directory readable by public.""" + # Standard Library import os try: @@ -107,6 +110,7 @@ def migrate_config(config_dir): """Copy example config files and remove .example extensions.""" status("Migrating example config files...") + # Standard Library import shutil examples = Path(PROJECT_ROOT / "examples").glob("*.yaml.example") @@ -138,6 +142,7 @@ def migrate_config(config_dir): def migrate_systemd(source, destination): """Copy example systemd service file to /etc/systemd/system/.""" + # Standard Library import os import shutil @@ -165,9 +170,10 @@ def build_ui(): ClickException: Raised on any errors. """ try: - from hyperglass.compat._asyncio import aiorun + # Project from hyperglass.util import build_frontend - from hyperglass.configuration import params, frontend_params, CONFIG_PATH + from hyperglass.configuration import CONFIG_PATH, params, frontend_params + from hyperglass.compat._asyncio import aiorun except ImportError as e: error("Error importing UI builder: {e}", e=e) @@ -296,6 +302,7 @@ def make_systemd(user): {str} -- Generated systemd template """ + # Third Party import distro template = """ @@ -364,6 +371,7 @@ def migrate_static_assets(app_path): Arguments: app_path {Path} -- hyperglass runtime path """ + # Project from hyperglass.util import migrate_static_assets as _migrate migrated, msg, a, b = _migrate(app_path) @@ -410,6 +418,7 @@ def system_info(): Returns: {str}: Markdown table """ + # Project from hyperglass.util.system_info import get_system_info values = get_system_info() diff --git a/hyperglass/compat/_asyncio.py b/hyperglass/compat/_asyncio.py index 68e5961..8cfeed9 100644 --- a/hyperglass/compat/_asyncio.py +++ b/hyperglass/compat/_asyncio.py @@ -6,8 +6,10 @@ import asyncio import weakref try: + # Standard Library from asyncio import get_running_loop except ImportError: + # Standard Library from asyncio.events import _get_running_loop as get_running_loop RUNNING_PYTHON_VERSION = sys.version_info diff --git a/hyperglass/external/_base.py b/hyperglass/external/_base.py index f317a9a..be867d6 100644 --- a/hyperglass/external/_base.py +++ b/hyperglass/external/_base.py @@ -152,6 +152,7 @@ class BaseExternal: def _build_request(self, **kwargs): """Process requests parameters into structure usable by http library.""" + # Standard Library from operator import itemgetter supported_methods = ("GET", "POST", "PUT", "DELETE", "HEAD", "PATCH") diff --git a/hyperglass/log.py b/hyperglass/log.py index 4e3c01c..058e1d0 100644 --- a/hyperglass/log.py +++ b/hyperglass/log.py @@ -7,9 +7,9 @@ from datetime import datetime # Third Party from loguru import logger as _loguru_logger -from rich.logging import RichHandler -from rich.console import Console from rich.theme import Theme +from rich.console import Console +from rich.logging import RichHandler _FMT_FILE = ( "[{level}] {time:YYYYMMDD} {time:HH:mm:ss} | {name}:" diff --git a/hyperglass/main.py b/hyperglass/main.py index 311facf..011bcc3 100644 --- a/hyperglass/main.py +++ b/hyperglass/main.py @@ -83,6 +83,7 @@ async def clear_cache(): async def cache_config(): """Add configuration to Redis cache as a pickled object.""" + # Standard Library import pickle cache = AsyncCache( @@ -101,6 +102,7 @@ def on_starting(server: Arbiter): log.info("Python {} detected ({} required)", python_version, required) async def runner(): + # Standard Library from asyncio import gather await gather(build_ui(), cache_config()) @@ -156,6 +158,7 @@ class HyperglassWSGI(BaseApplication): def start(**kwargs): """Start hyperglass via gunicorn.""" + # Project from hyperglass.api import app HyperglassWSGI( diff --git a/hyperglass/models.py b/hyperglass/models.py index b9608da..2c48534 100644 --- a/hyperglass/models.py +++ b/hyperglass/models.py @@ -86,7 +86,10 @@ class HyperglassModel(BaseModel): Returns: {str} -- Stringified YAML. """ + # Standard Library import json + + # Third Party import yaml export_kwargs = { diff --git a/hyperglass/util/__init__.py b/hyperglass/util/__init__.py index 9a1741a..85c02e9 100644 --- a/hyperglass/util/__init__.py +++ b/hyperglass/util/__init__.py @@ -29,6 +29,7 @@ def cpu_count(multiplier: int = 0): Returns: {int} -- CPU Cores """ + # Standard Library import multiprocessing return multiprocessing.cpu_count() * multiplier @@ -81,8 +82,11 @@ def check_python() -> str: Returns: {str} -- Python version """ + # Standard Library import sys import platform + + # Project from hyperglass.constants import MIN_PYTHON_VERSION pretty_version = ".".join(tuple(str(v) for v in MIN_PYTHON_VERSION)) @@ -176,6 +180,7 @@ async def check_redis(db: int, config: Dict) -> bool: Returns: {bool} -- True if redis is running. """ + # Third Party import aredis redis_instance = aredis.StrictRedis(db=db, **config) @@ -203,6 +208,7 @@ async def clear_redis_cache(db: int, config: Dict) -> bool: Returns: {bool} -- True if cache was cleared. """ + # Third Party import aredis try: @@ -222,6 +228,7 @@ async def move_files(src, dst, files): # noqa: C901 files {Iterable} -- Iterable of files """ + # Standard Library from typing import Iterable def error(*args, **kwargs): @@ -275,6 +282,7 @@ async def move_files(src, dst, files): # noqa: C901 def migrate_static_assets(app_path): """Synchronize the project assets with the installation assets.""" + # Standard Library from filecmp import dircmp asset_dir = Path(__file__).parent.parent / "images" @@ -382,6 +390,7 @@ async def read_package_json(): {dict} -- NPM package.json as dict """ + # Standard Library import json package_json_file = Path(__file__).parent.parent / "ui" / "package.json" @@ -407,6 +416,7 @@ def generate_opengraph( background_color: str, ): """Generate an OpenGraph compliant image.""" + # Third Party from PIL import Image def center_point(background: Image, foreground: Image): @@ -571,11 +581,14 @@ async def build_frontend( # noqa: C901 Returns: {bool} -- True if successful """ + # Standard Library import hashlib import tempfile + # Third Party from favicons import Favicons + # Project from hyperglass.constants import __version__ env_file = Path("/tmp/hyperglass.env.json") # noqa: S108 @@ -704,6 +717,7 @@ async def build_frontend( # noqa: C901 def set_app_path(required=False): """Find app directory and set value to environment variable.""" + # Standard Library from getpass import getuser matched_path = None diff --git a/validate_examples.py b/validate_examples.py index 4013d5c..d3498a8 100644 --- a/validate_examples.py +++ b/validate_examples.py @@ -50,6 +50,7 @@ def _comment_optional_files(): def _validate_devices(): + # Project from hyperglass.configuration.models.devices import Devices with DEVICES.open() as raw: @@ -62,6 +63,7 @@ def _validate_devices(): def _validate_commands(): + # Project from hyperglass.configuration.models.commands import Commands with COMMANDS.open() as raw: @@ -74,6 +76,7 @@ def _validate_commands(): def _validate_main(): + # Project from hyperglass.configuration.models.params import Params with MAIN.open() as raw: