how to apply yapf to every python file under a directory?











up vote
0
down vote

favorite












I have installed Google yapf (yet another python formatter) under a project and try to format all my python files in-place, however I got the following error:



$ yapf -i -r files **.py
yapf: Input filenames did not match any python files


why yapf is incapable of understanding pattern? What should I do to achieve the same thing?



EDIT I also tried yapf -ir as suggested but I got:



$ yapf -ir
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


which is strange as I'm not reading from stdin










share|improve this question
























  • That's not what I suggested...
    – larsks
    Nov 18 at 13:30















up vote
0
down vote

favorite












I have installed Google yapf (yet another python formatter) under a project and try to format all my python files in-place, however I got the following error:



$ yapf -i -r files **.py
yapf: Input filenames did not match any python files


why yapf is incapable of understanding pattern? What should I do to achieve the same thing?



EDIT I also tried yapf -ir as suggested but I got:



$ yapf -ir
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


which is strange as I'm not reading from stdin










share|improve this question
























  • That's not what I suggested...
    – larsks
    Nov 18 at 13:30













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have installed Google yapf (yet another python formatter) under a project and try to format all my python files in-place, however I got the following error:



$ yapf -i -r files **.py
yapf: Input filenames did not match any python files


why yapf is incapable of understanding pattern? What should I do to achieve the same thing?



EDIT I also tried yapf -ir as suggested but I got:



$ yapf -ir
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


which is strange as I'm not reading from stdin










share|improve this question















I have installed Google yapf (yet another python formatter) under a project and try to format all my python files in-place, however I got the following error:



$ yapf -i -r files **.py
yapf: Input filenames did not match any python files


why yapf is incapable of understanding pattern? What should I do to achieve the same thing?



EDIT I also tried yapf -ir as suggested but I got:



$ yapf -ir
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


which is strange as I'm not reading from stdin







python python-3.x yapf






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 18 at 6:17

























asked Nov 18 at 3:02









tribbloid

1,86952549




1,86952549












  • That's not what I suggested...
    – larsks
    Nov 18 at 13:30


















  • That's not what I suggested...
    – larsks
    Nov 18 at 13:30
















That's not what I suggested...
– larsks
Nov 18 at 13:30




That's not what I suggested...
– larsks
Nov 18 at 13:30












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










The first problem is that wildcard expansion happens in the shell, before the command line even executes. When you run:



somecommand *.py


That command doesn't know you typed a *. All it knows is that you passed in a list of files. In other words, yapf is incapable of understanding the pattern because it never sees the pattern.



The second problem is that ** isn't a valid shell file globbing pattern. That's semantically equivalent to *, so running yapf -ir files **.py will only process any .py files contained in your current directory and inside the files directory.



If you want to run yapf recursively on all your Python files, starting in your current directory, there are a few solutions. The simplest is probably:



yapf -ir .


This will process all .py files in your current directory and its children. If you want more control over the selection of files, use find and xargs:



find . -name '*.py' -print0 | xargs -0 yapf -i





share|improve this answer





















  • thanks a lot, the second command works properly, the first one doesn't, as I have shown in my question update.
    – tribbloid
    Nov 18 at 6:20










  • You forgot the . in the command in your example. Since you didn't pass yapf a list of files, it thinks you're trying to process Python input on stdin.
    – larsks
    Nov 18 at 13:30













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53357514%2fhow-to-apply-yapf-to-every-python-file-under-a-directory%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










The first problem is that wildcard expansion happens in the shell, before the command line even executes. When you run:



somecommand *.py


That command doesn't know you typed a *. All it knows is that you passed in a list of files. In other words, yapf is incapable of understanding the pattern because it never sees the pattern.



The second problem is that ** isn't a valid shell file globbing pattern. That's semantically equivalent to *, so running yapf -ir files **.py will only process any .py files contained in your current directory and inside the files directory.



If you want to run yapf recursively on all your Python files, starting in your current directory, there are a few solutions. The simplest is probably:



yapf -ir .


This will process all .py files in your current directory and its children. If you want more control over the selection of files, use find and xargs:



find . -name '*.py' -print0 | xargs -0 yapf -i





