Yapf: `yapf` without arguments hangs

Created on 14 Apr 2018  路  5Comments  路  Source: google/yapf

I saw that specifying files was optional on the README, so I just typed yapf at the root of my python project and expected it to pick up on all of the project's files. Instead, it seems to just hang using 0% CPU, without explaining to the user what they did wrong / offering a help prompt.

It ended up working with find . -iname '*.py' | xargs yapf -i, but it would be nice if I could simply issue yapf -i for the same effect.

Most helpful comment

Isn't this standard behaviour on Unix? ... if reading from stdin, the program just "hangs". (yapf is hardly unique in that respect; for example cat will just "hang".)

All 5 comments

Isn't this standard behaviour on Unix? ... if reading from stdin, the program just "hangs". (yapf is hardly unique in that respect; for example cat will just "hang".)

@kamahen From the perspective of the first-time user how should I know that yapf alone takes input from stdin? It doesn't indicate that in the help prompt.

If there is already established behavior for yapf without any switches, then maybe changing it isn't such a good idea after all. But we could still modify yapf -i to behave this way.

I agree that the behavior with yapf -r seems wrong ... anyway, the behaviour you want seems to be what yapf -r -i . does.

I surmise that there's a use case for running yapf as a filter, in which case the "hanging" behavior you mention would be useful (although it could be simulated by using /dev/stdin as the file name). Lots of Unix programs will take input from stdin if there's no file name, so the "hanging" isn't surprising, although it usually does make me stop and think for a few seconds. ;)

yapf -i already does complain:

$ yapf -i
usage: yapf [-h] [-v] [-d | -i] [-r | -l START-END] [-e PATTERN]
            [--style STYLE] [--style-help] [--no-local-style] [-p] [-vv]
            [files [files ...]]
yapf: error: cannot use --in-place or --diff flags when reading from stdin

From the perspective of the first-time user how should I know that yapf alone takes input from stdin? It doesn't indicate that in the help prompt.

I personally found it intuitive having used a number of Unix CLI tools. However, I guess that adding a hint in the help message would be useful for better user experience. E.g. cat outputs this in help:

With no FILE, or when FILE is -, read standard input.

@jamesqo It could probably be documented a bit better, but it's expected behavior in this case. It reads from stdin as has been mentioned. If you'd like to improve the help message I would appreciate it. :-)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

eli-schwartz picture eli-schwartz  路  5Comments

tschijnmo picture tschijnmo  路  6Comments

bukzor picture bukzor  路  3Comments

youngmit picture youngmit  路  4Comments

advance512 picture advance512  路  6Comments