Skip to content

Commit 3741bac

Browse files
committed
Revert "Uncap dependencies"
This reverts commit 9c00f7b.
1 parent 9c00f7b commit 3741bac

File tree

6 files changed

+60
-91
lines changed

6 files changed

+60
-91
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: CI
22

3-
"on":
3+
on:
44
push:
55
branches: [master]
66
tags:
@@ -26,15 +26,8 @@ jobs:
2626
runs-on: ${{ matrix.os }}
2727
strategy:
2828
matrix:
29-
python-version:
30-
- "3.10"
31-
- "3.11"
32-
- "3.12"
33-
- "3.13"
34-
- "3.14"
35-
os:
36-
- ubuntu-latest
37-
- windows-latest
29+
python-version: ['3.10', 3.11, 3.12, 3.13, 3.14]
30+
os: [ubuntu-latest, windows-latest]
3831

3932
steps:
4033
- uses: actions/checkout@v5

.pre-commit-config.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v6.0.0
3+
rev: v4.4.0
44
hooks:
55
- id: end-of-file-fixer
66
- id: mixed-line-ending
77
- id: trailing-whitespace
88
- id: check-yaml
99
- id: check-toml
1010
- repo: https://github.com/pre-commit/pygrep-hooks
11-
rev: v1.10.0
11+
rev: v1.9.0
1212
hooks:
1313
- id: python-check-blanket-noqa
1414
- repo: https://github.com/timothycrosley/isort
15-
rev: 7.0.0
15+
rev: 5.13.2
1616
hooks:
1717
- id: isort
1818
- repo: https://github.com/psf/black
19-
rev: 25.9.0
19+
rev: 22.12.0
2020
hooks:
2121
- id: black
2222
- repo: https://github.com/pycqa/flake8
23-
rev: 7.3.0
23+
rev: 6.0.0
2424
hooks:
2525
- id: flake8
2626
additional_dependencies:

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55

66
An [mdformat] plugin to read configuration from `pyproject.toml`.
77

