Skip to content

Commit

Permalink
Drop support for Python 3.8
Browse files Browse the repository at this point in the history
Python 3.8 has reached its end-of-life: https://peps.python.org/pep-0569/
  • Loading branch information
dlax committed Oct 8, 2024
1 parent d767856 commit 617dc57
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 156 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
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, 9):

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],
]
4 changes: 2 additions & 2 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 @@ -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
2 changes: 1 addition & 1 deletion 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
86 changes: 0 additions & 86 deletions tests/test_cli_help_py38.txt

This file was deleted.

0 comments on commit 617dc57

Please sign in to comment.