Add --config option to specify explicit configuration path #563
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request introduces the
--config <path>command-line option, allowing users to explicitly define the path to their TOML configuration file, overriding the default recursive search for.mdformat.toml.This feature primarily supports integration with modern tooling like pre-commit hooks and centralized configuration management systems where config files may live outside the project root or in a custom directory.
Key Changes:
--config(typePath) tosrc/mdformat/_cli.py.read_single_config_fileinsrc/mdformat/_conf.pyto support direct path loading. Therunfunction logic prioritizes--configand correctly handles non-existent file paths by exiting with an error.test_config_override_precedence) verifying that the explicit--configcorrectly overrides auto-detected.mdformat.tomlsettings.docs/users/configuration_file.mdto document the new usage.InvalidPathexception class insrc/mdformat/_cli.pyto properly callsuper().__init__(path), resolving theflake8-bugbear(B042) warning.