Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update supported python versions #428

Merged
merged 4 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@ jobs:
strategy:
matrix:
include:
- python: "3.8"
- python: "3.9"
psycopg: "psycopg2"
- python: "3.12"
- python: "3.13"
psycopg: "psycopg3"
steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
allow-prereleases: true
- name: Install tox
run: pip install tox
- name: Add fr_FR and zh_TW for test purposes
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repos:
hooks:
- id: pyupgrade
name: pyupgrade
entry: pyupgrade --py38-plus --exit-zero-even-if-changed
entry: pyupgrade --py39-plus --exit-zero-even-if-changed
language: system
types: [python]
- id: black
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
configuration file.
* Add non-negative counterparts of many `--no-...` command-line option, thus
allowing to enable respective feature/behaviour even if disabled in the
configuration. (Requires Python 3.9 or higher.)
configuration.
* Add a `y` command to copy focused query to the system clipboard, using
OSC 52 escape sequence (#311).

Expand All @@ -20,6 +20,10 @@

* Exit with status 0 upon keyboard interrupt.

### Removed

* Python 3.8 is no longer supported.

## pg\_activity 3.5.1 - 2024-04-03

### Fixed
Expand Down
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ ex:
pg_activity [options] [connection string]

Configuration:
-P PROFILE, --profile PROFILE
-P, --profile PROFILE
Configuration profile matching a PROFILE.conf file in
${XDG_CONFIG_HOME:~/.config}/pg_activity/ or
/etc/pg_activity/, or a built-in profile.
Expand Down Expand Up @@ -123,13 +123,11 @@ ex:
Connection Options:
connection string A valid connection string to the database, e.g.:
'host=HOSTNAME port=PORT user=USER dbname=DBNAME'.
-h HOSTNAME, --host HOSTNAME
Database server host or socket directory.
-p PORT, --port PORT Database server port.
-U USERNAME, --username USERNAME
-h, --host HOSTNAME Database server host or socket directory.
-p, --port PORT Database server port.
-U, --username USERNAME
Database user name.
-d DBNAME, --dbname DBNAME
Database name to connect to.
-d, --dbname DBNAME Database name to connect to.

Process table display options:
These options may be used hide some columns from the processes table.
Expand Down
2 changes: 1 addition & 1 deletion pgactivity/activities.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import builtins
import os
import time
from collections.abc import Sequence
from typing import TypeVar
from warnings import catch_warnings, simplefilter

import attr
import psutil

from .compat import Sequence
from .types import (
BlockingProcess,
IOCounter,
Expand Down
15 changes: 7 additions & 8 deletions pgactivity/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,13 @@ def configure_logger(debug_file: str | None = None) -> StringIO:

def flag(p: Any, spec: str, *, dest: str, feature: str) -> None:
assert not spec.startswith("--no-") and spec.startswith("--"), spec
if sys.version_info < (3, 9):
spec = f"--no-{spec[2:]}"
action = "store_false"
help = f"Disable {feature}."
else:
action = argparse.BooleanOptionalAction
help = f"Enable/disable {feature}."
p.add_argument(spec, dest=dest, help=help, action=action, default=None)
p.add_argument(
spec,
dest=dest,
help=f"Enable/disable {feature}.",
action=argparse.BooleanOptionalAction,
default=None,
)


def get_parser() -> argparse.ArgumentParser:
Expand Down
46 changes: 0 additions & 46 deletions pgactivity/compat.py
Original file line number Diff line number Diff line change
@@ -1,59 +1,13 @@
from __future__ import annotations

import importlib.resources
import operator
import sys
from importlib.metadata import version
from typing import Any

import attr
import attr.validators
import blessed

__all__ = [
"Callable",
"Dict",
"Iterable",
"Iterator",
"Mapping",
"MutableSet",
"Sequence",
]

if sys.version_info >= (3, 9):
from collections.abc import (
Callable,
Iterable,
Iterator,
Mapping,
MutableSet,
Sequence,
)

Dict = dict
else:
from typing import Callable, Dict, Iterable, Iterator, Mapping, MutableSet, Sequence

if sys.version_info >= (3, 11):

def read_resource(pkgname: str, dirname: str, *args: str) -> str | None:
resource = importlib.resources.files(pkgname).joinpath(dirname)
for arg in args:
resource = resource.joinpath(arg)
if resource.is_file():
return resource.read_text()
return None

else:

def read_resource(pkgname: str, dirname: str, *args: str) -> str | None:
with importlib.resources.path(pkgname, dirname) as dirp:
f = dirp.joinpath(*args)
if f.is_file():
return f.read_text()
return None


ATTR_VERSION = tuple(int(x) for x in version("attrs").split(".", 2)[:2])
BLESSED_VERSION = tuple(int(x) for x in version("blessed").split(".", 2)[:2])

Expand Down
12 changes: 11 additions & 1 deletion pgactivity/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import configparser
import enum
import importlib.resources
import io
import os
from collections.abc import ItemsView
Expand All @@ -11,7 +12,16 @@
import attr
from attr import validators

from .compat import gt, read_resource
from .compat import gt


def read_resource(pkgname: str, dirname: str, *args: str) -> str | None:
resource = importlib.resources.files(pkgname).joinpath(dirname)
for arg in args:
resource = resource.joinpath(arg)
if resource.is_file():
return resource.read_text()
return None


class ConfigurationError(Exception):
Expand Down
5 changes: 2 additions & 3 deletions pgactivity/pg.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

import logging
import os
from collections.abc import Callable, Sequence
from typing import Any, TypeVar, overload

from .compat import Callable, Dict, Sequence

Row = TypeVar("Row")

try:
Expand All @@ -29,7 +28,7 @@

__version__ = psycopg.__version__

Connection = psycopg.Connection[Dict[str, Any]]
Connection = psycopg.Connection[dict[str, Any]]

class BytesLoader(Loader):
def load(self, data: Buffer) -> bytes:
Expand Down
2 changes: 1 addition & 1 deletion pgactivity/queries/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
here = pathlib.Path(__file__).parent


@functools.lru_cache(maxsize=None)
@functools.cache
def get(name: str) -> str:
path = here / f"{name}.sql"
with path.open() as f:
Expand Down
10 changes: 5 additions & 5 deletions pgactivity/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

import enum
import functools
from collections.abc import Callable, Iterable, Iterator, Mapping, MutableSet, Sequence
from datetime import timedelta
from ipaddress import IPv4Address, IPv6Address
from typing import Any, Tuple, TypeVar, Union, overload
from typing import Any, TypeVar, Union, overload

import attr
import psutil
from attr import validators

from . import colors, compat, pg, utils
from .compat import Callable, Iterable, Iterator, Mapping, MutableSet, Sequence
from .config import Configuration, Flag, HeaderSection, UISection


Expand Down Expand Up @@ -1186,7 +1186,7 @@ def copy_focused_query_to_clipboard(self) -> str:
ActivityStats = Union[
Iterable[WaitingProcess],
Iterable[RunningProcess],
Tuple[Iterable[WaitingProcess], SystemInfo],
Tuple[Iterable[BlockingProcess], SystemInfo],
Tuple[Iterable[LocalRunningProcess], SystemInfo],
tuple[Iterable[WaitingProcess], SystemInfo],
tuple[Iterable[BlockingProcess], SystemInfo],
tuple[Iterable[LocalRunningProcess], SystemInfo],
]
6 changes: 3 additions & 3 deletions pgactivity/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import time
from argparse import Namespace
from functools import partial
from typing import List, cast
from typing import cast

import attr
from blessed import Terminal
Expand Down Expand Up @@ -120,7 +120,7 @@ def main(
action_formatter = getattr(term, color)
pids = pg_procs.selected
if len(pids) > 1:
ptitle = f"processes {', '.join((str(p) for p in pids))}"
ptitle = f"processes {', '.join(str(p) for p in pids)}"
else:
ptitle = f"process {pids[0]}"
with term.location(x=0, y=term.height // 3):
Expand Down Expand Up @@ -216,7 +216,7 @@ def main(
if is_local:
# TODO: Use this logic in waiting and blocking cases.
local_pg_procs, io_read, io_write = activities.ps_complete(
cast(List[types.RunningProcess], pg_procs.items),
cast(list[types.RunningProcess], pg_procs.items),
sys_procs,
fs_blocksize,
)
Expand Down
3 changes: 2 additions & 1 deletion pgactivity/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import functools
import re
import sys
from collections.abc import Iterable, Mapping
from datetime import datetime, timedelta, timezone
from typing import IO, Any, Iterable, Mapping
from typing import IO, Any

import attr
import humanize
Expand Down
3 changes: 2 additions & 1 deletion pgactivity/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
import functools
import inspect
import itertools
from collections.abc import Callable, Iterable, Iterator, Sequence
from textwrap import TextWrapper, dedent
from typing import Any, Literal

from blessed import Terminal

from . import colors, utils
from .activities import sorted as sorted_processes
from .compat import Callable, Iterable, Iterator, Sequence, link
from .compat import link
from .keys import BINDINGS, EXIT_KEY
from .keys import HELP as HELP_KEY
from .keys import (
Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dynamic = ["version"]
description = "Command line tool for PostgreSQL server activity monitoring."
readme = "README.md"
license = { text = "PostgreSQL" }
requires-python = ">=3.8"
requires-python = ">=3.9"
authors = [
{ name = "Julien Tachoires", email = "[email protected]" },
{ name = "Benoit Lobréau", email = "[email protected]" },
Expand Down Expand Up @@ -39,7 +39,6 @@ dependencies = [
"attrs >= 17.4, !=21.1",
"blessed >= 1.15.0",
"humanize >= 0.5.1",
"importlib_metadata; python_version < '3.8'",
"psutil >= 2.0.0",
]

Expand Down
5 changes: 0 additions & 5 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import sys

import pytest

from pgactivity import cli


Expand Down Expand Up @@ -48,7 +44,6 @@ def test_parser() -> None:
}


@pytest.mark.skipif(sys.version_info < (3, 9), reason="require python >= 3.9")
def test_parser_flag_on() -> None:
parser = cli.get_parser()
ns = parser.parse_args(["--pid", "--no-app-name"])
Expand Down
16 changes: 7 additions & 9 deletions tests/test_cli_help.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
>>> import sys
>>> import pytest
>>> if sys.version_info < (3, 9):
... pytest.skip("only applies for Python version >= 3.9")
>>> if sys.version_info < (3, 13):
... pytest.skip("only applies for Python version >= 3.13")
...

>>> from pgactivity import cli
Expand All @@ -12,7 +12,7 @@ usage: pytest [options] [connection string]
htop like application for PostgreSQL server activity monitoring.
<BLANKLINE>
Configuration:
-P PROFILE, --profile PROFILE
-P, --profile PROFILE
Configuration profile matching a PROFILE.conf file in
${XDG_CONFIG_HOME:~/.config}/pg_activity/ or
/etc/pg_activity/, or a built-in profile.
Expand Down Expand Up @@ -48,13 +48,11 @@ Options:
Connection Options:
connection string A valid connection string to the database, e.g.:
'host=HOSTNAME port=PORT user=USER dbname=DBNAME'.
-h HOSTNAME, --host HOSTNAME
Database server host or socket directory.
-p PORT, --port PORT Database server port.
-U USERNAME, --username USERNAME
-h, --host HOSTNAME Database server host or socket directory.
-p, --port PORT Database server port.
-U, --username USERNAME
Database user name.
-d DBNAME, --dbname DBNAME
Database name to connect to.
-d, --dbname DBNAME Database name to connect to.
<BLANKLINE>
Process table display options:
These options may be used hide some columns from the processes table.
Expand Down
Loading
Loading