From 014c7a4b7a40e8169681eb3990e8747ab3543f77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Pedro=20Oliveira?= Date: Thu, 4 Apr 2024 19:07:18 +0200 Subject: [PATCH] Sort imports (#46) Command: * isort --profile=black . Note: * this also addresses a couple of pylint issues Additionally: * add isort configuration section to the pyproject.toml file --- anycast_healthchecker/healthchecker.py | 32 +++++++++-------- anycast_healthchecker/main.py | 23 ++++++++---- anycast_healthchecker/servicecheck.py | 15 ++++---- anycast_healthchecker/utils.py | 36 ++++++++++--------- contrib/nagios/check_anycast_healthchecker.py | 5 +-- pyproject.toml | 4 +++ 6 files changed, 68 insertions(+), 47 deletions(-) diff --git a/anycast_healthchecker/healthchecker.py b/anycast_healthchecker/healthchecker.py index 43a1f99..11ffcd6 100644 --- a/anycast_healthchecker/healthchecker.py +++ b/anycast_healthchecker/healthchecker.py @@ -1,26 +1,28 @@ # pylint: disable=too-few-public-methods """A library which provides the HealthChecker class.""" -from configparser import NoOptionError +import logging import os import sys -import logging -from queue import Queue import threading +from configparser import NoOptionError +from queue import Queue + +from prometheus_client import CollectorRegistry, Counter, Gauge -from anycast_healthchecker import PROGRAM_NAME, METRIC_PREFIX +from anycast_healthchecker import METRIC_PREFIX, PROGRAM_NAME from anycast_healthchecker.servicecheck import ServiceCheck -from anycast_healthchecker.utils import (SERVICE_OPTIONS_TYPE, - get_ip_prefixes_from_bird, - get_ip_prefixes_from_config, - reconfigure_bird, - write_temp_bird_conf, - archive_bird_conf, - ServiceCheckDiedError, - run_custom_bird_reconfigure, - MainExporter) - -from prometheus_client import Gauge, CollectorRegistry, Counter +from anycast_healthchecker.utils import ( + SERVICE_OPTIONS_TYPE, + MainExporter, + ServiceCheckDiedError, + archive_bird_conf, + get_ip_prefixes_from_bird, + get_ip_prefixes_from_config, + reconfigure_bird, + run_custom_bird_reconfigure, + write_temp_bird_conf, +) class HealthChecker: diff --git a/anycast_healthchecker/main.py b/anycast_healthchecker/main.py index c19f402..8ba0046 100644 --- a/anycast_healthchecker/main.py +++ b/anycast_healthchecker/main.py @@ -22,17 +22,26 @@ -v, --version show version -h, --help show this screen """ -from functools import partial -import socket import signal +import socket import sys +from functools import partial + from docopt import docopt -from anycast_healthchecker import (DEFAULT_OPTIONS, PROGRAM_NAME, __version__, - healthchecker) -from anycast_healthchecker.utils import (load_configuration, shutdown, - ip_prefixes_sanity_check, - update_pidfile, setup_logger) +from anycast_healthchecker import ( + DEFAULT_OPTIONS, + PROGRAM_NAME, + __version__, + healthchecker, +) +from anycast_healthchecker.utils import ( + ip_prefixes_sanity_check, + load_configuration, + setup_logger, + shutdown, + update_pidfile, +) def main(): diff --git a/anycast_healthchecker/servicecheck.py b/anycast_healthchecker/servicecheck.py index e43e061..1e59735 100644 --- a/anycast_healthchecker/servicecheck.py +++ b/anycast_healthchecker/servicecheck.py @@ -6,18 +6,21 @@ """A library which provides the ServiceCheck class.""" +import ipaddress +import logging +import random +import shlex import subprocess import time -import logging import traceback from threading import Thread -import ipaddress -import random -import shlex from anycast_healthchecker import PROGRAM_NAME -from anycast_healthchecker.utils import (AddOperation, DeleteOperation, - ServiceCheckDiedError) +from anycast_healthchecker.utils import ( + AddOperation, + DeleteOperation, + ServiceCheckDiedError, +) class ServiceCheck(Thread): diff --git a/anycast_healthchecker/utils.py b/anycast_healthchecker/utils.py index bcada62..aa98ff7 100644 --- a/anycast_healthchecker/utils.py +++ b/anycast_healthchecker/utils.py @@ -6,30 +6,32 @@ # pylint: disable=too-few-public-methods # pylint: disable=too-many-lines """Provide functions and classes that are used within anycast_healthchecker.""" -from collections import Counter -import re -import os -import signal -import sys -import subprocess -import logging -import logging.handlers -from threading import Thread -import time -import datetime import configparser +import datetime import glob +import ipaddress +import logging +import logging.handlers +import os +import re import shlex import shutil -import ipaddress +import signal +import subprocess +import sys +import time +from collections import Counter +from threading import Thread +from prometheus_client import CollectorRegistry, Gauge, Info, write_to_textfile from pythonjsonlogger import jsonlogger -from anycast_healthchecker import DEFAULT_OPTIONS, PROGRAM_NAME, __version__, METRIC_PREFIX - -from prometheus_client import Gauge, CollectorRegistry, write_to_textfile, Info - - +from anycast_healthchecker import ( + DEFAULT_OPTIONS, + METRIC_PREFIX, + PROGRAM_NAME, + __version__, +) SERVICE_OPTIONS_TYPE = { 'check_cmd': 'get', diff --git a/contrib/nagios/check_anycast_healthchecker.py b/contrib/nagios/check_anycast_healthchecker.py index 01ec8ec..8e35b27 100755 --- a/contrib/nagios/check_anycast_healthchecker.py +++ b/contrib/nagios/check_anycast_healthchecker.py @@ -11,11 +11,12 @@ Options: -v report what it does """ -import os -import sys import configparser import glob +import os import subprocess +import sys + from docopt import docopt diff --git a/pyproject.toml b/pyproject.toml index a69da83..b8f37fd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,3 +39,7 @@ readme = {file = ["README.rst"]} [build-system] requires = ["setuptools>=61", "wheel"] build-backend = "setuptools.build_meta" + +[tool.isort] +# https://pycqa.github.io/isort/docs/configuration/profiles.html +profile = "black"