mdformat icon indicating copy to clipboard operation
mdformat copied to clipboard

Reading configuration from pyproject.toml

Open jspaezp opened this issue 3 years ago • 5 comments

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:

  • it first looks for the .mdformat.toml
    • if found use it
  • if it is not found, look for pyproject.toml
    • if found, look for a tool.mdformat section
      • if found use that as if it was the contents of .mdformat.toml

LMK what you think, I could make it a PR later in the week

Tasks and updates

  • [ ] implement changes
  • [ ] add unit testing
  • [ ] add documentation

jspaezp avatar Sep 14 '22 02:09 jspaezp

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:

welcome[bot] avatar Sep 14 '22 02:09 welcome[bot]

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.

hukkin avatar Sep 14 '22 10:09 hukkin

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!

jspaezp avatar Sep 15 '22 00:09 jspaezp

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 avatar Dec 30 '22 10:12 csala

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

csala avatar Jan 06 '23 15:01 csala