Issue with autoFormatOnSave and yapf
See original GitHub issueFrom @dcramer on June 1, 2017 6:44
Environment data
VS Code version: 1.12.2 (tried Insiders as well) Python Extension version: 0.6.4 Python Version: 2.7.13 OS and version: macOS Sierra 10.12.4
Actual behavior
Upon save it reformats the file, and does not appear to behave the same as yapf -i file
.
For example, this content:
from __future__ import absolute_import
from django.db import models
from django.utils import timezone
from sentry.db.models import (BoundedBigIntegerField, FlexibleForeignKey,
Model, sane_repr)
When I hit save, it generates invalid Python:
from __future__ import absolute_import
from django.db import models
from django.utils import timezone
from sentry.db.models import (
BoundedBigIntegerField, FlexibleForeignKey, Model, sane_repr
)
)
Expected behavior
The expected output should be:
from __future__ import absolute_import
from django.db import models
from django.utils import timezone
from sentry.db.models import (
BoundedBigIntegerField, FlexibleForeignKey, Model, sane_repr
)
Steps to reproduce:
- add
editor.formatOnSave
to workspace settings - save the file
Even when it doesnt incorrectly format the file into invalid Python, it doesnt seem to respect the configuration within setup.cfg (i still get different output from yapf -i).
Here is the changeset which we identified this behavior in:
https://github.com/getsentry/sentry/commit/a2587aa38a40c283eb6780e34f9caefa452ccf77
Settings
Your launch.json (if dealing with debugger issues):
Your settings.json:
{
"files.exclude": {
"**/*.pyc": true,
"static": true,
"node_modules": true,
"src/sentry/static/dist": true,
"env": true
},
"prettier.bracketSpacing": false,
"prettier.singleQuote": true,
"prettier.printWidth": 90,
"eslint.options": {
"configFile": ".eslintrc"
},
"[javascript]": {
"editor.formatOnSave": true
},
"[json]": {
"editor.formatOnSave": true
},
"editor.formatOnSave": true,
"python.linting.pylintEnabled": false,
"python.linting.flake8Enabled": true,
"python.formatting.provider": "yapf",
"python.pythonPath": "${env.WORKON_HOME}/sentry/bin/python"
}
Copied from original issue: DonJayamanne/pythonVSCode#992
Issue Analytics
- State:
- Created 6 years ago
- Comments:19 (3 by maintainers)
Top GitHub Comments
@yegorski, apologies for not having resolved this issue yet. Will look into this soon. I believe I know the problem (I’m creating a temporary file to perform the formatting, and in doing so, the config file isn’t picked up)
It seems that #730 covers my issue. Though for yapf settings I used section
[yapf]
in thesetup.cfg
file rather than.style.yapf
file in the #730. So this issue seems can be closed. I can’t understand in which version of VS Code #730 merged so didn’t test it.