executablebooks / mdformat

CommonMark compliant Markdown formatter
https://mdformat.rtfd.io
MIT License
440 stars 46 forks source link

Reading configuration from pyproject.toml #356

Closed jspaezp closed 1 month ago

jspaezp commented 2 years ago

Context

It has become increasingly adopted the option to store the configuration of many tools inside the pyproject.toml file.

example for black: https://ichard26-testblackdocs.readthedocs.io/en/refactor_docs/pyproject_toml.html

It would be amazing if mdformat could read it as well. And since mdformat already supports toml format configurations, it would be trivial to implement looking for the configuration in the tool.mdformat section of one's pyproject.toml file

# .mdformat.toml
#
# This file shows the default values and is equivalent to having
# no configuration file at all. Change the values for non-default
# behavior.
#
wrap = "keep"       # possible values: {"keep", "no", INTEGER}
number = false      # possible values: {false, true}
end_of_line = "lf"  # possible values: {"lf", "crlf", "keep"}
# pyproject.toml

#.......
[tool.mdformat]
wrap = "keep"       # possible values: {"keep", "no", INTEGER}
number = false      # possible values: {false, true}
end_of_line = "lf"  # possible values: {"lf", "crlf", "keep"}

Proposal

I think an approach would be ...

modify this function: https://github.com/executablebooks/mdformat/blob/2b3145d43909b15cbf84bb2c16705d24cecf177a/src/mdformat/_conf.py#L26-L44

so that:

Tasks and updates

welcome[bot] commented 2 years ago

Thanks for opening your first issue here! Engagement like this is essential for open source projects! :hugs:
If you haven't done so already, check out EBP's Code of Conduct. Also, please try to follow the issue template as it helps other community members to contribute more effectively.
If your issue is a feature request, others may react to it, to raise its prominence (see Feature Voting).
Welcome to the EBP community! :tada:

hukkin commented 2 years ago

Thanks for the issue!

I'm inclined to reject this to reduce configuration parsing complexity and to not set a bad precedent for what will be merged in the future.

pyproject.toml is a Python specific file so I really like that Python specific tools (pytest, black, tox, mypy etc.) support it. Mdformat is a programming language agnostic tool, however, so I don't think it should support a Python specific file.

jspaezp commented 2 years ago

Thanks for replying!

I think we can leave this open and see if it gets some traction. I can definitely understand not wanting to add more stuff due to the "maintainance tax" down the road and I understand the rationale behind it.

Implementation right now seems easy so if you need a PR just mention me and I could give it a go. Best!

csala commented 1 year ago

Definitely in favor of adding support for .pyproject.toml, but @hukkin has a point in this comment about mdformat not being strictly focused on Python projects.

What about adding a --config-file option instead? Then mdformat is not really adhering to any standard in particular other than the toml format, and users are still able to add their settings in the pyproject.toml if it exists, but also in any other configuration file that is parseable as toml (like setup.cfg or any other .ini file).

csala commented 1 year ago

I created this plugin which covers the request of this issue.

hukkin commented 1 month ago

I'm rejecting this, please see https://github.com/executablebooks/mdformat/issues/356#issuecomment-1246596603

csala's plugin exists for those who need this feature https://pypi.org/project/mdformat_pyproject/