Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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' }}

Expand Down
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ authors = [
{ name = "Taneli Hukkinen", email = "[email protected]" },
]
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 = [
Expand Down Expand Up @@ -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}"
Expand Down
2 changes: 1 addition & 1 deletion src/mdformat/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions src/mdformat/_compat.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
__all__ = ("importlib_metadata", "tomllib")
__all__ = ("tomllib",)

import sys

if sys.version_info >= (3, 11): # pragma: >=3.11 cover
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
4 changes: 2 additions & 2 deletions src/mdformat/_conf.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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():
Expand Down
9 changes: 4 additions & 5 deletions src/mdformat/plugins.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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]]] = {}
Expand Down Expand Up @@ -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`.
Expand All @@ -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`.
Expand Down
2 changes: 1 addition & 1 deletion src/mdformat/renderer/_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/mdformat/renderer/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/mdformat/renderer/typing.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/test_plugins.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import argparse
import importlib.metadata
from textwrap import dedent
from unittest.mock import patch

Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
Loading