8+
> ⚠️ WARNING: it has been detected that some native `mdformat` options like `end_of_line` or
9+
> `exclude` are currently being ignored when included in the `pyproject.toml` file. The issue is
10+
> being worked on right now. You can read more here in
11+
> [issue #4](https://github.com/csala/mdformat-pyproject/issues/4)
12+
813
## Install
914

1015
Install with:

mdformat_pyproject/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
"""An mdformat plugin for reading configuration from ``pyproject.toml`` files."""
1+
"""An mdformat plugin for..."""
22

3-
__version__ = "1.0.0"
3+
__version__ = "0.0.2"
44

55
from .plugin import RENDERERS, update_mdit # noqa: F401

mdformat_pyproject/plugin.py

Lines changed: 34 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,121 +1,84 @@
11
"""Main plugin module."""
22

3-
from __future__ import annotations
4-
3+
import pathlib
54
import sys
65
from functools import cache
7-
from pathlib import Path
6+
from typing import TYPE_CHECKING, MutableMapping, Optional, Sequence, Tuple, Union
87

98
import markdown_it
109
import mdformat
1110

12-
TYPE_CHECKING = False
1311
if TYPE_CHECKING:
14-
from collections.abc import MutableMapping, Sequence
15-
1612
from mdformat.renderer.typing import Render
1713

18-
_ConfigOptions = MutableMapping[str, int | str | Sequence[str]]
19-
20-
2114
if sys.version_info >= (3, 11):
2215
import tomllib
2316
else:
2417
import tomli as tomllib
2518

2619

27-
@cache
28-
def _search_config_file(search_path: Path) -> Path | None:
29-
"""Search the first ``.mdformat.toml`` or ``pyproject.toml`` file in the provided
30-
``search_path`` folder or its parents.
31-
32-
The search is done ascending through the folders tree until a ``.mdformat.toml`` or a
33-
``pyproject.toml`` file is found. If the root ``/`` is reached, ``None`` is returned.
20+
_ConfigOptions = MutableMapping[str, Union[int, str, Sequence[str]]]
3421

35-
``.mdformat.toml`` takes precedence over ``pyproject.toml`` if both are present in the
36-
same folder.
3722

38-
``pyproject.toml`` files without a ``[tool.mdformat]`` section are ignored.
23+
@cache
24+
def _find_pyproject_toml_path(search_path: pathlib.Path) -> Optional[pathlib.Path]:
25+
"""Find the pyproject.toml file that applies to the search path.
3926
40-
This behavior mimics the one from Ruff, as described in `issues#17
41-
<https://github.com/csala/mdformat-pyproject/issues/17>`_.
27+
The search is done ascending through the folders tree until a pyproject.toml
28+
file is found in the same folder. If the root '/' is reached, None is returned.
4229
"""
4330
if search_path.is_file():
4431
search_path = search_path.parent
4532

4633
for parent in (search_path, *search_path.parents):
47-
for filename in (".mdformat.toml", "pyproject.toml"):
48-
candidate = parent / filename
49-
if candidate.is_file():
50-
# If we found a pyproject.toml, only return it if it contains
51-
# a [tool.mdformat] section.
52-
if candidate.name == "pyproject.toml":
53-
options = _parse_pyproject(candidate)
54-
if options is None:
55-
continue
56-
57-
return candidate
34+
candidate = parent / "pyproject.toml"
35+
if candidate.is_file():
36+
return candidate
5837

5938
return None
6039

6140

6241
@cache
63-
def _parse_pyproject(pyproject_path: Path) -> _ConfigOptions | None:
64-
"""Extract and validate the mdformat options from the ``pyproject.toml`` file.
42+
def _parse_pyproject(pyproject_path: pathlib.Path) -> Optional[_ConfigOptions]:
43+
"""Extract and validate the mdformat options from the pyproject.toml file.
6544
66-
The options are searched inside a ``[tool.mdformat]`` section within the TOML file,
67-
and they are validated using the default functions from ``mdformat._conf``.
68-
69-
If no ``[tool.mdformat]`` section is found, ``None`` is returned.
45+
The options are searched inside a [tool.mdformat] key within the toml file,
46+
and they are validated using the default functions from `mdformat._conf`.
7047
"""
7148
with pyproject_path.open(mode="rb") as pyproject_file:
72-
try:
73-
content = tomllib.load(pyproject_file)
74-
except tomllib.TOMLDecodeError as e:
75-
raise mdformat._conf.InvalidConfError(f"Invalid TOML syntax: {e}")
49+
content = tomllib.load(pyproject_file)
7650

7751
options = content.get("tool", {}).get("mdformat")
78-
if options is None:
79-
return None
80-
81-
mdformat._conf._validate_keys(options, pyproject_path)
82-
mdformat._conf._validate_values(options, pyproject_path)
52+
if options is not None:
53+
mdformat._conf._validate_keys(options, pyproject_path)
54+
mdformat._conf._validate_values(options, pyproject_path)
8355

8456
return options
8557

8658

87-
_orig_read_toml_opts = mdformat._conf.read_toml_opts
88-
89-
9059
@cache
91-
def patched_read_toml_opts(conf_dir: Path) -> tuple[MutableMapping, Path | None]:
92-
"""Patched version of ``mdformat._conf.read_toml_opts``.
60+
def read_toml_opts(
61+
conf_dir: pathlib.Path,
62+
) -> Tuple[MutableMapping, Optional[pathlib.Path]]:
63+
"""Alternative read_toml_opts that reads from pyproject.toml instead of .mdformat.toml.
9364
94-
Tries to read options from ``pyproject.toml`` first before falling back to
95-
``.mdformat.toml``.
65+
Notice that if `.mdformat.toml` exists it is ignored.
9666
"""
97-
config_file = _search_config_file(conf_dir)
98-
99-
if config_file:
100-
# We found a .mdformat.toml, use the original function directly.
101-
if config_file.name == ".mdformat.toml":
102-
return _orig_read_toml_opts(config_file.parent)
103-
104-
# Otherwise, we found a pyproject.toml, try to parse it.
105-
options = _parse_pyproject(config_file)
106-
if options:
107-
return options, config_file
67+
pyproject_path = _find_pyproject_toml_path(conf_dir)
68+
if pyproject_path:
69+
pyproject_opts = _parse_pyproject(pyproject_path)
70+
else:
71+
pyproject_opts = {}
10872

109-
# No config file found, return empty options.
110-
return {}, None
73+
return pyproject_opts, pyproject_path
11174

11275

11376
def update_mdit(mdit: markdown_it.MarkdownIt) -> None:
114-
"""No-op, since this plugin only monkey patches and does not modify ``mdit``."""
77+
"""No-op, since this plugin only monkey patches and does not modify mdit."""
11578
pass
11679

11780

118-
RENDERERS: MutableMapping[str, Render] = {}
81+
RENDERERS: MutableMapping[str, "Render"] = {}
11982

120-
# Monkey patch mdformat._conf to use our own read_toml_opts version.
121-
mdformat._conf.read_toml_opts = patched_read_toml_opts
83+
# Monkey patch mdformat._conf to use our own read_toml_opts version
84+
mdformat._conf.read_toml_opts = read_toml_opts

pyproject.toml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ build-backend = "flit_core.buildapi"
44

55
[project]
66
name = "mdformat_pyproject"
7-
authors = [{ name = "Carles Sala", email = "[email protected]" }]
7+
authors = [
8+
{ name = "Carles Sala", email = "[email protected]" },
9+
]
810
readme = "README.md"
911
classifiers = [
1012
"Intended Audience :: Developers",
@@ -18,7 +20,11 @@ dependencies = ["mdformat >= 1.0.0", "tomli >= 2.0; python_version < '3.11'"]
1820
dynamic = ["version", "description"]
1921

2022
[project.optional-dependencies]
21-
test = ["pytest >= 6.0", "coverage", "pytest-cov"]
23+
test = [
24+
"pytest~=6.0",
25+
"coverage",
26+
"pytest-cov",
27+
]
2228
dev = ["pre-commit"]
2329

2430
[project.urls]
@@ -40,7 +46,9 @@ number = true
4046
exclude = [".tox/**", ".venv/**"]
4147

4248
[tool.coverage.report]
43-
exclude_lines = ['^ *import ']
49+
exclude_lines = [
50+
'^ *import '
51+
]
4452

4553
[tool.black]
4654
line_length = 99

0 commit comments

Comments
 (0)