Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: circular import in plugins that import from mdformat.renderer #502

Merged
merged 1 commit into from
Dec 19, 2024
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
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
Loading