Skip to content

Reading configuration from pyproject.toml #356

@jspaezp

Description

@jspaezp

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions