New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support reading configuration options from a file #263
Comments
Thanks for opening your first issue here! Engagement like this is essential for open source projects! 🤗 |
Hey, thanks for the issue! I recommend using the open source pre-commit tool and its configuration file ( I've been trying to avoid, or at least postpone having an mdformat specific conf file as If there's use cases that pre-commit won't solve and other users also need this, then sure let's have a conf file. In that case the format will be TOML and filename will be |
Thanks for the thoughtful response!
I do use
I'll describe my particular use case in more detail in an effort to illustrate what I mean by this. I write code in vim, and make use of many plugins and custom bindings to assist with this. For example, when editing python files, pressing F5 blackens the code in the focused buffer. When editing JSON, F5 now formats it with python's The problem here is that when executed in a shell, mdformat does not read local configuration from the pre-commit config. So if any options are set there, I will often be running into failed hooks when I attempt to commit my changes even if I already ran mdformat from the editor. If I'm editing a lot of markdown that day, that's a lot of extra toil and tedium.
I hope this helps.
Unfortunately, having any configuration options at all exposes us to this problem.
I agree and completely sympathize with your concerns about complexity. Even if I were to help write it initially, I am not volunteering to maintain all that new code indefinitely. :-) My objection is to everything after "that if...". pre-commit is not a configuration file because your other documented execution paths (through the terminal, and the python API) do not read options from it.
Simply reading |
Regarding running mdformat in vim and terminal: what if instead of running mdformat <filename> you run (and configure vim to run) pre-commit run mdformat --files <filename> This should make it so that pre-commit's configuration is used in those environments also. What do you think?
*sigh* yeah you're right about that. |
That might enable my current workflow. But there is a performance penalty:
I still feel constrained in how I can use this tool and promote its use in other projects that I don't control, though. Anyway, I understand if you decide not to do this. Thanks for hearing me out. |
Hmm, wonder why the performance hit was so significant for you. Perhaps the virtual environment wasn't initialized or not everything was installed on that 2.424 second invocation? Is the difference as significant on following invocations as well? On my machine I get foo@bar:~/dev/tomli$ time pre-commit run mdformat --files README.md CHANGELOG.md
mdformat.................................................................Passed
real 0m0.514s
user 0m0.468s
sys 0m0.050s
foo@bar:~/dev/tomli$ time mdformat README.md CHANGELOG.md
real 0m0.487s
user 0m0.462s
sys 0m0.024s There's barely any difference. I ran against tomli repository, with same plugins (the ones listed in pre-commit-config.yaml) in both methods. I studied conf file discovery logic of a couple other tools. I think what I'd want to do here is simply walk from current working directory to file system root, stopping if the file is found. This is more or less what rustfmt does. Prettier walks up from the directory of the file being formatted instead of CWD, which I also really like, but don't want to deal with the cases when more than one files, no files, or symlinks are passed in. Black seems to determine a common ancestor directory of the files passed in and start from that, which I find slightly more complex but not necessarily that much better than starting from CWD. Still not 100% sure we need the conf file, but if yes, it should be more or less planned out now 😄 |
That would be perfect! The discovery path I suggested in the OP would be for if we want to support user-specific configurations as well, but in retrospect that does seem to be somewhat against the spirit of this tool. |
Ok I've warmed up to the idea, mainly because
And also, perhaps not every user is able to use git and pre-commit. So a PR is very welcome if you or anyone else is interested in working on this. If not, I may do this eventually myself. I've changed my mind slightly regarding file discovery: let's do what Prettier does, i.e.:
|
Description / Summary
mdformat
supports three configuration options via switches to the command line interface:However, there does not seem to be support for configuring these options from a file that could be committed to source control.
Value / benefit
A configuration file would assist in ensuring consistent behavior between executing manually in a terminal, an editor integration, and when running as a
pre-commit
hook.Implementation details
I find yaml files to be excellent for implementing configurations that are more often parsed by humans than by programs. But I do not have a strong opinion about this. toml is also an option that is gaining traction in the python ecosystem.
To discover the configuration file, I suggest this logic to follow the xdg base directory spec:
./.mdformat-config.yaml
$XDG_CONFIG_HOME/mdformat-config.yaml
$HOME/mdformat-config.yaml
$HOME/.mdformat-config.yaml
If command-line switches are passed, they should over-ride conflicting options in the configuration file.
Tasks to complete
The text was updated successfully, but these errors were encountered: