Skip to content

Commit

Permalink
Drop support for Python < 3.6
Browse files Browse the repository at this point in the history
The Python syntax is upgrade accordingly by enabling
pyupgrade in Ruff configuration.

The following commands were executed:
 - `ruff check --fix`
 - `ruff check --fix --unsafe-fixes`
 - `ruff format`

We added python 3.7 in the lint tests job in CI. And we also check for
obvious syntax errors on Python3.6.
  • Loading branch information
pgiraud committed Nov 20, 2024
1 parent 121b76d commit eae8dc9
Show file tree
Hide file tree
Showing 24 changed files with 203 additions and 246 deletions.
28 changes: 27 additions & 1 deletion .github/workflows/python_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.12"]
python-version: ["3.7", "3.12"]
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -27,3 +27,29 @@ jobs:
run: |
ruff check --output-format=github .
ruff format --check
python36:
# This job will detect InvalidSyntax error on Python 3.6.
# A success doesn't necessarily mean that PoWA works.
runs-on: ubuntu-20.04
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set Python Version
uses: actions/setup-python@v5
with:
python-version: 3.6

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Configure PoWA
run: |
cp powa-web.conf-dist powa-web.conf
- name: Check for syntax errors
run: |
timeout 1 python run_powa.py || code=$?; if [[ $code -ne 124 && $code -ne 0 ]]; then exit $code; fi
3 changes: 2 additions & 1 deletion .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ line-length = 79
# In addition, we also enable:
# `Q` for "flake8-quotes"
# `I` for "isort"
extend-select = ["Q", "I"]
# `UP` for "pyupgrade"
extend-select = ["Q", "I", "UP"]

[lint.per-file-ignores]
"powa/__init__.py" = ["E402"]
Expand Down
24 changes: 11 additions & 13 deletions powa/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import print_function

"""
Powa main application.
"""
Expand Down Expand Up @@ -63,36 +61,36 @@ def make_app(**kwargs):
parse_options()

