mirror of
https://github.com/checktheroads/hyperglass
synced 2024-05-11 05:55:08 +00:00
update import syntax for new isort version
This commit is contained in:
@@ -47,6 +47,7 @@ from hyperglass.util import set_app_path
|
||||
from hyperglass.constants import METADATA
|
||||
|
||||
try:
|
||||
# Third Party
|
||||
import stackprinter
|
||||
except ImportError:
|
||||
pass
|
||||
|
@@ -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:
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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()
|
||||
|
@@ -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()
|
||||
|
@@ -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
|
||||
|
1
hyperglass/external/_base.py
vendored
1
hyperglass/external/_base.py
vendored
@@ -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")
|
||||
|
@@ -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 = (
|
||||
"<lvl><b>[{level}]</b> {time:YYYYMMDD} {time:HH:mm:ss} <lw>|</lw> {name}<lw>:</lw>"
|
||||
|
@@ -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(
|
||||
|
@@ -86,7 +86,10 @@ class HyperglassModel(BaseModel):
|
||||
Returns:
|
||||
{str} -- Stringified YAML.
|
||||
"""
|
||||
# Standard Library
|
||||
import json
|
||||
|
||||
# Third Party
|
||||
import yaml
|
||||
|
||||
export_kwargs = {
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user