Skip to content

Commit

Permalink
Sort module imports using Ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
pgiraud committed Aug 13, 2024
1 parent 6e1fea2 commit bbd88d5
Show file tree
Hide file tree
Showing 23 changed files with 276 additions and 167 deletions.
2 changes: 1 addition & 1 deletion .ruff.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[lint]
# Add "Q" to the list of enabled codes.
extend-select = ["E4", "E7", "E9", "F", "Q"]
extend-select = ["E4", "E7", "E9", "F", "Q", "I"]
110 changes: 70 additions & 40 deletions powa/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import print_function

"""
Powa main application.
"""
Expand All @@ -12,26 +13,33 @@

POWA_ROOT = os.path.dirname(__file__)

from tornado.web import Application, URLSpec as U # noqa: E402
from powa.options import parse_options # noqa: E402
from tornado.options import options # noqa: E402
from powa import ui_modules, ui_methods # noqa: E402
from tornado.web import Application # noqa: E402
from tornado.web import URLSpec as U # noqa: E402

from powa import ui_methods, ui_modules # noqa: E402
from powa.collector import ( # noqa: E402
CollectorDbCatRefreshHandler,
CollectorForceSnapshotHandler,
CollectorReloadHandler,
)
from powa.config import RemoteConfigOverview, RepositoryConfigOverview # noqa: E402
from powa.database import DatabaseOverview, DatabaseSelector # noqa: E402
from powa.framework import AuthHandler # noqa: E402
from powa.user import LoginHandler, LogoutHandler # noqa: E402
from powa.function import FunctionOverview # noqa: E402
from powa.io import ( # noqa: E402
ByBackendTypeIoOverview,
ByContextIoOverview,
ByObjIoOverview,
)
from powa.options import parse_options # noqa: E402
from powa.overview import Overview # noqa: E402
from powa.server import ServerSelector, ServerOverview # noqa: E402
from powa.database import DatabaseSelector, DatabaseOverview # noqa: E402
from powa.query import QueryOverview # noqa: E402
from powa.qual import QualOverview # noqa: E402
from powa.function import FunctionOverview # noqa: E402
from powa.config import RepositoryConfigOverview, RemoteConfigOverview # noqa: E402
from powa.collector import (CollectorReloadHandler, # noqa: E402
CollectorForceSnapshotHandler, # noqa: E402
CollectorDbCatRefreshHandler) # noqa: E402
from powa.wizard import IndexSuggestionHandler # noqa: E402
from powa.io import (ByBackendTypeIoOverview, ByObjIoOverview, # noqa: E402
ByContextIoOverview) # noqa: E402
from powa.query import QueryOverview # noqa: E402
from powa.server import ServerOverview, ServerSelector # noqa: E402
from powa.slru import ByNameSlruOverview # noqa: E402
from powa.user import LoginHandler, LogoutHandler # noqa: E402
from powa.wizard import IndexSuggestionHandler # noqa: E402


class IndexHandler(AuthHandler):
Expand All @@ -52,38 +60,59 @@ def make_app(**kwargs):
URLS = [
U(r"%slogin/" % options.url_prefix, LoginHandler, name="login"),
U(r"%slogout/" % options.url_prefix, LogoutHandler, name="logout"),
U(r"%sreload_collector/" % options.url_prefix, CollectorReloadHandler,
name="reload_collector"),
U(r"%sforce_snapshot/(\d+)" % options.url_prefix,
CollectorForceSnapshotHandler, name="force_snapshot"),
U(r"%srefresh_db_cat/" % options.url_prefix,
CollectorDbCatRefreshHandler, name="refresh_db_cat"),
U(r"%sserver/select" % options.url_prefix, ServerSelector,
name="server_selector"),
U(r"%sdatabase/select" % options.url_prefix, DatabaseSelector,
name="database_selector"),
U(
r"%sreload_collector/" % options.url_prefix,
CollectorReloadHandler,
name="reload_collector",
),
U(
r"%sforce_snapshot/(\d+)" % options.url_prefix,
CollectorForceSnapshotHandler,
name="force_snapshot",
),
U(
r"%srefresh_db_cat/" % options.url_prefix,
CollectorDbCatRefreshHandler,
name="refresh_db_cat",
),
U(
r"%sserver/select" % options.url_prefix,
ServerSelector,
name="server_selector",
),
U(
r"%sdatabase/select" % options.url_prefix,
DatabaseSelector,
name="database_selector",
),
U(r"%s" % options.url_prefix, IndexHandler, name="index"),
U(r"%sserver/(\d+)/database/([^\/]+)/suggest/" % options.url_prefix,
IndexSuggestionHandler, name="index_suggestion")
U(
r"%sserver/(\d+)/database/([^\/]+)/suggest/" % options.url_prefix,
IndexSuggestionHandler,
name="index_suggestion",
),
]

