diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index c297e92..31bd13a 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -33,7 +33,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - python-version: ['3.9', '3.10', '3.11', '3.12', '3.13', '3.14-dev'] + python-version: ['3.10', '3.11', '3.12', '3.13', '3.14-dev'] os: [ubuntu-latest, macos-latest, windows-latest] continue-on-error: ${{ matrix.python-version == '3.14-dev' }} diff --git a/pyproject.toml b/pyproject.toml index 7b08ed0..1d5b9dc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,11 +11,10 @@ authors = [ { name = "Taneli Hukkinen", email = "hukkin@users.noreply.github.com" }, ] license = { file = "LICENSE" } -requires-python = ">=3.9" +requires-python = ">=3.10" dependencies = [ 'markdown-it-py>=1,<5', 'tomli >=1.1.0; python_version < "3.11"', - 'importlib-metadata >=3.6.0; python_version < "3.10"', ] readme = "README.md" classifiers = [ @@ -62,7 +61,7 @@ xfail_strict = true [tool.tox] requires = ["tox>=4.21.1"] # Only run pytest envs when no args given to tox -env_list = ["3.9", "3.10", "3.11", "3.12", "3.13"] +env_list = ["3.10", "3.11", "3.12", "3.13"] [tool.tox.env_run_base] description = "run tests under {base_python}" diff --git a/src/mdformat/_cli.py b/src/mdformat/_cli.py index b3838b0..d7dd522 100644 --- a/src/mdformat/_cli.py +++ b/src/mdformat/_cli.py @@ -452,7 +452,7 @@ def wrap_paragraphs(paragraphs: Iterable[str]) -> str: @contextlib.contextmanager def log_handler_applied( logger: logging.Logger, handler: logging.Handler -) -> Generator[None, None, None]: +) -> Generator[None]: logger.addHandler(handler) try: yield diff --git a/src/mdformat/_compat.py b/src/mdformat/_compat.py index 8c788e7..04e69bc 100644 --- a/src/mdformat/_compat.py +++ b/src/mdformat/_compat.py @@ -1,4 +1,4 @@ -__all__ = ("importlib_metadata", "tomllib") +__all__ = ("tomllib",) import sys @@ -6,8 +6,3 @@ import tomllib else: # pragma: <3.11 cover import tomli as tomllib - -if sys.version_info >= (3, 10): # pragma: >=3.10 cover - from importlib import metadata as importlib_metadata -else: # pragma: <3.10 cover - import importlib_metadata diff --git a/src/mdformat/_conf.py b/src/mdformat/_conf.py index c2250b1..d50a798 100644 --- a/src/mdformat/_conf.py +++ b/src/mdformat/_conf.py @@ -1,9 +1,9 @@ from __future__ import annotations +from collections.abc import Mapping import functools from pathlib import Path from types import MappingProxyType -from typing import Mapping from mdformat._compat import tomllib from mdformat._util import EMPTY_MAP @@ -32,7 +32,7 @@ class InvalidConfError(Exception): """ -@functools.lru_cache() +@functools.lru_cache def read_toml_opts(conf_dir: Path) -> tuple[Mapping, Path | None]: conf_path = conf_dir / ".mdformat.toml" if not conf_path.is_file(): diff --git a/src/mdformat/plugins.py b/src/mdformat/plugins.py index c39d8bc..e984018 100644 --- a/src/mdformat/plugins.py +++ b/src/mdformat/plugins.py @@ -1,9 +1,8 @@ from __future__ import annotations +import importlib.metadata from typing import TYPE_CHECKING, Any, Protocol -from mdformat._compat import importlib_metadata - if TYPE_CHECKING: import argparse from collections.abc import Callable, Mapping @@ -14,7 +13,7 @@ def _load_entrypoints( - eps: importlib_metadata.EntryPoints, + eps: importlib.metadata.EntryPoints, ) -> tuple[dict[str, Any], dict[str, tuple[str, list[str]]]]: loaded_ifaces: dict[str, Any] = {} dist_versions: dict[str, tuple[str, list[str]]] = {} @@ -95,7 +94,7 @@ def __getattr__(name: str) -> Mapping[str, Any]: """ if name in {"CODEFORMATTERS", "_CODEFORMATTER_DISTS"}: formatters, formatter_dists = _load_entrypoints( - importlib_metadata.entry_points(group="mdformat.codeformatter") + importlib.metadata.entry_points(group="mdformat.codeformatter") ) # Cache the values in this module for next time, so that `__getattr__` # is only called once per `name`. @@ -105,7 +104,7 @@ def __getattr__(name: str) -> Mapping[str, Any]: return formatters if name == "CODEFORMATTERS" else formatter_dists if name in {"PARSER_EXTENSIONS", "_PARSER_EXTENSION_DISTS"}: extensions, extension_dists = _load_entrypoints( - importlib_metadata.entry_points(group="mdformat.parser_extension") + importlib.metadata.entry_points(group="mdformat.parser_extension") ) # Cache the value in this module for next time, so that `__getattr__` # is only called once per `name`. diff --git a/src/mdformat/renderer/_context.py b/src/mdformat/renderer/_context.py index 1e5a666..238dd07 100644 --- a/src/mdformat/renderer/_context.py +++ b/src/mdformat/renderer/_context.py @@ -631,7 +631,7 @@ class RenderContext(NamedTuple): env: MutableMapping @contextmanager - def indented(self, width: int) -> Generator[None, None, None]: + def indented(self, width: int) -> Generator[None]: self.env["indent_width"] += width try: yield diff --git a/src/mdformat/renderer/_util.py b/src/mdformat/renderer/_util.py index 6532cc5..b400c7b 100644 --- a/src/mdformat/renderer/_util.py +++ b/src/mdformat/renderer/_util.py @@ -231,7 +231,7 @@ def escape_square_brackets(text: str, used_refs: Iterable[str]) -> str: enclosure_start: int | None = None while True: bracket_match = RE_SQUARE_BRACKET.search(text, pos) - if not bracket_match: # pragma: >=3.10 cover + if not bracket_match: if enclosure_start is not None: escape_before_pos.append(enclosure_start) break diff --git a/src/mdformat/renderer/typing.py b/src/mdformat/renderer/typing.py index b29c636..c4bdef0 100644 --- a/src/mdformat/renderer/typing.py +++ b/src/mdformat/renderer/typing.py @@ -1,7 +1,8 @@ -from typing import TYPE_CHECKING, Any, Callable +from collections.abc import Callable +from typing import TYPE_CHECKING, Any if TYPE_CHECKING: - from mdformat.renderer import RenderTreeNode + from mdformat.renderer import RenderTreeNode # noqa: F401 # There should be `mdformat.renderer.RenderContext` instead of `Any` # here and in `Postprocess` below but that results in recursive typing diff --git a/tests/test_plugins.py b/tests/test_plugins.py index 1b596ee..d25646c 100644 --- a/tests/test_plugins.py +++ b/tests/test_plugins.py @@ -1,4 +1,5 @@ import argparse +import importlib.metadata from textwrap import dedent from unittest.mock import patch @@ -7,7 +8,6 @@ import mdformat from mdformat._cli import run -from mdformat._compat import importlib_metadata from mdformat.plugins import ( _PARSER_EXTENSION_DISTS, CODEFORMATTERS, @@ -439,7 +439,7 @@ def test_load_entrypoints(tmp_path, monkeypatch): Version: 0.3.6 """ ) - distro = importlib_metadata.PathDistribution(dist_info_path) + distro = importlib.metadata.PathDistribution(dist_info_path) entrypoints = distro.entry_points loaded_eps, dist_infos = _load_entrypoints(entrypoints)