Skip to content

Commit

Permalink
fix: circular import in plugins that import from mdformat.renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
hukkin committed Dec 19, 2024
1 parent d9aa005 commit 3e29016
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 16 deletions.
7 changes: 7 additions & 0 deletions docs/users/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@
This log documents all Python API or CLI breaking backwards incompatible changes.
Note that there is currently no guarantee for a stable Markdown formatting style across versions.

## 0.7.21

- Fixed
- Circular import in plugins that import from `mdformat.renderer`.

## 0.7.20

**NOTE:** This release was yanked from PyPI.

- Deprecated
- `mdformat.codepoints.ASCII_WHITESPACE`.
CommonMark no longer defines this since v0.30.
Expand Down
15 changes: 14 additions & 1 deletion src/mdformat/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
import argparse
from collections.abc import Generator, Iterable, Mapping, Sequence
import contextlib
import functools
import logging
import os.path
from pathlib import Path
import shutil
import sys
import textwrap

import mdformat
from mdformat._conf import DEFAULT_OPTS, InvalidConfError, read_toml_opts
from mdformat._util import cached_textwrapper, detect_newline_type, is_md_equal
from mdformat._util import detect_newline_type, is_md_equal
import mdformat.plugins
import mdformat.renderer

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


@functools.lru_cache
def cached_textwrapper(width: int) -> textwrap.TextWrapper:
return textwrap.TextWrapper(
break_long_words=False,
break_on_hyphens=False,
width=width,
expand_tabs=False,
replace_whitespace=False,
)


def wrap_paragraphs(paragraphs: Iterable[str]) -> str:
"""Wrap and concatenate paragraphs.
Expand Down
13 changes: 0 additions & 13 deletions src/mdformat/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

from collections.abc import Iterable, Mapping
from contextlib import nullcontext
import functools
import re
import textwrap
from types import MappingProxyType
from typing import Any, Literal

Expand Down Expand Up @@ -126,14 +124,3 @@ def detect_newline_type(md: str, eol_setting: str) -> Literal["\n", "\r\n"]:
if eol_setting == "crlf":
return "\r\n"
return "\n"


@functools.lru_cache
def cached_textwrapper(width: int) -> textwrap.TextWrapper:
return textwrap.TextWrapper(
break_long_words=False,
break_on_hyphens=False,
width=width,
expand_tabs=False,
replace_whitespace=False,
)
16 changes: 14 additions & 2 deletions src/mdformat/renderer/_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
from collections import defaultdict
from collections.abc import Generator, Iterable, Mapping, MutableMapping
from contextlib import contextmanager
import functools
import logging
import re
import textwrap
from types import MappingProxyType
from typing import TYPE_CHECKING, Any, Literal, NamedTuple

from markdown_it.rules_block.html_block import HTML_SEQUENCES

from mdformat import codepoints
from mdformat._conf import DEFAULT_OPTS
from mdformat._util import cached_textwrapper
from mdformat.renderer._util import (
RE_CHAR_REFERENCE,
decimalify_leading,
Expand All @@ -27,10 +28,10 @@
longest_consecutive_sequence,
maybe_add_link_brackets,
)
from mdformat.renderer.typing import Postprocess, Render

if TYPE_CHECKING:
from mdformat.renderer import RenderTreeNode
from mdformat.renderer.typing import Postprocess, Render

LOGGER = logging.getLogger(__name__)

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


@functools.lru_cache
def cached_textwrapper(width: int) -> textwrap.TextWrapper:
return textwrap.TextWrapper(
break_long_words=False,
break_on_hyphens=False,
width=width,
expand_tabs=False,
replace_whitespace=False,
)


def _wrap(text: str, *, width: int | Literal["no"]) -> str:
"""Wrap text at locations pointed by `WRAP_POINT`s.
Expand Down

0 comments on commit 3e29016

Please sign in to comment.