From eac0b4750388cf9445a0ea1639389f419dd84965 Mon Sep 17 00:00:00 2001 From: Garrett Heel Date: Wed, 21 Dec 2016 00:23:30 +1000 Subject: [PATCH] Fix imports --- graphite_beacon/alerts.py | 17 ++++++----------- graphite_beacon/app.py | 1 - graphite_beacon/core.py | 13 ++++++------- graphite_beacon/handlers/cli.py | 2 +- graphite_beacon/handlers/hipchat.py | 5 +++-- graphite_beacon/handlers/http.py | 5 +++-- graphite_beacon/handlers/log.py | 2 +- graphite_beacon/handlers/pagerduty.py | 5 +++-- graphite_beacon/handlers/slack.py | 5 +++-- graphite_beacon/handlers/smtp.py | 4 ++-- graphite_beacon/handlers/telegram.py | 4 +++- graphite_beacon/handlers/victorops.py | 10 ++++++---- graphite_beacon/template.py | 1 - graphite_beacon/units.py | 1 - graphite_beacon/utils.py | 7 +++---- tests/integration/graphite_test.py | 13 ++++--------- tests/unit/alerts_test.py | 3 +-- tests/unit/handlers/smtp_test.py | 2 +- tests/unit/units_test.py | 13 +++---------- tests/unit/utils_test.py | 10 +++------- 20 files changed, 52 insertions(+), 71 deletions(-) diff --git a/graphite_beacon/alerts.py b/graphite_beacon/alerts.py index 82c810d..b55dd73 100644 --- a/graphite_beacon/alerts.py +++ b/graphite_beacon/alerts.py @@ -1,22 +1,17 @@ """Implement alerts.""" import math - -from collections import deque, defaultdict +from collections import defaultdict, deque from itertools import islice -from tornado import ioloop, httpclient as hc, gen, log, escape +from tornado import httpclient as hc +from tornado import escape, gen, ioloop, log -from . import _compat as _, units +from . import _compat as _ +from . import units from .graphite import GraphiteRecord from .units import MILLISECOND, TimeUnit -from .utils import ( - HISTORICAL, - LOGICAL_OPERATORS, - convert_to_format, - parse_rule, -) - +from .utils import HISTORICAL, LOGICAL_OPERATORS, convert_to_format, parse_rule LOGGER = log.gen_log METHODS = "average", "last_value", "sum", "minimum", "maximum" diff --git a/graphite_beacon/app.py b/graphite_beacon/app.py index f4b081a..28afa24 100644 --- a/graphite_beacon/app.py +++ b/graphite_beacon/app.py @@ -7,7 +7,6 @@ from .core import Reactor - LOGGER = log.gen_log DEFAULT_CONFIG_PATH = 'config.json' diff --git a/graphite_beacon/core.py b/graphite_beacon/core.py index d9263e5..d3c5b85 100644 --- a/graphite_beacon/core.py +++ b/graphite_beacon/core.py @@ -1,17 +1,16 @@ -import sys -import os -from re import compile as re, M - import json import logging +import os +import sys +from re import compile as re +from re import M -from tornado import ioloop, log import yaml +from tornado import ioloop, log from .alerts import BaseAlert -from .units import MILLISECOND, TimeUnit from .handlers import registry - +from .units import MILLISECOND, TimeUnit LOGGER = log.gen_log diff --git a/graphite_beacon/handlers/cli.py b/graphite_beacon/handlers/cli.py index bd16d45..c92a504 100644 --- a/graphite_beacon/handlers/cli.py +++ b/graphite_beacon/handlers/cli.py @@ -1,6 +1,6 @@ import subprocess -from graphite_beacon.handlers import AbstractHandler, LOGGER +from graphite_beacon.handlers import LOGGER, AbstractHandler class CliHandler(AbstractHandler): diff --git a/graphite_beacon/handlers/hipchat.py b/graphite_beacon/handlers/hipchat.py index e47f012..9a5802a 100644 --- a/graphite_beacon/handlers/hipchat.py +++ b/graphite_beacon/handlers/hipchat.py @@ -1,8 +1,9 @@ import json -from tornado import gen, httpclient as hc +from tornado import httpclient as hc +from tornado import gen -from graphite_beacon.handlers import AbstractHandler, LOGGER +from graphite_beacon.handlers import LOGGER, AbstractHandler class HipChatHandler(AbstractHandler): diff --git a/graphite_beacon/handlers/http.py b/graphite_beacon/handlers/http.py index 97a8577..32339a9 100644 --- a/graphite_beacon/handlers/http.py +++ b/graphite_beacon/handlers/http.py @@ -1,8 +1,9 @@ import urllib -from tornado import gen, httpclient as hc +from tornado import httpclient as hc +from tornado import gen -from graphite_beacon.handlers import AbstractHandler, LOGGER +from graphite_beacon.handlers import LOGGER, AbstractHandler class HttpHandler(AbstractHandler): diff --git a/graphite_beacon/handlers/log.py b/graphite_beacon/handlers/log.py index cb350b0..df2d8eb 100644 --- a/graphite_beacon/handlers/log.py +++ b/graphite_beacon/handlers/log.py @@ -1,4 +1,4 @@ -from graphite_beacon.handlers import AbstractHandler, LOGGER +from graphite_beacon.handlers import LOGGER, AbstractHandler class LogHandler(AbstractHandler): diff --git a/graphite_beacon/handlers/pagerduty.py b/graphite_beacon/handlers/pagerduty.py index 7a52827..8f0a730 100644 --- a/graphite_beacon/handlers/pagerduty.py +++ b/graphite_beacon/handlers/pagerduty.py @@ -1,8 +1,9 @@ import json -from tornado import gen, httpclient as hc +from tornado import httpclient as hc +from tornado import gen -from graphite_beacon.handlers import AbstractHandler, LOGGER +from graphite_beacon.handlers import LOGGER, AbstractHandler class PagerdutyHandler(AbstractHandler): diff --git a/graphite_beacon/handlers/slack.py b/graphite_beacon/handlers/slack.py index 8f5de2f..c5dd2c8 100644 --- a/graphite_beacon/handlers/slack.py +++ b/graphite_beacon/handlers/slack.py @@ -1,8 +1,9 @@ import json -from tornado import gen, httpclient as hc +from tornado import httpclient as hc +from tornado import gen -from graphite_beacon.handlers import AbstractHandler, LOGGER +from graphite_beacon.handlers import LOGGER, AbstractHandler from graphite_beacon.template import TEMPLATES diff --git a/graphite_beacon/handlers/smtp.py b/graphite_beacon/handlers/smtp.py index 91b1f30..d85ad9f 100644 --- a/graphite_beacon/handlers/smtp.py +++ b/graphite_beacon/handlers/smtp.py @@ -3,9 +3,9 @@ from email.mime.text import MIMEText from smtplib import SMTP -from tornado import gen, concurrent +from tornado import concurrent, gen -from graphite_beacon.handlers import AbstractHandler, TEMPLATES, LOGGER +from graphite_beacon.handlers import LOGGER, TEMPLATES, AbstractHandler class SMTPHandler(AbstractHandler): diff --git a/graphite_beacon/handlers/telegram.py b/graphite_beacon/handlers/telegram.py index ed9f890..7ca4ff2 100644 --- a/graphite_beacon/handlers/telegram.py +++ b/graphite_beacon/handlers/telegram.py @@ -2,11 +2,13 @@ import json from os.path import exists + from tornado import gen, httpclient -from graphite_beacon.handlers import AbstractHandler, LOGGER +from graphite_beacon.handlers import LOGGER, AbstractHandler from graphite_beacon.template import TEMPLATES + HELP_MESSAGE = """Telegram handler for graphite-beacon *usage* /command [parameters] *examples* diff --git a/graphite_beacon/handlers/victorops.py b/graphite_beacon/handlers/victorops.py index 35cb409..623082d 100644 --- a/graphite_beacon/handlers/victorops.py +++ b/graphite_beacon/handlers/victorops.py @@ -1,13 +1,15 @@ import json + +from tornado import httpclient as hc +from tornado import gen + +from graphite_beacon.handlers import LOGGER, AbstractHandler + try: from urlparse import urljoin except ImportError: from urllib.parse import urljoin -from tornado import gen, httpclient as hc - -from graphite_beacon.handlers import AbstractHandler, LOGGER - class VictorOpsHandler(AbstractHandler): diff --git a/graphite_beacon/template.py b/graphite_beacon/template.py index a3e952c..88600d9 100644 --- a/graphite_beacon/template.py +++ b/graphite_beacon/template.py @@ -2,7 +2,6 @@ from tornado import template - LOADER = template.Loader(op.join(op.dirname(op.abspath(__file__)), 'templates'), autoescape=None) TEMPLATES = { 'graphite': { diff --git a/graphite_beacon/units.py b/graphite_beacon/units.py index 3d9d3bb..943c652 100644 --- a/graphite_beacon/units.py +++ b/graphite_beacon/units.py @@ -2,7 +2,6 @@ import re - NUMBER_RE = re.compile(r'(?P\-?\d*\.?\d*)(?P\w+)') # Time units diff --git a/graphite_beacon/utils.py b/graphite_beacon/utils.py index 52adf6d..369f883 100644 --- a/graphite_beacon/utils.py +++ b/graphite_beacon/utils.py @@ -1,9 +1,8 @@ -from re import compile as re import operator as op +from re import compile as re -from funcparserlib.lexer import make_tokenizer, Token -from funcparserlib.parser import (some, a, maybe, finished, skip, many) - +from funcparserlib.lexer import Token, make_tokenizer +from funcparserlib.parser import a, finished, many, maybe, skip, some # NOTE: the unit conversions below should be considered deprecated and migrated # over to `unit.py` instead. diff --git a/tests/integration/graphite_test.py b/tests/integration/graphite_test.py index 6bbd26d..f4a9bbc 100644 --- a/tests/integration/graphite_test.py +++ b/tests/integration/graphite_test.py @@ -1,21 +1,16 @@ import mock - -from mock import ANY - -from itertools import cycle, imap - import tornado.gen - +from mock import ANY from tornado import ioloop -from tornado.httpclient import HTTPResponse, HTTPRequest +from tornado.httpclient import HTTPRequest, HTTPResponse from tornado.testing import AsyncTestCase, gen_test from graphite_beacon.alerts import GraphiteAlert from graphite_beacon.core import Reactor +from graphite_beacon._compat import range from ..util import build_graphite_response - fetch_mock_url = lambda m: m.call_args_list[0][0][0] @@ -56,7 +51,7 @@ def test_graphite(self, mock_smpt_notify, mock_fetch): buffer=build_graphite_response(data=metric_data)) mock_fetch.side_effect = iter(tornado.gen.maybe_future(build_resp()) - for _ in xrange(100)) + for _ in range(100)) rr.start(start_loop=False) yield tornado.gen.sleep(0.5) diff --git a/tests/unit/alerts_test.py b/tests/unit/alerts_test.py index 602a610..65272a2 100644 --- a/tests/unit/alerts_test.py +++ b/tests/unit/alerts_test.py @@ -1,11 +1,10 @@ import mock from graphite_beacon import units +from graphite_beacon._compat import urlparse from graphite_beacon.alerts import BaseAlert, GraphiteAlert, URLAlert from graphite_beacon.core import Reactor from graphite_beacon.units import SECOND -from graphite_beacon._compat import urlparse - BASIC_ALERT_OPTS = { 'name': 'GraphiteTest', diff --git a/tests/unit/handlers/smtp_test.py b/tests/unit/handlers/smtp_test.py index 257f4ab..453a517 100644 --- a/tests/unit/handlers/smtp_test.py +++ b/tests/unit/handlers/smtp_test.py @@ -1,5 +1,5 @@ -from graphite_beacon.handlers.smtp import SMTPHandler from graphite_beacon.alerts import BaseAlert +from graphite_beacon.handlers.smtp import SMTPHandler def test_html_template(reactor): diff --git a/tests/unit/units_test.py b/tests/unit/units_test.py index ea2cea4..879732d 100644 --- a/tests/unit/units_test.py +++ b/tests/unit/units_test.py @@ -1,15 +1,8 @@ import pytest -from graphite_beacon.units import ( - DAY, - HOUR, - MILLISECOND, - MINUTE, - MONTH, - SECOND, - TimeUnit, - YEAR, -) +from graphite_beacon.units import (DAY, HOUR, MILLISECOND, MINUTE, MONTH, + SECOND, YEAR, TimeUnit) + class TestTimeUnit(object): def test_from_interval(self): diff --git a/tests/unit/utils_test.py b/tests/unit/utils_test.py index a4b539a..648c2c7 100644 --- a/tests/unit/utils_test.py +++ b/tests/unit/utils_test.py @@ -1,15 +1,11 @@ import operator as op import pytest - from funcparserlib.lexer import LexerError -from graphite_beacon.utils import ( - convert_to_format, - convert_from_format, - parse_rule as parse_rule, - IDENTITY -) +from graphite_beacon.utils import parse_rule as parse_rule +from graphite_beacon.utils import (IDENTITY, convert_from_format, + convert_to_format) def test_convert():