for dashboard in (Overview,
ServerOverview,
DatabaseOverview,
QueryOverview,
QualOverview,
FunctionOverview,
RepositoryConfigOverview,
RemoteConfigOverview,
ByBackendTypeIoOverview,
ByObjIoOverview,
ByContextIoOverview,
ByNameSlruOverview):
for dashboard in (
Overview,
ServerOverview,
DatabaseOverview,
QueryOverview,
QualOverview,
FunctionOverview,
RepositoryConfigOverview,
RemoteConfigOverview,
ByBackendTypeIoOverview,
ByObjIoOverview,
ByContextIoOverview,
ByNameSlruOverview,
):
URLS.extend(dashboard.url_specs(options.url_prefix))

_cls = Application
if "legacy_wsgi" in kwargs:
from tornado.wsgi import WSGIApplication

_cls = WSGIApplication

return _cls(
Expand All @@ -95,4 +124,5 @@ def make_app(**kwargs):
static_url_prefix=("%sstatic/" % options.url_prefix),
cookie_secret=options.cookie_secret,
template_path=os.path.join(POWA_ROOT, "templates"),
**kwargs)
**kwargs,
)
2 changes: 2 additions & 0 deletions powa/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
collector handling.
"""
from __future__ import absolute_import

import json

from powa.dashboards import MetricGroupDef
from powa.framework import AuthHandler

Expand Down
4 changes: 3 additions & 1 deletion powa/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
"""
from __future__ import absolute_import

import json

import psycopg2
from psycopg2 import extensions
import json

# If psycopg2 < 2.5, register json type
psycopg2_version = tuple(psycopg2.__version__.split(" ")[0].split("."))
Expand Down
16 changes: 11 additions & 5 deletions powa/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@
Dashboard for the configuration summary page.
"""
from __future__ import absolute_import

import json

from powa.collector import CollectorServerDetail
from powa.dashboards import (
Dashboard, Grid,
MetricGroupDef, MetricDef,
DashboardPage, ContentWidget)
ContentWidget,
Dashboard,
DashboardPage,
Grid,
MetricDef,
MetricGroupDef,
)
from powa.sql.views import get_config_changes
from powa.collector import CollectorServerDetail
import json


def get_pgts_query(handler, restrict_database=False):
Expand Down
14 changes: 8 additions & 6 deletions powa/dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@
This module provides several classes to define a Dashboard.
"""

from powa.json import JSONizable
from powa.framework import AuthHandler
from powa.compat import with_metaclass, classproperty
from powa.ui_modules import MenuEntry
from tornado.web import URLSpec
from operator import attrgetter
from collections import OrderedDict
from inspect import isfunction
from operator import attrgetter

import psycopg2
from tornado.web import URLSpec

from powa.compat import classproperty, with_metaclass
from powa.framework import AuthHandler
from powa.json import JSONizable
from powa.ui_modules import MenuEntry

GLOBAL_COUNTER = 0

