Skip to content

Commit aae2e3e

Browse files
committed
fix: circular import in plugins that import from mdformat.renderer
1 parent d9aa005 commit aae2e3e

File tree

4 files changed

+35
-16
lines changed

4 files changed

+35
-16
lines changed

docs/users/changelog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,15 @@
33
This log documents all Python API or CLI breaking backwards incompatible changes.
44
Note that there is currently no guarantee for a stable Markdown formatting style across versions.
55

6+
## 0.7.21
7+
8+
- Fixed
9+
- Circular import in plugins that import from `mdformat.renderer`.
10+
611
## 0.7.20
712

13+
**NOTE:** This release was yanked from PyPI.
14+
815
- Deprecated
916
- `mdformat.codepoints.ASCII_WHITESPACE`.
1017
CommonMark no longer defines this since v0.30.

src/mdformat/_cli.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33
import argparse
44
from collections.abc import Generator, Iterable, Mapping, Sequence
55
import contextlib
6+
import functools
67
import logging
78
import os.path
89
from pathlib import Path
910
import shutil
1011
import sys
12+
import textwrap
1113

1214
import mdformat
1315
from mdformat._conf import DEFAULT_OPTS, InvalidConfError, read_toml_opts
14-
from mdformat._util import cached_textwrapper, detect_newline_type, is_md_equal
16+
from mdformat._util import detect_newline_type, is_md_equal
1517
import mdformat.plugins
1618
import mdformat.renderer
1719

@@ -406,6 +408,17 @@ def print_error(title: str, paragraphs: Iterable[str] = ()) -> None:
406408
print_paragraphs(paragraphs)
407409

408410

411+
@functools.lru_cache
412+
def cached_textwrapper(width: int) -> textwrap.TextWrapper:
413+
return textwrap.TextWrapper(
414+
break_long_words=False,
415+
break_on_hyphens=False,
416+
width=width,
417+
expand_tabs=False,
418+
replace_whitespace=False,
419+
)
420+
421+
409422
def wrap_paragraphs(paragraphs: Iterable[str]) -> str:
410423
"""Wrap and concatenate paragraphs.
411424

src/mdformat/_util.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
from collections.abc import Iterable, Mapping
44
from contextlib import nullcontext
5-
import functools
65
import re
7-
import textwrap
86
from types import MappingProxyType
97
from typing import Any, Literal
108

@@ -126,14 +124,3 @@ def detect_newline_type(md: str, eol_setting: str) -> Literal["\n", "\r\n"]:
126124
if eol_setting == "crlf":
127125
return "\r\n"
128126
return "\n"
129-
130-
131-
@functools.lru_cache
132-
def cached_textwrapper(width: int) -> textwrap.TextWrapper:
133-
return textwrap.TextWrapper(
134-
break_long_words=False,
135-
break_on_hyphens=False,
136-
width=width,
137-
expand_tabs=False,
138-
replace_whitespace=False,
139-
)

src/mdformat/renderer/_context.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@
33
from collections import defaultdict
44
from collections.abc import Generator, Iterable, Mapping, MutableMapping
55
from contextlib import contextmanager
6+
import functools
67
import logging
78
import re
9+
import textwrap
810
from types import MappingProxyType
911
from typing import TYPE_CHECKING, Any, Literal, NamedTuple
1012

1113
from markdown_it.rules_block.html_block import HTML_SEQUENCES
1214

1315
from mdformat import codepoints
1416
from mdformat._conf import DEFAULT_OPTS
15-
from mdformat._util import cached_textwrapper
1617
from mdformat.renderer._util import (
1718
RE_CHAR_REFERENCE,
1819
decimalify_leading,
@@ -27,10 +28,10 @@
2728
longest_consecutive_sequence,
2829
maybe_add_link_brackets,
2930
)
30-
from mdformat.renderer.typing import Postprocess, Render
3131

3232
if TYPE_CHECKING:
3333
from mdformat.renderer import RenderTreeNode
34+
from mdformat.renderer.typing import Postprocess, Render
3435

3536
LOGGER = logging.getLogger(__name__)
3637

@@ -333,6 +334,17 @@ def blockquote(node: RenderTreeNode, context: RenderContext) -> str:
333334
return quoted_str
334335

335336

337+
@functools.lru_cache
338+
def cached_textwrapper(width: int) -> textwrap.TextWrapper:
339+
return textwrap.TextWrapper(
340+
break_long_words=False,
341+
break_on_hyphens=False,
342+
width=width,
343+
expand_tabs=False,
344+
replace_whitespace=False,
345+
)
346+
347+
336348
def _wrap(text: str, *, width: int | Literal["no"]) -> str:
337349
"""Wrap text at locations pointed by `WRAP_POINT`s.
338350

0 commit comments

Comments
 (0)