Add --config option to specify explicit configuration path - #563
Add --config option to specify explicit configuration path#563meek2100 wants to merge 20 commits into
Conversation
|
@hukkin, |
KyleKing
left a comment
There was a problem hiding this comment.
I added a few minor comments as an active in the mdformat community and to possibly help this PR along, but I'm not a maintainer, so take my feedback with a grain of salt!
There was a problem hiding this comment.
Maybe this snippet could be extracted into a shared helper? The only difference is the error message (which includes the config_path in the former)
| """ | ||
|
|
||
|
|
||
| def read_single_config_file(config_path: Path) -> tuple[Mapping, Path | None]: |
There was a problem hiding this comment.
This function should be cached like read_toml_opts (not strictly necessary, see proposal to hoist outside of the for loop)
| except FileNotFoundError as e: | ||
| if config_override_path and str(config_override_path) == str(e.args[0]): | ||
| print_error(f"Configuration file not found at: {e.args[0]}") | ||
| return 1 | ||
| raise |
There was a problem hiding this comment.
What about raising a custom ConfigFileNotFoundError or ConfigOverrideNotFoundError (instead of the more general FileNotFoundError) with the relevant metadata, then this conditional logic isn't necessary?
| try: | ||
| toml_opts, toml_path = read_toml(path.parent if path else Path.cwd()) | ||
| if config_override_path: | ||
| toml_opts, toml_path = read_single_config_file(config_override_path) |
There was a problem hiding this comment.
Actually on caching, the config override file can be read outside of the loop because the configuration file isn't relative to the file path. Maybe something like:
(toml_opts, toml_path): tuple[...?, Path] = None, None
if config_override_path:
toml_opts, toml_path = read_single_config_file(config_override_path)
for path in file_paths:
...|
Okay, so you're interested in how cryptocurrencies are created! That's a fundamental part of the crypto world. There are primarily two main ways new cryptocurrencies are "created" or brought into existence:
|
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.