Skip to content

Commit

Permalink
🔧 Use new API to fix DeprecationWarning
Browse files Browse the repository at this point in the history
  • Loading branch information
hukkin committed Nov 18, 2024
1 parent 01dbde1 commit db15964
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
2 changes: 1 addition & 1 deletion mdformat_tables/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
from .plugin import ( # noqa: F401
POSTPROCESSORS,
RENDERERS,
add_cli_options,
add_cli_argument_group,
update_mdit,
)
16 changes: 12 additions & 4 deletions mdformat_tables/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
from wcwidth import wcswidth


def add_cli_options(parser: argparse.ArgumentParser) -> None:
"""Add options to the mdformat CLI, to be stored in `mdit.options["mdformat"]`."""
parser.add_argument(
def add_cli_argument_group(group: argparse._ArgumentGroup) -> None:
"""Add options to the mdformat CLI, to be stored in
`mdit.options["mdformat"]["plugin"]["tables"]`."""
group.add_argument(
"--compact-tables",
action="store_true",
help="If specified, do not add padding to table cells.",
Expand Down Expand Up @@ -70,7 +71,14 @@ def format_delimiter_cell(index: int, align: str) -> str:

def _render_table(node: RenderTreeNode, context: RenderContext) -> str:
"""Render a `RenderTreeNode` of type "table"."""
compact_tables = context.options["mdformat"].get("compact_tables", False)
compact_tables_from_cli_or_toml = (
context.options["mdformat"]
.get("plugin", {})
.get("tables", {})
.get("compact_tables")
)
compact_tables_from_api = context.options["mdformat"].get("compact_tables")
compact_tables = compact_tables_from_cli_or_toml or compact_tables_from_api
# gather rendered cell content into row * column array
rows: List[List[str]] = []
align: List[List[str]] = []
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ classifiers = [
keywords = "mdformat,markdown,markdown-it"

requires-python=">=3.7.0"
requires=["mdformat>=0.7.5,<0.8.0", "wcwidth>=0.2.13"]
requires=["mdformat>=0.7.19,<0.8.0", "wcwidth>=0.2.13"]

[tool.flit.metadata.requires-extra]
test = [
Expand Down
27 changes: 25 additions & 2 deletions tests/test_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from markdown_it.utils import read_fixture_file
import mdformat
import mdformat._cli
import pytest

FIXTURE_PATH = Path(__file__).parent / "fixtures.md"
Expand All @@ -11,22 +12,44 @@
@pytest.mark.parametrize(
"line,title,text,expected", fixtures, ids=[f[1] for f in fixtures]
)
def test_fixtures(line, title, text, expected):
def test_fixtures__api(line, title, text, expected):
output = mdformat.text(text, extensions={"tables"})
print(output)
assert output.rstrip() == expected.rstrip(), output


@pytest.mark.parametrize(
"line,title,text,expected", fixtures, ids=[f[1] for f in fixtures]
)
def test_fixtures__cli(line, title, text, expected, tmp_path):
file_path = tmp_path / "test_markdown.md"
file_path.write_text(text, encoding="utf-8")
assert mdformat._cli.run([str(file_path)]) == 0
md_new = file_path.read_text()
assert md_new == expected


FIXTURES_COMPACT_PATH = Path(__file__).parent / "fixtures-compact.md"
fixtures_compact = read_fixture_file(FIXTURES_COMPACT_PATH)


@pytest.mark.parametrize(
"line,title,text,expected", fixtures_compact, ids=[f[1] for f in fixtures_compact]
)
def test_fixtures_compact(line, title, text, expected):
def test_fixtures_compact__api(line, title, text, expected):
output = mdformat.text(
text, extensions={"tables"}, options={"compact_tables": True}
)
print(output)
assert output.rstrip() == expected.rstrip(), output


@pytest.mark.parametrize(
"line,title,text,expected", fixtures_compact, ids=[f[1] for f in fixtures_compact]
)
def test_fixtures_compact__cli(line, title, text, expected, tmp_path):
file_path = tmp_path / "test_markdown.md"
file_path.write_text(text, encoding="utf-8")
assert mdformat._cli.run([str(file_path), "--compact-tables"]) == 0
md_new = file_path.read_text()
assert md_new == expected

0 comments on commit db15964

Please sign in to comment.