Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format Document not working (autopep8, python, vscode) #6495

Closed
sanathkumarbs opened this issue Jul 8, 2019 · 6 comments
Closed

Format Document not working (autopep8, python, vscode) #6495

sanathkumarbs opened this issue Jul 8, 2019 · 6 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug

Comments

@sanathkumarbs
Copy link

Environment data

  • VS Code version: 1.36.0
  • Extension version (available under the Extensions sidebar): 2019.6.22090
  • OS and version: macOS, Mojave 10.14.5
  • Python version (& distribution if applicable, e.g. Anaconda): Python 2.7.16
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): N/A
  • Relevant/affected Python packages and their versions:
    autopep8 1.4.4
    pycodestyle: 2.5.0
  • Jedi or Language Server? (i.e. what is "python.jediEnabled" set to; more info How to update the language server to the latest stable version #3977): Jedi Enabled is "checked" (so, True?)

Expected behaviour

When I run "Format Document", the file is formatted.

Actual behaviour

When I run "Format Document", the file is not formatted.

Steps to reproduce:

  1. Open a Workspace
  2. Open up a Python File in the Workspace
  3. Right Click -> Format Document

Current Settings:

User Settings (showing only Python related settings):

{
    .
    .
    .
    "workbench.statusBar.visible": true,
    "files.autoSave": "afterDelay",
    "editor.formatOnPaste": true,
    "editor.formatOnSave": true,
    "editor.formatOnSaveTimeout": 1500,
    "python.pythonPath": "/usr/local/bin/python",
    "python.formatting.provider": "autopep8",
    "python.formatting.autopep8Path": "/usr/local/lib/python2.7/site-packages/autopep8.py",
    "python.formatting.autopep8Args": [
        "--max-line-length",
        "70",
        "--aggressive",
        "--aggressive",
        "--in-place"
    ],
    "python.linting.pylintArgs": [
        "--init-hook='import sys; sys.path.append(\"/Users/bagursreenivasamurth/OneDrive - F5 Networks/dev/godev/src/gitswarm.f5net.com/proj/tests/libs\")'"
    ]
}

Workspace Settings:

{
	"folders": [
		{
			"path": "."
		},
		{
			"path": "godev"
		}
	],
	"settings": {
		"python.pythonPath": "/usr/local/bin/python",
	}
}

Extensions:

Extensions

What I have already tried:

  1. Ensured autopep8 is installed correctly to py2.7 : pip2 install --upgrade autopep8
  2. The interpreter seems to be correctly pointing to py2.7 too
    py27
  3. This works:
    /usr/local/lib/python2.7/site-packages/autopep8.py --max-line-length 60 --in-place --aggressive --aggressive test.py
  4. This works too:
    python -m autopep8 --max-line-length 60 --in-place --aggressive --aggressive test.py
  5. autopep8 imported in python interpreter is the same as the one pointing in vscode python.formatting.autopep8Path setting:
$ python
Python 2.7.16 (default, Apr 12 2019, 15:32:40) 
[GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.46.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import autopep8
>>> autopep8.__file__
'/usr/local/lib/python2.7/site-packages/autopep8.pyc


vscode setting:
 "python.formatting.autopep8Path": "/usr/local/lib/python2.7/site-packages/autopep8.py"
  1. Uninstalled all extensions, reloaded. Reinstalled all extensions.
  • When I had uninstalled all extensions, including Python. On "Format Document", I got a prompt asking me to choose formatter.
  • After reinstalling all extensions, including Python. On "Format Document", I get no prompt. I'm guessing it is honoring my user settings.
    onFormatSave-disabled-extensions

Meanwhile,

$ which python
/usr/local/bin/python

$ python --version
Python 2.7.16

Logs

  1. No output in "Output" when I run "Format Document"
  2. Console log on Developer Tools on "Format Document"
    onFormatDocument
@sanathkumarbs sanathkumarbs added triage-needed Needs assignment to the proper sub-team bug Issue identified by VS Code Team member as probable bug labels Jul 8, 2019
@DonJayamanne DonJayamanne self-assigned this Jul 9, 2019
@coldino

This comment has been minimized.

@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Jul 10, 2019
@sanathkumarbs

This comment has been minimized.

@DonJayamanne
Copy link

"python.formatting.autopep8Path": "/usr/local/lib/python2.7/site-packages/autopep8.py"

Please remove the above setting, and then select the required interpreter from the statusbar or using the command Python: Select Interpreter. (using the approach you have used might not always work as the file is a .py file and not an executable. We expect autopep8Path to be an executable)

Not 100% certain this is the same issue, but I am seeing similar behaviour with the yapf formatter - but only in certain sub-directories of a project.

@coldino Please create a separate issue if it still persists.

@sanathkumarbs
Copy link
Author

@DonJayamanne I removed python.formatting.autopep8Path and tried Format Document that didn't do anything.

I just started removing each of my setting and was just left with:

    "python.formatting.autopep8Args": [
        "--max-line-length",
        "70",
        "--aggressive",
        "--aggressive",
        "--in-place"
    ]

Looks like the issue was in using --in-place, as soon as I got rid of the --in-place arg - voila everything started working!

Not really sure why that was causing the issue. Also, I'm a tad bit confused why the console log never showed this issue.

@DonJayamanne
Copy link

Thanks for getting back. When you use In-place then no response is sent as the output, hence it's assumed that there's nothing to be formatted (i.e. code has already been formatted).

Closing as this issue has been resolved.

@ghost ghost removed the triage label Jul 12, 2019
@sanathkumarbs
Copy link
Author

sanathkumarbs commented Jul 12, 2019

Thanks, @DonJayamanne. Could there be some additional checks to catch this issue? Possibly log in console with an error/warning?

Or mention about this in the docs?

@lock lock bot locked as resolved and limited conversation to collaborators Jul 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

No branches or pull requests

3 participants