share|improve this answer





















  • thanks a lot, the second command works properly, the first one doesn't, as I have shown in my question update.
    – tribbloid
    Nov 18 at 6:20










  • You forgot the . in the command in your example. Since you didn't pass yapf a list of files, it thinks you're trying to process Python input on stdin.
    – larsks
    Nov 18 at 13:30

















up vote
1
down vote



accepted










The first problem is that wildcard expansion happens in the shell, before the command line even executes. When you run:



somecommand *.py


That command doesn't know you typed a *. All it knows is that you passed in a list of files. In other words, yapf is incapable of understanding the pattern because it never sees the pattern.



The second problem is that ** isn't a valid shell file globbing pattern. That's semantically equivalent to *, so running yapf -ir files **.py will only process any .py files contained in your current directory and inside the files directory.



If you want to run yapf recursively on all your Python files, starting in your current directory, there are a few solutions. The simplest is probably:



yapf -ir .


This will process all .py files in your current directory and its children. If you want more control over the selection of files, use find and xargs:



find . -name '*.py' -print0 | xargs -0 yapf -i





share|improve this answer





















  • thanks a lot, the second command works properly, the first one doesn't, as I have shown in my question update.
    – tribbloid
    Nov 18 at 6:20










  • You forgot the . in the command in your example. Since you didn't pass yapf a list of files, it thinks you're trying to process Python input on stdin.
    – larsks
    Nov 18 at 13:30















up vote
1
down vote



accepted







up vote
1
down vote



accepted






The first problem is that wildcard expansion happens in the shell, before the command line even executes. When you run:



somecommand *.py


That command doesn't know you typed a *. All it knows is that you passed in a list of files. In other words, yapf is incapable of understanding the pattern because it never sees the pattern.



The second problem is that ** isn't a valid shell file globbing pattern. That's semantically equivalent to *, so running yapf -ir files **.py will only process any .py files contained in your current directory and inside the files directory.



If you want to run yapf recursively on all your Python files, starting in your current directory, there are a few solutions. The simplest is probably:



yapf -ir .


This will process all .py files in your current directory and its children. If you want more control over the selection of files, use find and xargs:



find . -name '*.py' -print0 | xargs -0 yapf -i





share|improve this answer












The first problem is that wildcard expansion happens in the shell, before the command line even executes. When you run:



somecommand *.py


That command doesn't know you typed a *. All it knows is that you passed in a list of files. In other words, yapf is incapable of understanding the pattern because it never sees the pattern.



The second problem is that ** isn't a valid shell file globbing pattern. That's semantically equivalent to *, so running yapf -ir files **.py will only process any .py files contained in your current directory and inside the files directory.



If you want to run yapf recursively on all your Python files, starting in your current directory, there are a few solutions. The simplest is probably:



yapf -ir .


This will process all .py files in your current directory and its children. If you want more control over the selection of files, use find and xargs:



find . -name '*.py' -print0 | xargs -0 yapf -i






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 18 at 4:21









larsks

111k18181193




111k18181193












  • thanks a lot, the second command works properly, the first one doesn't, as I have shown in my question update.
    – tribbloid
    Nov 18 at 6:20










  • You forgot the . in the command in your example. Since you didn't pass yapf a list of files, it thinks you're trying to process Python input on stdin.
    – larsks
    Nov 18 at 13:30




















  • thanks a lot, the second command works properly, the first one doesn't, as I have shown in my question update.
    – tribbloid
    Nov 18 at 6:20










  • You forgot the . in the command in your example. Since you didn't pass yapf a list of files, it thinks you're trying to process Python input on stdin.
    – larsks
    Nov 18 at 13:30


















thanks a lot, the second command works properly, the first one doesn't, as I have shown in my question update.
– tribbloid
Nov 18 at 6:20




thanks a lot, the second command works properly, the first one doesn't, as I have shown in my question update.
– tribbloid
Nov 18 at 6:20












You forgot the . in the command in your example. Since you didn't pass yapf a list of files, it thinks you're trying to process Python input on stdin.
– larsks
Nov 18 at 13:30






You forgot the . in the command in your example. Since you didn't pass yapf a list of files, it thinks you're trying to process Python input on stdin.
– larsks
Nov 18 at 13:30




















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53357514%2fhow-to-apply-yapf-to-every-python-file-under-a-directory%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

RAC Tourist Trophy