Skip to content

Give precedence to .mdformat.toml over pyproject.toml options, if it exists. #17

@csala

Description

@csala

Context

After #4 has been resolved, if mdformat-pyproject is installed, .mdformat.toml is fully ignored if it exists.

This can be confusing to some users who might find that the options that they set in .mdformat.toml are ignored if they are not aware of having mdformat-pyproject installed.

Proposal

The proposed behavior is to imitate the approach used by ruff, which is to support both pyproject.toml options and its own .ruff.toml configuration file, but giving precedence to its own .ruff.toml file if both exist.

In our case, this translates into:

  1. When looking for configuration, search for both .mdformat.toml file and pyproject.toml with mdformat options, scaling up the directory tree.
  2. If an .mdformat.toml is found in a directory, parse its options and stop the search, even if it defines none.
  3. If a pyproject.toml is found and it contains an mdformat section, parse its options and stop the search, even if it defines none.
  4. If no mdformat.toml is found and no pyproject.toml is found or if a pyproject.toml is found but does not have an mdformat section, we move one level up the tree and continue searching.

As a consequence:

  • pyproject.toml files that do not define an mdformat section are ignored
  • If the first directory in which configuration is found contains both an .mdformat.toml file and a pyproject.toml file that also defines an mdformat section, only the options from .mdformat.toml are considered, and pyproject.toml is ignored.

To prevent confusions, if a pyproject.toml with mdformat section is found but it is ignored because an .mdformat.toml file exists in the same directory, a warning should be given.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions