From 6da73762b036d7cd9b2460b5e40c41858bf15dc9 Mon Sep 17 00:00:00 2001 From: Kevin Deldycke Date: Mon, 27 Oct 2025 20:47:17 +0400 Subject: [PATCH 1/4] Makes `.mdformat.toml` takes precedence Closes #17 --- .mdformat.toml | 5 +- mdformat_pyproject/plugin.py | 104 +++++++++++++++++++++++------------ tests/test_plugin.py | 59 ++++++++++---------- 3 files changed, 101 insertions(+), 67 deletions(-) diff --git a/.mdformat.toml b/.mdformat.toml index 1cdb3e2..3243e0b 100644 --- a/.mdformat.toml +++ b/.mdformat.toml @@ -1,2 +1,3 @@ -wrap = 80 -number = false +wrap = 99 +number = true +exclude = [".tox/**", ".venv/**"] diff --git a/mdformat_pyproject/plugin.py b/mdformat_pyproject/plugin.py index 5ad664c..ad02969 100644 --- a/mdformat_pyproject/plugin.py +++ b/mdformat_pyproject/plugin.py @@ -8,6 +8,7 @@ import markdown_it import mdformat +from mdformat._cli import print_paragraphs TYPE_CHECKING = False if TYPE_CHECKING: @@ -23,63 +24,94 @@ import tomli as tomllib -@cache -def _find_pyproject_toml_path(search_path: Path) -> Path | None: - """Find the pyproject.toml file that applies to the search path. - - The search is done ascending through the folders tree until a pyproject.toml - file is found in the same folder. If the root '/' is reached, None is returned. - """ - if search_path.is_file(): - search_path = search_path.parent - - for parent in (search_path, *search_path.parents): - candidate = parent / "pyproject.toml" - if candidate.is_file(): - return candidate - - return None - - @cache def _parse_pyproject(pyproject_path: Path) -> _ConfigOptions | None: - """Extract and validate the mdformat options from the pyproject.toml file. + """Extract and validate the mdformat options from the ``pyproject.toml`` file. + + The options are searched inside a ``[tool.mdformat]`` section within the TOML file, + and they are validated using the default functions from ``mdformat._conf``. - The options are searched inside a [tool.mdformat] key within the toml file, - and they are validated using the default functions from `mdformat._conf`. + If no ``[tool.mdformat]`` section is found, ``None`` is returned. """ with pyproject_path.open(mode="rb") as pyproject_file: - content = tomllib.load(pyproject_file) + try: + content = tomllib.load(pyproject_file) + except tomllib.TOMLDecodeError as e: + raise mdformat._conf.InvalidConfError(f"Invalid TOML syntax: {e}") options = content.get("tool", {}).get("mdformat") - if options is not None: - mdformat._conf._validate_keys(options, pyproject_path) - mdformat._conf._validate_values(options, pyproject_path) + if options is None: + return None + + mdformat._conf._validate_keys(options, pyproject_path) + mdformat._conf._validate_values(options, pyproject_path) return options +_orig_read_toml_opts = mdformat._conf.read_toml_opts + + @cache -def read_toml_opts(conf_dir: Path) -> tuple[dict, Path | None]: - """Alternative read_toml_opts that reads from pyproject.toml instead of .mdformat.toml. +def patched_read_toml_opts(search_path: Path) -> tuple[dict, Path | None]: + """Patched version of ``mdformat._conf.read_toml_opts``. + + Search the first ``.mdformat.toml`` or ``pyproject.toml`` file in the provided + ``search_path`` folder or its parents. + + The search is done ascending through the folders tree until a ``.mdformat.toml`` or a + ``pyproject.toml`` file is found. If the root ``/`` is reached, ``None`` is returned. - Notice that if `.mdformat.toml` exists it is ignored. + ``.mdformat.toml`` takes precedence over ``pyproject.toml`` if both are present in the + same folder. In that case, a warning is logged to inform the user that the + ``pyproject.toml`` file has been ignored. + + ``pyproject.toml`` files without a ``[tool.mdformat]`` section are ignored. + + This behavior mimics the one from Ruff, as described in `issues#17 + `_. """ - pyproject_path = _find_pyproject_toml_path(conf_dir) - if pyproject_path: - pyproject_opts = _parse_pyproject(pyproject_path) - else: - pyproject_opts = {} + if search_path.is_file(): + search_path = search_path.parent - return pyproject_opts, pyproject_path + for parent in (search_path, *search_path.parents): + # Try to find a pyproject.toml file first, with a [tool.mdformat] section. + pyproject_options = None + pyproject_path = parent / "pyproject.toml" + if pyproject_path.is_file(): + pyproject_options = _parse_pyproject(pyproject_path) + + # Read options from .mdformat.toml if present. + mdformat_path = parent / ".mdformat.toml" + if mdformat_path.is_file(): + # If both pyproject.toml and .mdformat.toml are present, the latter takes + # precedence, but we warn the user that pyproject.toml is being ignored. + if pyproject_options is not None: + print_paragraphs( + ( + f"Warning: ignoring mdformat options from {pyproject_path} " + f"since {mdformat_path} is present.", + ) + ) + + # Return options from .mdformat.toml using the original function, even if + # they are empty. + return _orig_read_toml_opts(mdformat_path.parent) + + # Return options from pyproject.toml if .mdformat.toml is not present. + elif pyproject_options is not None: + return pyproject_options, pyproject_path + + # No config file found, return empty options. + return {}, None def update_mdit(mdit: markdown_it.MarkdownIt) -> None: - """No-op, since this plugin only monkey patches and does not modify mdit.""" + """No-op, since this plugin only monkey patches and does not modify ``mdit``.""" pass RENDERERS: dict[str, Render] = {} # Monkey patch mdformat._conf to use our own read_toml_opts version -mdformat._conf.read_toml_opts = read_toml_opts +mdformat._conf.read_toml_opts = patched_read_toml_opts diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 1a2e911..794553d 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -12,6 +12,7 @@ THIS_MODULE_PATH = pathlib.Path(__file__) THIS_MODULE_PARENT = THIS_MODULE_PATH.parent PYPROJECT_PATH = THIS_MODULE_PARENT.parent / "pyproject.toml" +MDFORMAT_TOML_PATH = THIS_MODULE_PARENT.parent / ".mdformat.toml" def setup_function(): @@ -30,74 +31,74 @@ def nonexistent_path(): return pathlib.Path(fake_parent) / "path" / "to" / "a" / "file.md" -def test__find_pyproject_toml_path_directory_inside_project(): - """Test _find_pyproject_toml_path when search_path points at a directory within the project. +def test_search_config_directory_inside_project(): + """Test patched_read_toml_opts when search_path points at a directory within the project. Input: - search_path=THIS_MODULE_PATH -> directory is inside the project Expected output: - - pyproject.toml of this project. + - .mdformat.toml of this project. """ - returned = plugin._find_pyproject_toml_path(THIS_MODULE_PARENT) - assert returned == PYPROJECT_PATH + options, conf_path = plugin.patched_read_toml_opts(THIS_MODULE_PARENT) + assert conf_path == MDFORMAT_TOML_PATH -def test__find_pyproject_toml_path_directory_outside_project(nonexistent_path): - """Test _find_pyproject_toml_path when search_path points at a directory within the project. +def test_search_config_directory_outside_project(nonexistent_path): + """Test patched_read_toml_opts when search_path points at a directory within the project. Input: - search_path=nonexistent_path.parent -> directory is outside the project Expected output: - - pyproject.toml of this project. + - None """ - returned = plugin._find_pyproject_toml_path(nonexistent_path.parent) - assert returned is None + options, conf_path = plugin.patched_read_toml_opts(nonexistent_path.parent) + assert conf_path is None -def test__find_pyproject_toml_path_file_inside_project(): - """Test _find_pyproject_toml_path when search_path points at a file within the project. +def test_search_config_file_inside_project(): + """Test patched_read_toml_opts when search_path points at a file within the project. Input: - search_path="__file__" -> file is inside the project Expected output: - - pyproject.toml of this project. + - .mdformat.toml of this project. """ - returned = plugin._find_pyproject_toml_path(THIS_MODULE_PATH) - assert returned == PYPROJECT_PATH + options, conf_path = plugin.patched_read_toml_opts(THIS_MODULE_PATH) + assert conf_path == MDFORMAT_TOML_PATH -def test__find_pyproject_toml_path_file_outside_of_project(nonexistent_path): - """Test _find_pyproject_toml_path when search_path points at a file outside of a project. +def test_search_config_file_outside_of_project(nonexistent_path): + """Test patched_read_toml_opts when search_path points at a file outside of a project. Input: - search_path="/fake/folder/path" -> A madeup path to an nonexistent folder. Expected output: - None """ - returned = plugin._find_pyproject_toml_path(nonexistent_path) - assert returned is None + options, conf_path = plugin.patched_read_toml_opts(nonexistent_path) + assert conf_path is None -def test_read_toml_opts_with_pyproject(): - """Test read_toml_opts when there is a pyproject.toml file. +def test_patched_read_toml_opts_with_pyproject(): + """Test patched_read_toml_opts when there is a pyproject.toml and a .mdformat.toml file. Input: - conf_dir pointing to this module's folder Expected Output: - Tuple containing: - - Dict with the mdformat options from pyproject.toml - - Path to the pyproject.toml file + - Dict with the mdformat options from .mdformat.toml, which takes precedence + - Path to the .mdformat.toml file """ # run - opts, path = plugin.read_toml_opts(THIS_MODULE_PATH) + options, conf_path = plugin.patched_read_toml_opts(THIS_MODULE_PATH) # assert - assert opts == {"wrap": 99, "number": True, "exclude": [".tox/**", ".venv/**"]} - assert path == PYPROJECT_PATH + assert options == {"wrap": 99, "number": True, "exclude": [".tox/**", ".venv/**"]} + assert conf_path == MDFORMAT_TOML_PATH -def test_read_toml_opts_without_pyproject(nonexistent_path): - """Test read_toml_opts when there is no pyproject.toml file. +def test_patched_read_toml_opts_without_pyproject(nonexistent_path): + """Test read_toml_opts when there is no pyproject.toml or .mdformat.toml file. Input: - conf_dir pointing to a non-existent folder @@ -107,7 +108,7 @@ def test_read_toml_opts_without_pyproject(nonexistent_path): - None """ # run - opts, path = plugin.read_toml_opts(nonexistent_path) + opts, path = plugin.patched_read_toml_opts(nonexistent_path) # assert assert opts == {} From 3f0f3845c99925230e1884bc32e95678ad4924a6 Mon Sep 17 00:00:00 2001 From: Carles Sala Date: Wed, 29 Oct 2025 12:02:55 +0100 Subject: [PATCH 2/4] Improve tests to cover all scenarios --- .mdformat.toml | 3 - mdformat_pyproject/plugin.py | 2 +- tests/.mdformat.toml | 2 + tests/test_plugin.py | 164 +++++++++++++++++++++++++---------- 4 files changed, 123 insertions(+), 48 deletions(-) delete mode 100644 .mdformat.toml create mode 100644 tests/.mdformat.toml diff --git a/.mdformat.toml b/.mdformat.toml deleted file mode 100644 index 3243e0b..0000000 --- a/.mdformat.toml +++ /dev/null @@ -1,3 +0,0 @@ -wrap = 99 -number = true -exclude = [".tox/**", ".venv/**"] diff --git a/mdformat_pyproject/plugin.py b/mdformat_pyproject/plugin.py index ad02969..770e6e6 100644 --- a/mdformat_pyproject/plugin.py +++ b/mdformat_pyproject/plugin.py @@ -114,4 +114,4 @@ def update_mdit(mdit: markdown_it.MarkdownIt) -> None: RENDERERS: dict[str, Render] = {} # Monkey patch mdformat._conf to use our own read_toml_opts version -mdformat._conf.read_toml_opts = patched_read_toml_opts +mdformat._cli.read_toml_opts = patched_read_toml_opts diff --git a/tests/.mdformat.toml b/tests/.mdformat.toml new file mode 100644 index 0000000..1cdb3e2 --- /dev/null +++ b/tests/.mdformat.toml @@ -0,0 +1,2 @@ +wrap = 80 +number = false diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 794553d..3dea4f2 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -2,7 +2,7 @@ import copy import pathlib -import unittest.mock +from unittest import mock import markdown_it import pytest @@ -12,7 +12,9 @@ THIS_MODULE_PATH = pathlib.Path(__file__) THIS_MODULE_PARENT = THIS_MODULE_PATH.parent PYPROJECT_PATH = THIS_MODULE_PARENT.parent / "pyproject.toml" -MDFORMAT_TOML_PATH = THIS_MODULE_PARENT.parent / ".mdformat.toml" +PYPROJECT_OPTIONS = {"wrap": 99, "number": True, "exclude": [".tox/**", ".venv/**"]} +MDFORMAT_TOML_PATH = THIS_MODULE_PARENT / ".mdformat.toml" +MDFORMAT_TOML_OPTIONS = {"wrap": 80, "number": False} def setup_function(): @@ -31,88 +33,162 @@ def nonexistent_path(): return pathlib.Path(fake_parent) / "path" / "to" / "a" / "file.md" -def test_search_config_directory_inside_project(): - """Test patched_read_toml_opts when search_path points at a directory within the project. +def test__parse_pyproject_invalid_toml(tmp_path): + """Test _parse_pyproject when the given file is not a valid toml. Input: - - search_path=THIS_MODULE_PATH -> directory is inside the project - Expected output: - - .mdformat.toml of this project. + - pyproject_path pointing to an invalid toml file + Expected outcome: + - raise an mdformat._conf.InvalidConfError """ - options, conf_path = plugin.patched_read_toml_opts(THIS_MODULE_PARENT) - assert conf_path == MDFORMAT_TOML_PATH + invalid_pyproject_path = tmp_path / "pyproject.toml" + invalid_pyproject_path.write_text("This is not a valid toml") + with pytest.raises(plugin.mdformat._conf.InvalidConfError): + plugin._parse_pyproject(invalid_pyproject_path) -def test_search_config_directory_outside_project(nonexistent_path): - """Test patched_read_toml_opts when search_path points at a directory within the project. +def test__parse_pyproject_no_options(tmp_path): + """Test _parse_pyproject when the given file has no tool.mdformat section. Input: - - search_path=nonexistent_path.parent -> directory is outside the project + - pyproject_path pointing at a pyproject.toml with no mdformat options. Expected output: - None """ - options, conf_path = plugin.patched_read_toml_opts(nonexistent_path.parent) - assert conf_path is None + pyproject_path = tmp_path / "pyproject.toml" + pyproject_path.write_text('name = "mdformat-pyproject-testing"') + options = plugin._parse_pyproject(pyproject_path) + assert options is None -def test_search_config_file_inside_project(): - """Test patched_read_toml_opts when search_path points at a file within the project. +@mock.patch("mdformat_pyproject.plugin.mdformat._conf") +def test__parse_pyproject_with_options(_conf_patch): + """Test _parse_pyproject when the given file has tool.mdformat options. Input: - - search_path="__file__" -> file is inside the project + - pyproject_path pointing at this project's pyproject.toml Expected output: - - .mdformat.toml of this project. + - Current options + Expected outcome: + - mdformat._conf._validate_keys has been called + - mdformat._conf._validate_values has been called """ - options, conf_path = plugin.patched_read_toml_opts(THIS_MODULE_PATH) - assert conf_path == MDFORMAT_TOML_PATH + options = plugin._parse_pyproject(PYPROJECT_PATH) + assert options == PYPROJECT_OPTIONS + _conf_patch._validate_keys.assert_called_once_with(PYPROJECT_OPTIONS, PYPROJECT_PATH) + _conf_patch._validate_values.assert_called_once_with(PYPROJECT_OPTIONS, PYPROJECT_PATH) -def test_search_config_file_outside_of_project(nonexistent_path): - """Test patched_read_toml_opts when search_path points at a file outside of a project. +def test_patched_read_toml_opts_without_configuration(nonexistent_path): + """Test read_toml_opts when there is no pyproject.toml or .mdformat.toml file. Input: - - search_path="/fake/folder/path" -> A madeup path to an nonexistent folder. - Expected output: - - None + - search_path pointing to a non-existent folder + Expected Output: + - Tuple containing: + - Empty dict + - None """ - options, conf_path = plugin.patched_read_toml_opts(nonexistent_path) - assert conf_path is None + # run + options, path = plugin.patched_read_toml_opts(nonexistent_path) + + # assert + assert options == {} + assert path is None -def test_patched_read_toml_opts_with_pyproject(): - """Test patched_read_toml_opts when there is a pyproject.toml and a .mdformat.toml file. +def test_patched_read_toml_opts_with_only_mdformat(): + """Test read_toml_opts when there is only an .mdformat.toml file. Input: - - conf_dir pointing to this module's folder + - search_path pointing to the current file, which has an .mdformat.toml alongside it Expected Output: - Tuple containing: - - Dict with the mdformat options from .mdformat.toml, which takes precedence - - Path to the .mdformat.toml file + - mdformat options + - mdformat path """ # run - options, conf_path = plugin.patched_read_toml_opts(THIS_MODULE_PATH) + options, path = plugin.patched_read_toml_opts(THIS_MODULE_PATH) # assert - assert options == {"wrap": 99, "number": True, "exclude": [".tox/**", ".venv/**"]} - assert conf_path == MDFORMAT_TOML_PATH + assert options == MDFORMAT_TOML_OPTIONS + assert path == MDFORMAT_TOML_PATH -def test_patched_read_toml_opts_without_pyproject(nonexistent_path): - """Test read_toml_opts when there is no pyproject.toml or .mdformat.toml file. +def test_patched_read_toml_opts_with_only_pyproject(): + """Test read_toml_opts when there is only a .pyproject.toml file. Input: - - conf_dir pointing to a non-existent folder + - search_path pointing to a folder with a pyproject.toml Expected Output: - Tuple containing: - - Empty dict - - None + - pyproject options + - pyproject path """ # run - opts, path = plugin.patched_read_toml_opts(nonexistent_path) + options, path = plugin.patched_read_toml_opts(PYPROJECT_PATH.parent) # assert - assert opts == {} - assert path is None + assert options == PYPROJECT_OPTIONS + assert path == PYPROJECT_PATH + + +@mock.patch("mdformat_pyproject.plugin.print_paragraphs") +def test_patched_read_toml_opts_with_both_no_mdformat_options(pp_patch, tmp_path): + """Test read_toml_opts when both files exist, but pyproject has no options. + + Input: + - search_path pointing to a folder with both pyproject.toml and .mdformat.toml, but + pyproject.toml has no mdformat options. + Expected Output: + - Tuple containing: + - mdformat options + - mdformat path + Expected Outcome: + - print_paragraphs has not been called + """ + # setup + mdformat_toml_path = tmp_path / ".mdformat.toml" + mdformat_toml_path.write_text(MDFORMAT_TOML_PATH.read_text()) + pyproject_path = tmp_path / "pyproject.toml" + pyproject_path.write_text('name = "mdformat-pyproject-testing"') + + # run + options, path = plugin.patched_read_toml_opts(tmp_path) + + # assert + assert options == MDFORMAT_TOML_OPTIONS + assert path == mdformat_toml_path + pp_patch.assert_not_called() + + +@mock.patch("mdformat_pyproject.plugin.print_paragraphs") +def test_patched_read_toml_opts_with_both(pp_patch, tmp_path): + """Test read_toml_opts when both files exist and have options. + + Input: + - search_path pointing to a folder with both pyproject.toml and .mdformat.toml, both with + options. + Expected Output: + - Tuple containing: + - mdformat options + - mdformat path + Expected Outcome: + - print_paragraphs has been called to warn the user + """ + # setup + mdformat_toml_path = tmp_path / ".mdformat.toml" + mdformat_toml_path.write_text(MDFORMAT_TOML_PATH.read_text()) + pyproject_path = tmp_path / "pyproject.toml" + pyproject_path.write_text(PYPROJECT_PATH.read_text()) + + # run + options, path = plugin.patched_read_toml_opts(tmp_path) + + # assert + assert options == MDFORMAT_TOML_OPTIONS + assert path == mdformat_toml_path + pp_patch.assert_called() def test_update_mdit_no_config(): @@ -132,7 +208,7 @@ def test_update_mdit_no_config(): "paths": [filename], "wrap": 80, } - mdit = unittest.mock.Mock(spec_set=markdown_it.MarkdownIt()) + mdit = mock.Mock(spec_set=markdown_it.MarkdownIt()) mdit.options = {"mdformat": mdformat_options} expected_options = copy.deepcopy(mdformat_options) From 462a890a413e31e231cf084f9c6f640e8541b9c9 Mon Sep 17 00:00:00 2001 From: Carles Sala Date: Wed, 29 Oct 2025 12:15:51 +0100 Subject: [PATCH 3/4] Use 2 separate files to test pyproject.toml and .mdproject.toml via pre-commit --- .pre-commit-config.yaml | 2 +- .pre-commit-test.yaml | 2 +- tests/{ => mdformat_toml}/.mdformat.toml | 0 tests/mdformat_toml/pre-commit-test.md | 16 ++++++++++++++++ tests/pre-commit-test.md | 5 ++--- tests/test_plugin.py | 6 +++--- 6 files changed, 23 insertions(+), 8 deletions(-) rename tests/{ => mdformat_toml}/.mdformat.toml (100%) create mode 100644 tests/mdformat_toml/pre-commit-test.md diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 620deb7..4fd7ab9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -29,7 +29,7 @@ repos: - flake8-builtins - flake8-comprehensions - repo: https://github.com/hukkin/mdformat - rev: 0.7.21 + rev: 1.0.0 hooks: - id: mdformat additional_dependencies: diff --git a/.pre-commit-test.yaml b/.pre-commit-test.yaml index e06ffb1..683f0b7 100644 --- a/.pre-commit-test.yaml +++ b/.pre-commit-test.yaml @@ -4,6 +4,6 @@ repos: - id: mdformat name: mdformat entry: mdformat - files: "tests/pre-commit-test.md" + files: "**/pre-commit-test.md" types: [markdown] language: system diff --git a/tests/.mdformat.toml b/tests/mdformat_toml/.mdformat.toml similarity index 100% rename from tests/.mdformat.toml rename to tests/mdformat_toml/.mdformat.toml diff --git a/tests/mdformat_toml/pre-commit-test.md b/tests/mdformat_toml/pre-commit-test.md new file mode 100644 index 0000000..4ede8c9 --- /dev/null +++ b/tests/mdformat_toml/pre-commit-test.md @@ -0,0 +1,16 @@ +# Test file + +This repository contains 2 separate configuration files with contradictory +settings: + +1. The `tests/mdformat_toml/.mdformat.toml`, which defines a `wrap` length of 80 + and sets `number` to `false`, meaning that numbered lists would be written + starting with `1.` on all the rows. +1. The `pyproject.toml`, which should be used after the `mdformat-pyproject` + plugin is installed, and which defines wrap length of 99 and sets `number` to + `true`, meaning that numbered lists would be written starting with + consecutive numbers. + +This file is written according to the rules specified in the `.mdformat.toml` +file placed alongside it, and serves as a valid test to see if the plugin is +working as expected and honoring `.mdformat.toml` when found. diff --git a/tests/pre-commit-test.md b/tests/pre-commit-test.md index 6d1d9da..2ed3f69 100644 --- a/tests/pre-commit-test.md +++ b/tests/pre-commit-test.md @@ -2,9 +2,8 @@ This repository contains 2 separate configuration files with contradictory settings: -1. The `.mdformat.toml`, which should be used by default by `mdformat`, and which defines a `wrap` - length of 80 and sets `number` to `false`, meaning that numbered lists would be written starting - with `1.` on all the rows. +1. The `tests/mdformat_toml/.mdformat.toml`, which defines a `wrap` length of 80 and sets `number` + to `false`, meaning that numbered lists would be written starting with `1.` on all the rows. 2. The `pyproject.toml`, which should be used after the `mdformat-pyproject` plugin is installed, and which defines wrap length of 99 and sets `number` to `true`, meaning that numbered lists would be written starting with consecutive numbers. diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 3dea4f2..8566c41 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -13,7 +13,7 @@ THIS_MODULE_PARENT = THIS_MODULE_PATH.parent PYPROJECT_PATH = THIS_MODULE_PARENT.parent / "pyproject.toml" PYPROJECT_OPTIONS = {"wrap": 99, "number": True, "exclude": [".tox/**", ".venv/**"]} -MDFORMAT_TOML_PATH = THIS_MODULE_PARENT / ".mdformat.toml" +MDFORMAT_TOML_PATH = THIS_MODULE_PARENT / "mdformat_toml" / ".mdformat.toml" MDFORMAT_TOML_OPTIONS = {"wrap": 80, "number": False} @@ -101,14 +101,14 @@ def test_patched_read_toml_opts_with_only_mdformat(): """Test read_toml_opts when there is only an .mdformat.toml file. Input: - - search_path pointing to the current file, which has an .mdformat.toml alongside it + - search_path pointing to the folder that contains the .mdformat.toml Expected Output: - Tuple containing: - mdformat options - mdformat path """ # run - options, path = plugin.patched_read_toml_opts(THIS_MODULE_PATH) + options, path = plugin.patched_read_toml_opts(MDFORMAT_TOML_PATH.parent) # assert assert options == MDFORMAT_TOML_OPTIONS From 1750b85fc877494b3cea6b91bd13fab3d0932337 Mon Sep 17 00:00:00 2001 From: Carles Sala Date: Wed, 29 Oct 2025 13:13:25 +0100 Subject: [PATCH 4/4] Fix pre-commit-test regex --- .pre-commit-test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-test.yaml b/.pre-commit-test.yaml index 683f0b7..402d81a 100644 --- a/.pre-commit-test.yaml +++ b/.pre-commit-test.yaml @@ -4,6 +4,6 @@ repos: - id: mdformat name: mdformat entry: mdformat - files: "**/pre-commit-test.md" + files: ".*/pre-commit-test.md" types: [markdown] language: system