Questions tagged [yapf]
30 questions
26
votes
4 answers
How to use yapf (or black) in VSCode
I installed yapf using:
conda install yapf
and add next lines in my .vscode/settings.json file:
{
//"python.linting.pylintEnabled": true,
//"python.linting.pycodestyleEnabled": false,
//"python.linting.flake8Enabled": true,
…

Mikhail_Sam
- 10,602
- 11
- 66
- 102
13
votes
1 answer
how to apply yapf to every python file under a directory?
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…

tribbloid
- 4,026
- 14
- 64
- 103
10
votes
0 answers
Force Yapf to wrap lines after expression/just before for-loop in list comprehension
yapf formatter can wrap long lines in the code inside parentheses in the expression in the list comprehension:
threads = [threading.Thread(
target=worker, args=[q], daemon=True) for _ in range(worker_count)]
I want to wrap just before the…

jfs
- 399,953
- 195
- 994
- 1,670
5
votes
0 answers
Is there a way to force YAPF to always split/fold comprehensions?
How to force YAPF to always split/fold comprehensions like with SPLIT_COMPLEX_COMPREHENSION when column_limit is exceeded?
I have been trying many sorts of configuration setups - all to no avail. I'd rather avoid spraying over the codebase with…

CapedHero
- 597
- 1
- 9
- 20
5
votes
1 answer
How to configure YAPF to use hanging indentation for long argument lists
I've using yapf to automatically format my python code. In general I'm very happy with it, but there's a style convention I can't figure out how to configure. When there's a long list of arguments inside a pair of parentheses, which expand beyond…

jorgeh
- 1,727
- 20
- 32
5
votes
1 answer
Is it possible to get yapf to ignore portions of a file?
I'm using a python-dsl called snakemake that looks like this:
from bx.intervals.cluster import ClusterTree
from epipp.config import system_prefix, include_prefix, config, expression_matrix
config["name"] =…

The Unfun Cat
- 29,987
- 31
- 114
- 156
3
votes
1 answer
How to configure YAPF to format the same way as Black
Black won't work on my computer but I want YAPF to function the same way black does. Is there a way to change the custom settings of YAPF to format the exact same way as black? I figure black is industry standard and want to follow that. What…

SEB
- 89
- 1
- 6
3
votes
1 answer
Yapf (a formatter for python files) in Sublime Text 3 doesn't work. Access is denied
When I press Ctrl + alt + F , It says :
OSError: [WinError 5] Access is denied
You may need to install YAPF and/or configure 'yapf_command' in PyYapf's Settings.
So I have already installed YAPF and configured in PyYapf's Settings :
// full…

Nikiphor
- 31
- 3
2
votes
0 answers
Yapf wanting a linebreak and tabbing when it shouldn't
I'm having an issue with yapf behaving differently on my local machine and on a jenkins pipeline build.
This is my line:
groups = thing.func(
*[iter(people)] * constants.MAX_PEOPLE_PER_CREATE)
That yapf keeps telling me is wrong (and failing,…

Rev Tyler
- 601
- 7
- 17
2
votes
2 answers
pre-commit yapf fails on file included in yapfignore
One of the pre-commit hooks set up in the repo is yapf (.pre-commit-config.yaml):
repos:
# Note: the YAPF config is found in `.style.yapf` and `.yapfignore`
- repo: https://github.com/pre-commit/mirrors-yapf
rev: v0.29.0
hooks:
- id:…

MauroNeira
- 315
- 3
- 13
2
votes
1 answer
Python code style: is there a way to configure linters to split parameters into multiple lines?
Currently I am working on a Python 3.8 project with Django 3.1.4 where I would like the code style to be enforced in the following manner:
Split iterables into multiple lines, keeping brackets in separate lines from their contents. For…

Gabriela Valle
- 31
- 3
2
votes
0 answers
how to add rule to auto change strings to use double quotes with yapf formatter and add comma after the last item of the list?
In the doc don't have a list available properties, and i find one file with some properties in gist.github, but i don't find the key for this rules.
Example of my problem:
I have this code:
endpoints = [
path('check_email/', check_email)
]
and…

marcos souza
- 51
- 5
2
votes
1 answer
Unable to exclude directory with yapf
I'm unable to exclude a directory from being autoformatted with yapf.
Tested usages:
yapf --in-place --recursive --parallel --exclude 'somedir' --exclude '*_pb2.py' .
yapf --in-place --recursive --parallel --exclude 'somedir/*' --exclude '*_pb2.py'…

tarabyte
- 17,837
- 15
- 76
- 117
1
vote
0 answers
VSCode: how to run yapf to format on save the file
I recently installed yapf using pip and configured the settings.json file of vscode but I don't know how to run yapf formatting the current opened file on save. Any clue?
here is my settings.json file:
"[python]": {
…

Stefano Borzì
- 1,019
- 1
- 15
- 32
1
vote
1 answer
pre-commit hook yapf returns different results than running yapf in the command line
When running over a file using the command line and yapf, my tags are the following:
-i --verbose --style "google"
When using the same above as args for pre-commit, my pre-commit hook always returns "Pass".
This was tested against the same file…

jtso
- 21
- 3