Expand Down
57 changes: 37 additions & 20 deletions powa/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,45 @@
Module containing the by-database dashboard.
"""
from tornado.web import HTTPError
from powa.framework import AuthHandler

from powa.config import ConfigChangesDatabase
from powa.dashboards import (
Dashboard, Graph, Grid, ContentWidget,
MetricGroupDef, MetricDef,
DashboardPage, TabContainer)

from powa.sql.views_graph import (powa_getstatdata_sample,
kcache_getstatdata_sample,
powa_getwaitdata_sample,
powa_get_pgsa_sample,
powa_get_all_idx_sample,
powa_get_all_tbl_sample,
powa_get_user_fct_sample,
powa_get_database_sample)
from powa.sql.views_grid import (powa_getstatdata_detailed_db,
powa_getwaitdata_detailed_db,
powa_getuserfuncdata_detailed_db)
from powa.wizard import WizardMetricGroup, Wizard
ContentWidget,
Dashboard,
DashboardPage,
Graph,
Grid,
MetricDef,
MetricGroupDef,
TabContainer,
)
from powa.framework import AuthHandler
from powa.server import ServerOverview
from powa.sql.utils import (block_size, sum_per_sec, wps,
mulblock, total_read, total_hit, to_epoch)
from powa.config import ConfigChangesDatabase
from powa.sql.utils import (
block_size,
mulblock,
sum_per_sec,
to_epoch,
total_hit,
total_read,
wps,
)
from powa.sql.views_graph import (
kcache_getstatdata_sample,
powa_get_all_idx_sample,
powa_get_all_tbl_sample,
powa_get_database_sample,
powa_get_pgsa_sample,
powa_get_user_fct_sample,
powa_getstatdata_sample,
powa_getwaitdata_sample,
)
from powa.sql.views_grid import (
powa_getstatdata_detailed_db,
powa_getuserfuncdata_detailed_db,
powa_getwaitdata_detailed_db,
)
from powa.wizard import Wizard, WizardMetricGroup


class DatabaseSelector(AuthHandler):
Expand Down
22 changes: 12 additions & 10 deletions powa/framework.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
"""
Utilities for the basis of Powa
"""
from collections import defaultdict
from tornado.web import RequestHandler, authenticated, HTTPError
from powa.json import JSONizable
from powa import ui_methods
from powa.json import to_json
import psycopg2
from psycopg2.extensions import connection as _connection, cursor as _cursor
from psycopg2.extras import RealDictCursor
from tornado.options import options
import pickle
import logging
import pickle
import random
import re
import select
import time
from collections import defaultdict

import psycopg2
from psycopg2.extensions import connection as _connection
from psycopg2.extensions import cursor as _cursor
from psycopg2.extras import RealDictCursor
from tornado.options import options
from tornado.web import HTTPError, RequestHandler, authenticated

from powa import ui_methods
from powa.json import JSONizable, to_json


class CustomConnection(_connection):
Expand Down
2 changes: 1 addition & 1 deletion powa/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Dashboard for the by-function page.
"""

from powa.dashboards import (Dashboard, DashboardPage, ContentWidget)
from powa.dashboards import ContentWidget, Dashboard, DashboardPage
from powa.database import DatabaseOverview
from powa.sql.views_grid import powa_getuserfuncdata_detailed_db

Expand Down
5 changes: 2 additions & 3 deletions powa/io.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
"""
Dashboards for the various IO pages.
"""
from powa.dashboards import Dashboard, Graph, Grid, DashboardPage
from powa.config import ConfigChangesGlobal
from powa.server import ServerOverview

from powa.dashboards import Dashboard, DashboardPage, Graph, Grid
from powa.io_template import TemplateIoGraph, TemplateIoGrid
from powa.server import ServerOverview


class TemplateIoOverview(DashboardPage):
Expand Down
1 change: 0 additions & 1 deletion powa/io_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Datasource template used for the various IO pages.
"""
from powa.dashboards import MetricDef, MetricGroupDef

from powa.sql.utils import sum_per_sec
from powa.sql.views_graph import powa_get_io_sample
from powa.sql.views_grid import powa_getiodata
Expand Down
4 changes: 3 additions & 1 deletion powa/json.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from __future__ import absolute_import
from json import JSONEncoder as BaseJSONEncoder

from datetime import datetime
from decimal import Decimal
from json import JSONEncoder as BaseJSONEncoder


class JSONEncoder(BaseJSONEncoder):
"""
Expand Down
9 changes: 7 additions & 2 deletions powa/options.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
from tornado.options import (define, parse_config_file, options,
Error, parse_command_line)
import os
import sys

from tornado.options import (
Error,
define,
options,
parse_command_line,
parse_config_file,
)

SAMPLE_CONFIG_FILE = """
servers={
Expand Down
6 changes: 1 addition & 5 deletions powa/overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
Index page presenting the list of available servers.
"""

from powa.dashboards import (
Dashboard, Grid,
MetricGroupDef, MetricDef,
DashboardPage)

from powa.dashboards import Dashboard, DashboardPage, Grid, MetricDef, MetricGroupDef


class OverviewMetricGroup(MetricGroupDef):
Expand Down
Loading

0 comments on commit bbd88d5

Please sign in to comment.