asottile / setup-cfg-fmt

apply a consistent format to `setup.cfg` files
MIT License
152 stars 20 forks source link

allow passing '-' as filename, print reformatted setup.cfg to stdout #217

Closed seanbreckenridge closed 11 months ago

seanbreckenridge commented 11 months ago

Was trying to set this up to autoformat my setup.cfg files in neovim, and the easiest way to do that (with the plugin I use) is to be able to read from STDIN/write back to STDOUT which then replaces the contents of the buffer. I ended up just wrapping it in a script like:

#!/usr/bin/env bash
set -e
tfile="$(mktemp -t setup.cfg.XXXXXX -p "$(pwd)")"
cat >"$tfile"
setup-cfg-fmt "$@" "$tfile" >&2 || true
cat "$tfile"
command rm -f "$tfile"

and that works, but would be nice to be able to avoid the tempfile.

So, proposed feature is to be able to call this with like setup-cfg-fmt - <setup.cfg, and it prints the formatted setup.cfg to stdout

If you're ok with adding this, I can make a PR

asottile commented 11 months ago

tbh I'd rather not carry the complexity and you've already got a working solution

seanbreckenridge commented 11 months ago

yeah, fair enough -- I only format a setup.cfg once in a while anyways, so this is fine as a solution

after reading through the code would infect a bunch of things because of _adjacent_filename

For anyone else trying to do this, should note that you should make the setup.cfg tempfile in the same directory as the setup.cfg, so it can pick up readme/license changes