From c9d82a20eed6972e3686078d58cb29035ae88ce7 Mon Sep 17 00:00:00 2001 From: Dima Gerasimov Date: Mon, 21 Oct 2024 19:45:42 +0100 Subject: [PATCH] general: set min versionto 3.9, since 3.8 reached EOL also update tox file and other ci files --- .github/workflows/main.yml | 9 +++-- ruff.toml | 4 +-- setup.py | 2 +- src/promnesia/__main__.py | 3 +- src/promnesia/cannon.py | 7 ++-- src/promnesia/common.py | 3 +- src/promnesia/compare.py | 3 +- src/promnesia/compat.py | 9 ++--- src/promnesia/config.py | 3 +- src/promnesia/database/common.py | 2 +- src/promnesia/database/dump.py | 5 +-- src/promnesia/database/load.py | 3 +- src/promnesia/extract.py | 2 +- src/promnesia/kjson.py | 10 +++--- src/promnesia/server.py | 8 ++--- src/promnesia/sources/auto.py | 3 +- src/promnesia/sources/browser.py | 3 +- src/promnesia/sources/browser_legacy.py | 5 +-- src/promnesia/sources/filetypes.py | 3 +- src/promnesia/sources/guess.py | 3 +- src/promnesia/sources/html.py | 4 +-- src/promnesia/sources/markdown.py | 3 +- src/promnesia/sources/org.py | 3 +- src/promnesia/sources/plaintext.py | 6 ++-- src/promnesia/sources/shellcmd.py | 2 +- src/promnesia/sources/signal.py | 3 +- src/promnesia/sources/takeout.py | 8 ++--- src/promnesia/sources/takeout_legacy.py | 4 ++- src/promnesia/sources/twitter.py | 2 +- src/promnesia/sources/vcs.py | 2 +- src/promnesia/sources/viber.py | 2 +- src/promnesia/sources/website.py | 2 +- src/promnesia/sqlite.py | 3 +- src/promnesia/tests/common.py | 3 +- src/promnesia/tests/server_helper.py | 3 +- src/promnesia/tests/test_indexer.py | 3 +- src/promnesia/tests/utils.py | 5 +-- tox.ini | 48 +++++++++++++------------ 38 files changed, 110 insertions(+), 86 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0abb95d0..c218b197 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -24,20 +24,23 @@ jobs: fail-fast: false matrix: platform: [ubuntu-latest, macos-latest, windows-latest] - python-version: ['3.9', '3.10', '3.11', '3.12'] + python-version: ['3.9', '3.10', '3.11', '3.12', '3.13'] exclude: [ # windows runners are pretty scarce, so let's only run lowest and highest python version {platform: windows-latest, python-version: '3.10'}, {platform: windows-latest, python-version: '3.11'}, + {platform: windows-latest, python-version: '3.12'}, # same, macos is a bit too slow and ubuntu covers python quirks well {platform: macos-latest , python-version: '3.10'}, {platform: macos-latest , python-version: '3.11'}, + {platform: macos-latest , python-version: '3.12'}, ] runs-on: ${{ matrix.platform }} - #continue-on-error: ${{ matrix.platform == 'windows-latest' }} + # useful for 'optional' pipelines + # continue-on-error: ${{ matrix.platform == 'windows-latest' }} steps: # ugh https://github.com/actions/toolkit/blob/main/docs/commands.md#path-manipulation @@ -61,11 +64,13 @@ jobs: - if: matrix.platform == 'ubuntu-latest' # no need to compute coverage for other platforms uses: actions/upload-artifact@v4 with: + include-hidden-files: true name: .coverage.mypy-core_${{ matrix.platform }}_${{ matrix.python-version }} path: .coverage.mypy-core/ - if: matrix.platform == 'ubuntu-latest' # no need to compute coverage for other platforms uses: actions/upload-artifact@v4 with: + include-hidden-files: true name: .coverage.mypy-misc_${{ matrix.platform }}_${{ matrix.python-version }} path: .coverage.mypy-misc/ diff --git a/ruff.toml b/ruff.toml index 6adeb91b..431e0292 100644 --- a/ruff.toml +++ b/ruff.toml @@ -1,4 +1,4 @@ -target-version = "py38" # NOTE: inferred from pyproject.toml if present +target-version = "py39" # NOTE: inferred from pyproject.toml if present lint.extend-select = [ "F", # flakes rules -- default, but extend just in case @@ -9,7 +9,7 @@ lint.extend-select = [ "C4", # flake8-comprehensions -- unnecessary list/map/dict calls "COM", # trailing commas "EXE", # various checks wrt executable files - # "I", # sort imports + "I", # sort imports "ICN", # various import conventions "FBT", # detect use of boolean arguments "FURB", # various rules diff --git a/setup.py b/setup.py index fbc57489..53802ffd 100644 --- a/setup.py +++ b/setup.py @@ -32,7 +32,7 @@ def main() -> None: author_email='karlicoss@gmail.com', description='Enhancement of your browsing history', - python_requires='>=3.8', + python_requires='>=3.9', install_requires=[ 'appdirs', # for portable user directories detection 'tzlocal', diff --git a/src/promnesia/__main__.py b/src/promnesia/__main__.py index 40d35630..cd172577 100644 --- a/src/promnesia/__main__.py +++ b/src/promnesia/__main__.py @@ -8,10 +8,11 @@ import shlex import shutil import sys +from collections.abc import Iterable, Iterator, Sequence from pathlib import Path from subprocess import Popen, check_call, run from tempfile import TemporaryDirectory, gettempdir -from typing import Callable, Iterable, Iterator, Sequence +from typing import Callable from . import config, server from .common import ( diff --git a/src/promnesia/cannon.py b/src/promnesia/cannon.py index a3d873e1..612d3226 100755 --- a/src/promnesia/cannon.py +++ b/src/promnesia/cannon.py @@ -14,10 +14,11 @@ import re import typing import urllib.parse +from collections.abc import Collection, Iterable, Sequence # TODO eh?? they fixed mobile.twitter.com? from itertools import chain -from typing import Any, Collection, Iterable, NamedTuple, Sequence, Tuple, Union +from typing import Any, NamedTuple, Union from urllib.parse import SplitResult, parse_qsl, urlencode, urlsplit, urlunsplit # this has some benchmark, but quite a few librarires seem unmaintained, sadly @@ -217,7 +218,7 @@ def get_spec(dom: str) -> Spec: # TODO this should be a map Frag = Any -Parts = Sequence[Tuple[str, str]] +Parts = Sequence[tuple[str, str]] def _yc(domain: str, path: str, qq: Parts, frag: Frag) -> tuple[Any, Any, Parts, Frag]: @@ -284,7 +285,7 @@ def transform_split(split: SplitResult): REST = r'(?P.*)' Left = Union[str, Sequence[str]] - Right = Tuple[str, str, str] + Right = tuple[str, str, str] # the idea is that we can unify certain URLs here and map them to the 'canonical' one # this is a dict only for grouping but should be a list really.. todo rules: dict[Left, Right] = { diff --git a/src/promnesia/common.py b/src/promnesia/common.py index 478e1818..c10c7b6d 100644 --- a/src/promnesia/common.py +++ b/src/promnesia/common.py @@ -7,6 +7,7 @@ import shutil import tempfile import warnings +from collections.abc import Iterable, Sequence from contextlib import contextmanager from copy import copy from datetime import date, datetime @@ -16,7 +17,7 @@ from subprocess import PIPE, Popen, run from timeit import default_timer as timer from types import ModuleType -from typing import Callable, Iterable, NamedTuple, Optional, Sequence, TypeVar, Union +from typing import Callable, NamedTuple, Optional, TypeVar, Union import pytz from more_itertools import intersperse diff --git a/src/promnesia/compare.py b/src/promnesia/compare.py index f29834ea..1f89ecaf 100644 --- a/src/promnesia/compare.py +++ b/src/promnesia/compare.py @@ -4,8 +4,9 @@ import argparse import logging import sys +from collections.abc import Iterator, Sequence from pathlib import Path -from typing import Iterator, Sequence, TypeVar +from typing import TypeVar from .common import DbVisit, PathWithMtime, Url from .database.load import row_to_db_visit diff --git a/src/promnesia/compat.py b/src/promnesia/compat.py index 95ebe5fe..c8737f95 100644 --- a/src/promnesia/compat.py +++ b/src/promnesia/compat.py @@ -7,9 +7,6 @@ from typing import Literal, Protocol # noqa: F401 ## - -# can deprecate after python3.9 -def removeprefix(text: str, prefix: str) -> str: - if text.startswith(prefix): - return text[len(prefix):] - return text + # todo deprecate properly + def removeprefix(text: str, prefix: str) -> str: + return text.removeprefix(prefix) diff --git a/src/promnesia/config.py b/src/promnesia/config.py index 9ebe2a55..ff299a33 100644 --- a/src/promnesia/config.py +++ b/src/promnesia/config.py @@ -4,9 +4,10 @@ import importlib.util import os import warnings +from collections.abc import Iterable from pathlib import Path from types import ModuleType -from typing import Callable, Iterable, NamedTuple, Union +from typing import Callable, NamedTuple, Union from .common import DbVisit, PathIsh, Res, Source, default_cache_dir, default_output_dir diff --git a/src/promnesia/database/common.py b/src/promnesia/database/common.py index bb132ea7..a63c9ef7 100644 --- a/src/promnesia/database/common.py +++ b/src/promnesia/database/common.py @@ -1,7 +1,7 @@ from __future__ import annotations +from collections.abc import Sequence from datetime import datetime -from typing import Sequence from sqlalchemy import ( Column, diff --git a/src/promnesia/database/dump.py b/src/promnesia/database/dump.py index b5f11492..1118da1c 100644 --- a/src/promnesia/database/dump.py +++ b/src/promnesia/database/dump.py @@ -1,8 +1,9 @@ from __future__ import annotations import sqlite3 +from collections.abc import Iterable from pathlib import Path -from typing import Dict, Iterable, Optional +from typing import Optional from more_itertools import chunked from sqlalchemy import ( @@ -50,7 +51,7 @@ def begin_immediate_transaction(conn): conn.exec_driver_sql('BEGIN IMMEDIATE') -Stats = Dict[Optional[SourceName], int] +Stats = dict[Optional[SourceName], int] # returns critical warnings diff --git a/src/promnesia/database/load.py b/src/promnesia/database/load.py index 2c9762c3..1313e35f 100644 --- a/src/promnesia/database/load.py +++ b/src/promnesia/database/load.py @@ -1,7 +1,6 @@ from __future__ import annotations from pathlib import Path -from typing import Tuple from sqlalchemy import ( Engine, @@ -14,7 +13,7 @@ from .common import DbVisit, get_columns, row_to_db_visit -DbStuff = Tuple[Engine, Table] +DbStuff = tuple[Engine, Table] def get_db_stuff(db_path: Path) -> DbStuff: diff --git a/src/promnesia/extract.py b/src/promnesia/extract.py index eaa95ea8..fc911cec 100644 --- a/src/promnesia/extract.py +++ b/src/promnesia/extract.py @@ -1,8 +1,8 @@ from __future__ import annotations import re +from collections.abc import Iterable, Sequence from functools import lru_cache -from typing import Iterable, Sequence from .cannon import CanonifyException from .common import ( diff --git a/src/promnesia/kjson.py b/src/promnesia/kjson.py index 54956391..4571b4ec 100644 --- a/src/promnesia/kjson.py +++ b/src/promnesia/kjson.py @@ -5,17 +5,17 @@ """ from __future__ import annotations -from typing import Any, Dict, List, Tuple, Union, cast +from typing import Any, Union, cast -JDict = Dict[str, Any] # TODO not sure if we can do recursive.. -JList = List[Any] +JDict = dict[str, Any] # TODO not sure if we can do recursive.. +JList = list[Any] JPrim = Union[str, int, float] # , type(None)] Json = Union[JDict, JList, JPrim] -JPathPart = Tuple[Json, Union[str, int]] +JPathPart = tuple[Json, Union[str, int]] -JPath = Tuple[JPathPart, ...] +JPath = tuple[JPathPart, ...] class JsonProcessor: diff --git a/src/promnesia/server.py b/src/promnesia/server.py index e0ba4a86..ec203372 100644 --- a/src/promnesia/server.py +++ b/src/promnesia/server.py @@ -9,7 +9,7 @@ from datetime import timedelta from functools import lru_cache from pathlib import Path -from typing import Any, Dict, List, NamedTuple, Optional, Protocol +from typing import Any, NamedTuple, Optional, Protocol import fastapi import pytz @@ -39,7 +39,7 @@ ) from .database.load import DbStuff, get_db_stuff, row_to_db_visit -Json = Dict[str, Any] +Json = dict[str, Any] app = fastapi.FastAPI() @@ -348,10 +348,10 @@ def as_version(version: str) -> tuple[int, int, int]: @dataclass class VisitedRequest: - urls: List[str] # noqa: UP006 # pydantic doesn't like list[str] on 3.8 -- remove later + urls: list[str] client_version: str = '' -VisitedResponse = List[Optional[Json]] +VisitedResponse = list[Optional[Json]] @app.get ('/visited', response_model=VisitedResponse) @app.post('/visited', response_model=VisitedResponse) diff --git a/src/promnesia/sources/auto.py b/src/promnesia/sources/auto.py index 16945acb..466271e1 100644 --- a/src/promnesia/sources/auto.py +++ b/src/promnesia/sources/auto.py @@ -11,12 +11,13 @@ import itertools import json import os +from collections.abc import Iterable, Iterator, Sequence from concurrent.futures import ProcessPoolExecutor as Pool from contextlib import nullcontext from fnmatch import fnmatch from functools import wraps from pathlib import Path -from typing import Any, Callable, Iterable, Iterator, NamedTuple, Optional, Sequence +from typing import Any, Callable, NamedTuple, Optional from promnesia.common import ( Loc, diff --git a/src/promnesia/sources/browser.py b/src/promnesia/sources/browser.py index b788c7dc..d52dbd19 100644 --- a/src/promnesia/sources/browser.py +++ b/src/promnesia/sources/browser.py @@ -6,7 +6,8 @@ import re import warnings -from typing import TYPE_CHECKING, Any, Iterator +from collections.abc import Iterator +from typing import TYPE_CHECKING, Any from promnesia.common import Loc, PathIsh, Results, Second, Visit, is_sqlite_db, logger diff --git a/src/promnesia/sources/browser_legacy.py b/src/promnesia/sources/browser_legacy.py index 6023ea1a..3a1aa082 100644 --- a/src/promnesia/sources/browser_legacy.py +++ b/src/promnesia/sources/browser_legacy.py @@ -122,7 +122,8 @@ def _index_db(db: Path, emitted: set): ColType = str -from typing import NamedTuple, Sequence, Tuple, Union +from collections.abc import Sequence +from typing import NamedTuple, Union class Schema(NamedTuple): @@ -130,7 +131,7 @@ class Schema(NamedTuple): key: Sequence[str] -SchemaCheck = Tuple[str, Union[str, Sequence[str]]] # todo Union: meh +SchemaCheck = tuple[str, Union[str, Sequence[str]]] # todo Union: meh from dataclasses import dataclass diff --git a/src/promnesia/sources/filetypes.py b/src/promnesia/sources/filetypes.py index b0e86ff9..fd6bca73 100644 --- a/src/promnesia/sources/filetypes.py +++ b/src/promnesia/sources/filetypes.py @@ -1,8 +1,9 @@ from __future__ import annotations +from collections.abc import Iterable, Sequence from functools import lru_cache from pathlib import Path -from typing import Callable, Iterable, NamedTuple, Sequence, Union +from typing import Callable, NamedTuple, Union from ..common import Results, Url diff --git a/src/promnesia/sources/guess.py b/src/promnesia/sources/guess.py index a0ef0e7f..af9885f1 100644 --- a/src/promnesia/sources/guess.py +++ b/src/promnesia/sources/guess.py @@ -1,6 +1,7 @@ # TODO eh. confusing how guess and auto are different... # maybe merge them later? -from typing import Any, Iterable +from collections.abc import Iterable +from typing import Any from ..common import Extraction, PathIsh diff --git a/src/promnesia/sources/html.py b/src/promnesia/sources/html.py index eaac27e5..228828b9 100644 --- a/src/promnesia/sources/html.py +++ b/src/promnesia/sources/html.py @@ -4,8 +4,8 @@ from __future__ import annotations +from collections.abc import Iterator from pathlib import Path -from typing import Iterator, Tuple from bs4 import BeautifulSoup @@ -15,7 +15,7 @@ # TODO on some exceptions, request a fallback to text? -Url = Tuple[str, str] +Url = tuple[str, str] def extract_urls_from_html(s: str) -> Iterator[Url]: diff --git a/src/promnesia/sources/markdown.py b/src/promnesia/sources/markdown.py index e681545c..57b01424 100644 --- a/src/promnesia/sources/markdown.py +++ b/src/promnesia/sources/markdown.py @@ -1,7 +1,8 @@ from __future__ import annotations +from collections.abc import Iterator from pathlib import Path -from typing import Iterator, NamedTuple +from typing import NamedTuple import mistletoe # type: ignore import mistletoe.block_token as BT # type: ignore diff --git a/src/promnesia/sources/org.py b/src/promnesia/sources/org.py index 7ec8866c..3c255bce 100644 --- a/src/promnesia/sources/org.py +++ b/src/promnesia/sources/org.py @@ -1,9 +1,10 @@ from __future__ import annotations import re +from collections.abc import Iterable, Iterator from datetime import datetime from pathlib import Path -from typing import Iterable, Iterator, NamedTuple, Optional, cast +from typing import NamedTuple, Optional, cast import orgparse from orgparse.date import OrgDate, gene_timestamp_regex diff --git a/src/promnesia/sources/plaintext.py b/src/promnesia/sources/plaintext.py index 342a427e..2d16728f 100644 --- a/src/promnesia/sources/plaintext.py +++ b/src/promnesia/sources/plaintext.py @@ -2,10 +2,8 @@ from functools import lru_cache from pathlib import Path -from typing import List from promnesia.common import PathIsh, _is_windows, get_logger, get_tmpdir -from promnesia.compat import removeprefix # https://linux-and-mac-hacks.blogspot.co.uk/2013/04/use-grep-and-regular-expressions-to.html _URL_REGEX = r'\b(https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]*[-A-Za-z0-9+&@#/%=~_|]' @@ -13,7 +11,7 @@ if _is_windows: # wtf? for some reason on windows (in cmd.exe specificaly) \b isn't working... # this will make the regex a bit less precise, but not end of the world - _URL_REGEX = removeprefix(_URL_REGEX, r'\b') + _URL_REGEX = _URL_REGEX.removeprefix(r'\b') @lru_cache @@ -22,7 +20,7 @@ def _has_grep() -> bool: return shutil.which('grep') is not None -Command = List[str] +Command = list[str] _GREP_ARGS: Command = [ diff --git a/src/promnesia/sources/shellcmd.py b/src/promnesia/sources/shellcmd.py index 6d76c699..d79ac6c4 100644 --- a/src/promnesia/sources/shellcmd.py +++ b/src/promnesia/sources/shellcmd.py @@ -7,9 +7,9 @@ import os import re import warnings +from collections.abc import Sequence from datetime import datetime from subprocess import PIPE, run -from typing import Sequence from promnesia.common import ( Loc, diff --git a/src/promnesia/sources/signal.py b/src/promnesia/sources/signal.py index cf455aca..a1e7c556 100644 --- a/src/promnesia/sources/signal.py +++ b/src/promnesia/sources/signal.py @@ -13,10 +13,11 @@ import platform import sqlite3 import subprocess as sbp +from collections.abc import Iterable, Iterator, Mapping from contextlib import contextmanager from pathlib import Path from textwrap import dedent, indent -from typing import Any, Iterable, Iterator, Mapping, Union +from typing import Any, Union from ..common import Loc, PathIsh, Results, Visit, extract_urls, from_epoch diff --git a/src/promnesia/sources/takeout.py b/src/promnesia/sources/takeout.py index 3a5ce947..8f34362d 100644 --- a/src/promnesia/sources/takeout.py +++ b/src/promnesia/sources/takeout.py @@ -5,10 +5,10 @@ from __future__ import annotations import warnings -from typing import Any, Iterable, NamedTuple +from collections.abc import Iterable +from typing import Any, NamedTuple from promnesia.common import Loc, Results, Visit, logger -from promnesia.compat import removeprefix # incase user is using an old version of google_takeout_parser @@ -77,13 +77,13 @@ def warn_once_if_not_seen(e: Any) -> Iterable[Exception]: # when you follow something from search the actual url goes after this # e.g. https://www.google.com/url?q=https://en.wikipedia.org/wiki/Clapham # note: also title usually starts with 'Visited ', in such case but perhaps fine to keep it - url = removeprefix(url, "https://www.google.com/url?q=") + url = url.removeprefix("https://www.google.com/url?q=") title = e.title if e.header == 'Chrome': # title contains 'Visited ' in this case context = None - title = removeprefix(title, 'Visited ') + title = title.removeprefix('Visited ') elif e.header in _CLEAR_CONTEXT_FOR_HEADERS: # todo perhaps could add to some sort of metadata? # only useful for debugging really diff --git a/src/promnesia/sources/takeout_legacy.py b/src/promnesia/sources/takeout_legacy.py index 0eb44aa4..66fd3c45 100644 --- a/src/promnesia/sources/takeout_legacy.py +++ b/src/promnesia/sources/takeout_legacy.py @@ -27,10 +27,10 @@ def index() -> Results: import json +from collections.abc import Iterable from datetime import datetime from itertools import chain from pathlib import Path -from typing import Iterable import pytz from more_itertools import unique_everseen @@ -52,7 +52,9 @@ def cachew(*args, **kwargs): # type: ignore[no-redef] def _read_myactivity_html(takeout: TakeoutPath, kind: str) -> Iterable[Visit]: + # FIXME switch to actual kompress? and use CPath? from my.core.kompress import kexists + # TODO glob # TODO not sure about windows path separators?? spath = 'Takeout/My Activity/' + kind diff --git a/src/promnesia/sources/twitter.py b/src/promnesia/sources/twitter.py index 8aa7bf32..9ec7b0ad 100644 --- a/src/promnesia/sources/twitter.py +++ b/src/promnesia/sources/twitter.py @@ -2,7 +2,7 @@ Uses [[https://github.com/karlicoss/HPI][HPI]] for Twitter data. ''' -from typing import Iterable +from collections.abc import Iterable from promnesia.common import Loc, Res, Results, Visit, extract_urls, logger diff --git a/src/promnesia/sources/vcs.py b/src/promnesia/sources/vcs.py index b2d3d245..dfdafe5b 100644 --- a/src/promnesia/sources/vcs.py +++ b/src/promnesia/sources/vcs.py @@ -4,11 +4,11 @@ from __future__ import annotations import re +from collections.abc import Iterable # TODO not sure if worth exposing... could be just handled by auto or something?) from pathlib import Path from subprocess import check_call -from typing import Iterable from ..common import Extraction, PathIsh, get_tmpdir, slugify diff --git a/src/promnesia/sources/viber.py b/src/promnesia/sources/viber.py index 8c3fa005..18bb4643 100644 --- a/src/promnesia/sources/viber.py +++ b/src/promnesia/sources/viber.py @@ -7,9 +7,9 @@ import logging import sqlite3 import textwrap +from collections.abc import Iterable from os import PathLike from pathlib import Path -from typing import Iterable from ..common import Loc, PathIsh, Results, Visit, extract_urls, from_epoch, join_tags from ..sqlite import sqlite_connection diff --git a/src/promnesia/sources/website.py b/src/promnesia/sources/website.py index 2c2617f7..17b66846 100644 --- a/src/promnesia/sources/website.py +++ b/src/promnesia/sources/website.py @@ -3,9 +3,9 @@ ''' import re +from collections.abc import Iterable from pathlib import Path from subprocess import run -from typing import Iterable from promnesia.common import Extraction, PathIsh, get_logger, get_tmpdir, slugify diff --git a/src/promnesia/sqlite.py b/src/promnesia/sqlite.py index 10cdcd79..5068903a 100644 --- a/src/promnesia/sqlite.py +++ b/src/promnesia/sqlite.py @@ -1,8 +1,9 @@ from __future__ import annotations import sqlite3 +from collections.abc import Iterator from contextlib import contextmanager -from typing import Any, Callable, Iterator, Literal, Union +from typing import Any, Callable, Literal, Union from .common import PathIsh diff --git a/src/promnesia/tests/common.py b/src/promnesia/tests/common.py index 9089b9c5..d48555df 100644 --- a/src/promnesia/tests/common.py +++ b/src/promnesia/tests/common.py @@ -5,10 +5,11 @@ import os import socket import sys +from collections.abc import Iterator from contextlib import closing, contextmanager from pathlib import Path from textwrap import dedent -from typing import Iterator, NoReturn, TypeVar +from typing import NoReturn, TypeVar import pytest diff --git a/src/promnesia/tests/server_helper.py b/src/promnesia/tests/server_helper.py index c746773f..0c2485fe 100644 --- a/src/promnesia/tests/server_helper.py +++ b/src/promnesia/tests/server_helper.py @@ -2,10 +2,11 @@ import sys import time +from collections.abc import Iterator from contextlib import contextmanager from dataclasses import dataclass from pathlib import Path -from typing import Any, Iterator +from typing import Any import psutil import requests diff --git a/src/promnesia/tests/test_indexer.py b/src/promnesia/tests/test_indexer.py index 5a64c9dd..d1592490 100644 --- a/src/promnesia/tests/test_indexer.py +++ b/src/promnesia/tests/test_indexer.py @@ -196,7 +196,8 @@ def cfg() -> None: SOURCES = [Source(demo.index, count=7, name='somename')] - from typing import Iterator, cast + from collections.abc import Iterator + from typing import cast from promnesia.common import DbVisit, Loc, Res from promnesia.sources import demo diff --git a/src/promnesia/tests/utils.py b/src/promnesia/tests/utils.py index bc6c27a4..f32f2a85 100644 --- a/src/promnesia/tests/utils.py +++ b/src/promnesia/tests/utils.py @@ -1,6 +1,7 @@ +from collections.abc import Mapping, Sequence from datetime import datetime, timedelta from pathlib import Path -from typing import Mapping, Optional, Sequence, Tuple, Union +from typing import Optional, Union from ..common import Loc, Source, Visit from ..database.dump import visits_to_sqlite @@ -9,7 +10,7 @@ # TODO a bit shit... why did I make it dict at first?? Urls = Union[ Mapping[str, Optional[str]], - Sequence[Tuple[str, Optional[str]]], + Sequence[tuple[str, Optional[str]]], ] diff --git a/tox.ini b/tox.ini index 62200cc8..01e9e9c8 100644 --- a/tox.ini +++ b/tox.ini @@ -27,22 +27,25 @@ passenv = # todo ugh this is all so confusing... need to simplify +# note: --use-pep517 below is necessary for tox --parallel flag to work properly +# otherwise it seems that it tries to modify .eggs dir in parallel and it fails + + [testenv:ruff] +deps = + -e .[testing] commands = - {envpython} -m pip install --use-pep517 -e .[testing] {envpython} -m ruff check src/ [testenv:tests] +deps = + -e .[testing,all,HPI,org] commands = - {envpython} -m pip install --use-pep517 -e .[testing] - - {envpython} -m pip install --use-pep517 -e .[all] - {envpython} -m pip install --use-pep517 -e .[HPI,org] - # used in some tests - {envpython} -m my.core module install my.google.takeout.parser - {envpython} -m my.core module install my.hypothesis + {envpython} -m my.core module install \ + my.google.takeout.parser \ + my.hypothesis {envpython} -m pytest --pyargs {[testenv]package_name}.tests @@ -50,15 +53,17 @@ commands = setenv = WITH_BROWSER_TESTS=true PYTEST_TIMEOUT=120 +deps = + -e .[testing,HPI] commands = - {envpython} -m pip install --use-pep517 -e .[testing,HPI] {envpython} -m my.core module install my.hypothesis {envpython} -m pytest tests/end2end_test.py {posargs} [testenv:mypy-core] +deps = + -e .[testing] commands = - {envpython} -m pip install --use-pep517 -e .[testing] {envpython} -m mypy --install-types --non-interactive \ # note: sources are tested separately, below -p {[testenv]package_name} --exclude 'sources/*' \ @@ -69,19 +74,18 @@ commands = [testenv:mypy-misc] +deps = + -e .[testing,HPI,org] # todo install from HPI[all] or something? commands = - {envpython} -m pip install --use-pep517 -e .[testing] - {envpython} -m pip install --use-pep517 -e .[HPI,org] - # todo install from HPI[all] or something? - - {envpython} -m my.core module install my.github.ghexport - {envpython} -m my.core module install my.hypothesis - {envpython} -m my.core module install my.instapaper - {envpython} -m my.core module install my.pocket - {envpython} -m my.core module install my.reddit - {envpython} -m my.core module install my.fbmessenger - {envpython} -m my.core module install my.google.takeout.parser - {envpython} -m my.core module install my.browser.export + {envpython} -m my.core module install \ + my.github.ghexport \ + my.hypothesis \ + my.instapaper \ + my.pocket \ + my.reddit \ + my.fbmessenger \ + my.google.takeout.parser \ + my.browser.export {envpython} -m mypy --install-types --non-interactive \ -p {[testenv]package_name}.sources \