URLS = [
U(r"%slogin/" % options.url_prefix, LoginHandler, name="login"),
U(r"%slogout/" % options.url_prefix, LogoutHandler, name="logout"),
U(rf"{options.url_prefix}login/", LoginHandler, name="login"),
U(rf"{options.url_prefix}logout/", LogoutHandler, name="logout"),
U(
r"%sreload_collector/" % options.url_prefix,
rf"{options.url_prefix}reload_collector/",
CollectorReloadHandler,
name="reload_collector",
),
U(
r"%sforce_snapshot/(\d+)" % options.url_prefix,
rf"{options.url_prefix}force_snapshot/(\d+)",
CollectorForceSnapshotHandler,
name="force_snapshot",
),
U(
r"%srefresh_db_cat/" % options.url_prefix,
rf"{options.url_prefix}refresh_db_cat/",
CollectorDbCatRefreshHandler,
name="refresh_db_cat",
),
U(
r"%sserver/select" % options.url_prefix,
rf"{options.url_prefix}server/select",
ServerSelector,
name="server_selector",
),
U(
r"%sdatabase/select" % options.url_prefix,
rf"{options.url_prefix}database/select",
DatabaseSelector,
name="database_selector",
),
U(r"%s" % options.url_prefix, IndexHandler, name="index"),
U(rf"{options.url_prefix}", IndexHandler, name="index"),
U(
r"%sserver/(\d+)/database/([^\/]+)/suggest/" % options.url_prefix,
rf"{options.url_prefix}server/(\d+)/database/([^\/]+)/suggest/",
IndexSuggestionHandler,
name="index_suggestion",
),
Expand Down Expand Up @@ -124,9 +122,9 @@ def make_app(**kwargs):
URLS,
ui_modules=ui_modules,
ui_methods=ui_methods,
login_url=("%slogin/" % options.url_prefix),
login_url=(f"{options.url_prefix}login/"),
static_path=os.path.join(POWA_ROOT, "static"),
static_url_prefix=("%sstatic/" % options.url_prefix),
static_url_prefix=(f"{options.url_prefix}static/"),
cookie_secret=options.cookie_secret,
template_path=os.path.join(POWA_ROOT, "templates"),
**kwargs,
Expand Down
2 changes: 0 additions & 2 deletions powa/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
collector handling.
"""

from __future__ import absolute_import

import json
from powa.dashboards import MetricGroupDef
from powa.framework import AuthHandler
Expand Down
4 changes: 1 addition & 3 deletions powa/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
"""

from __future__ import absolute_import

import json
import psycopg2
from psycopg2 import extensions
Expand Down Expand Up @@ -37,7 +35,7 @@ def __new__(cls, name, _, d):
return type.__new__(metaclass, "temporary_class", (), {})


class classproperty(object):
class classproperty:
"""
A descriptor similar to property, but using the class.
"""
Expand Down
6 changes: 2 additions & 4 deletions powa/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
Dashboard for the configuration summary page.
"""

from __future__ import absolute_import

import json
from powa.collector import CollectorServerDetail
from powa.dashboards import (
Expand Down Expand Up @@ -418,7 +416,7 @@ def post_process(self, data, server, **kwargs):
data["messages"] = {
"alert": [
"Could not retrieve extensions"
+ " on remote server: %s" % errmsg
+ f" on remote server: {errmsg}"
]
}
return data
Expand Down Expand Up @@ -528,7 +526,7 @@ def post_process(self, data, server, **kwargs):
data["messages"] = {
"alert": [
"Could not retrieve extensions"
+ " on remote server: %s" % errmsg
+ f" on remote server: {errmsg}"
]
}
return data
Expand Down
25 changes: 13 additions & 12 deletions powa/dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def url_name(cls):
"""
Returns the default url_name for this data source.
"""
return "datasource_%s" % cls.__name__
return f"datasource_{cls.__name__}"

@classproperty
def parameterized_json(cls, handler, **parms):
Expand Down Expand Up @@ -310,14 +310,14 @@ def bind(self, group):
"""

if self._group is not None:
raise ValueError("Already bound to %s" % self._group)
raise ValueError(f"Already bound to {self._group}")
self._group = group

def _fqn(self):
"""
Return the fully qualified name of this metric.
"""
return "%s.%s" % (self._group.name, self.name)
return f"{self._group.name}.{self.name}"


class Dashboard(JSONizable):
Expand Down Expand Up @@ -502,7 +502,7 @@ def _validate(self):
if any(m._group != mg1 for m in self.metrics):
raise ValueError(
"A grid is not allowed to have metrics from different "
"groups. (title: %s)" % self.title
f"groups. (title: {self.title})"
)

def to_json(self):
Expand Down Expand Up @@ -559,7 +559,7 @@ def to_json(self):
return values


class Declarative(object):
class Declarative:
"""
Base class for declarative classes.
"""
Expand Down Expand Up @@ -606,12 +606,12 @@ def __new__(meta, name, bases, dct):
if isinstance(val, Metric):
dct.pop(key)
dct["metrics"][key] = val
return super(MetaMetricGroup, meta).__new__(meta, name, bases, dct)
return super().__new__(meta, name, bases, dct)

def __init__(cls, name, bases, dct):
for metric in dct.get("metrics").values():
metric.bind(cls)
super(MetaMetricGroup, cls).__init__(name, bases, dct)
super().__init__(name, bases, dct)

def __getattr__(cls, key):
if key not in cls.metrics:
Expand Down Expand Up @@ -705,7 +705,7 @@ def metrics(self):
return self._metrics


class DashboardPage(object):
class DashboardPage:
"""
A Dashboard page ties together a set of datasources, and a dashboard.
Expand Down Expand Up @@ -745,7 +745,7 @@ def url_specs(cls, url_prefix):
url_specs = []
url_specs.append(
URLSpec(
r"%s%s/" % (url_prefix, cls.base_url.strip("/")),
r"{}{}/".format(url_prefix, cls.base_url.strip("/")),
type(cls.__name__, (cls.dashboard_handler_cls, cls), {}),
{"template": cls.template, "params": cls.params},
name=cls.__name__,
Expand All @@ -754,12 +754,13 @@ def url_specs(cls, url_prefix):
for datasource in cls.datasources:
if datasource.data_url is None:
raise KeyError(
"A Datasource must have a data_url: %s"
% datasource.__name__
f"A Datasource must have a data_url: {datasource.__name__}"
)
url_specs.append(
URLSpec(
r"%s%s/" % (url_prefix, datasource.data_url.strip("/")),
r"{}{}/".format(
url_prefix, datasource.data_url.strip("/")
),
type(
datasource.__name__,
(datasource, datasource.datasource_handler_cls),
Expand Down
18 changes: 8 additions & 10 deletions powa/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def query(self):
from_clause = query

if self.has_extension(self.path_args[0], "pg_stat_kcache"):
from_clause = "({query}) AS sub2".format(query=query)
from_clause = f"({query}) AS sub2"

# Add system metrics from pg_stat_kcache,
kcache_query = kcache_getstatdata_sample(
Expand Down Expand Up @@ -344,10 +344,8 @@ def query(self):
]
)

from_clause += """
LEFT JOIN ({kcache_query}) AS kc USING (dbid, ts, srvid)""".format(
kcache_query=kcache_query
)
from_clause += f"""
LEFT JOIN ({kcache_query}) AS kc USING (dbid, ts, srvid)"""

return """SELECT {cols}
FROM (
Expand Down Expand Up @@ -505,7 +503,7 @@ def query(self):
wps("count_io"),
]

from_clause = "({query}) AS sub".format(query=query)
from_clause = f"({query}) AS sub"

return """SELECT {cols}
FROM {from_clause}
Expand Down Expand Up @@ -887,12 +885,12 @@ def query(self):
]
)

from_clause = """(
from_clause = f"""(
{inner_query}
) AS sub
JOIN {{powa}}.powa_statements AS ps
USING (srvid, queryid, userid, dbid)
CROSS JOIN {bs}""".format(inner_query=inner_query, bs=block_size)
CROSS JOIN {block_size}"""

return """SELECT {cols}
FROM {from_clause}
Expand Down Expand Up @@ -936,11 +934,11 @@ def query(self):
"sum(count) AS counts",
]

from_clause = """(
from_clause = f"""(
{inner_query}
) AS sub
JOIN {{powa}}.powa_statements AS ps
USING (srvid, queryid, dbid)""".format(inner_query=inner_query)
USING (srvid, queryid, dbid)"""

return """SELECT {cols}
FROM {from_clause}
Expand Down
Loading

0 comments on commit eae8dc9

Please sign in to comment.