Code Monkey home page Code Monkey logo

vscode-autopep8's Introduction

Formatter extension for Visual Studio Code using autopep8

A Visual Studio Code extension with support for the autopep8 formatter. The extension ships with autopep8=2.1.0.

Note: The minimum supported version of autopep8 is 1.7.0. If you have any issues with formatting with autopep8, please report it to this issue tracker as this extension is just a wrapper around autopep8.

This extension supports for all actively supported versions of the Python language (i.e., Python >= 3.8).

For more information on autopep8, see https://pypi.org/project/autopep8/.

Usage and Features

The autopep8 extension for Visual Studio Code provides formatting support for your Python files. Check out the Settings section for more details on how to customize this extension.

  • Integrated formatting: Once this extension is installed in VS Code, autopep8 will be automatically available as a formatter for Python. This is because the extension ships with a autopep8 binary. You can ensure VS Code uses autopep8 by default for all your Python files by setting the following in your User settings (View > Command Palette... and run Preferences: Open User Settings (JSON)):

        "[python]": {
          "editor.defaultFormatter": "ms-python.autopep8"
        }
  • Format on save: Automatically format your Python files on save by setting the editor.formatOnSave setting to true and the editor.defaultFormatter setting to ms-python.autopep8. You can also enable format on save for Python files only by adding the following to your settings:

      "[python]": {
        "editor.defaultFormatter": "ms-python.autopep8",
        "editor.formatOnSave": true
      }
  • Customize autopep8: You can customize the behavior of autopep8 by setting the autopep8.args setting.

Disabling formatting with autopep8

If you want to disable the autopep8 formatter, you can disable this extension per workspace in Visual Studio Code.

Settings

There are several settings you can configure to customize the behavior of this extension.

Settings Default Description
autopep8.args [] Arguments passed to autopep8 to format Python files. Each argument should be provided as a separate string in the array. Example: "autopep8.args" = ["--config", "<file>"]
autopep8.cwd ${workspaceFolder} Sets the current working directory used to format Python files with autopep8. By default, it uses the root directory of the workspace ${workspaceFolder}. You can set it to ${fileDirname} to use the parent folder of the file being formatted as the working directory for autopep8.
autopep8.path [] Path or command to be used by the extension to format Python files with autopep8. Accepts an array of a single or multiple strings. If passing a command, each argument should be provided as a separate string in the array. If set to ["autopep8"], it will use the version of autopep8 available in the PATH environment variable. Note: Using this option may slowdown formatting.
Examples:
["~/global_env/autopep8"]
["conda", "run", "-n", "lint_env", "python", "-m", "autopep8"]
autopep8.interpreter [] Path to a Python executable or a command that will be used to launch the autopep8 server and any subprocess. Accepts an array of a single or multiple strings. When set to [], the extension will use the path to the selected Python interpreter. If passing a command, each argument should be provided as a separate string in the array.
autopep8.importStrategy useBundled Defines which autopep8 formatter binary to be used to format Python files. When set to useBundled, the extension will use the autopep8 formatter binary that is shipped with the extension. When set to fromEnvironment, the extension will attempt to use the autopep8 formatter binary and all dependencies that are available in the currently selected environment.
Note: If the extension can't find a valid autopep8 formatter binary in the selected environment, it will fallback to using the binary that is shipped with the extension. The autopep8.path setting takes precedence and overrides the behavior of autopep8.importStrategy .
autopep8.showNotification off Controls when notifications are shown by this extension. Accepted values are onError, onWarning, always and off.

Commands

Command Description
autopep8: Restart Force re-start the format server.

Logging

From the Command Palette (View > Command Palette ...), run the Developer: Set Log Level... command. Select autopep8 from the Extension logs group. Then select the log level you want to set.

Alternatively, you can set the autopep8.trace.server setting to verbose to get more detailed logs from the autopep8 server. This can be helpful when filing bug reports.

To open the logs, click on the language status icon ({}) on the bottom right of the Status bar, next to the Python language mode. Locate the autopep8 entry and select Open logs.

Troubleshooting

In this section, you will find some common issues you might encounter and how to resolve them. If you are experiencing any issues that are not covered here, please file an issue.

  • If the autopep8.importStrategy setting is set to fromEnvironment but autopep8 is not found in the selected environment, this extension will fallback to using the autopep8 binary that is shipped with the extension. However, if there are dependencies installed in the environment, those dependencies will be used along with the shipped autopep8 binary. This can lead to problems if the dependencies are not compatible with the shipped autopep8 binary.

    To resolve this issue, you can:

    • Set the autopep8.importStrategy setting to useBundled and the autopep8.path setting to point to the custom binary of autopep8 you want to use; or
    • Install autopep8 in the selected environment.

vscode-autopep8's People

Contributors

dependabot[bot] avatar eleanorjboyd avatar joaomoreno avatar karthiknadig avatar kirankumarmanku avatar lramos15 avatar lszomoru avatar luabud avatar microsoft-github-operations[bot] avatar microsoftopensource avatar norasoliman avatar paulacamargo25 avatar vinitaparasrampuria avatar wuyumin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vscode-autopep8's Issues

Command 'Format Document With...' resulted in an error

When I select "Format document with..." and autopep8 from the command palette, I get a dialog box with the following error:

Command 'Format Document With...' resulted in an error
KeyError: <function continued_indentation at 0x10a0a0e00>

These are my user settings for Python:

    "python.defaultInterpreterPath": "/usr/local/bin/python3",
    "[python]": {
        "editor.insertSpaces": true,
        "editor.tabSize": 2,
        "editor.formatOnType": true,
        "editor.defaultFormatter": "ms-python.autopep8",
    },

autopep8 incorrectly skips sources as standard library files

Symptoms: Trying to format a source with autopep8 v2023.6.0 doesn't do anything. The code is on a Debian-based system.

Output>autopep8:

2023-07-13 12:20:40.266 [info] [Trace - 12:20:40 PM] Sending request 'textDocument/formatting - (3)'.
2023-07-13 12:20:40.268 [info] [Trace - 12:20:40 PM] Received notification 'window/logMessage'.
2023-07-13 12:20:40.268 [info] [Warn  - 12:20:40 PM] Skipping standard library file: /usr/local/home/username/code/foo.py
2023-07-13 12:20:40.269 [info] [Trace - 12:20:40 PM] Received response 'textDocument/formatting - (3)' in 2ms.

Likely culprit is #103 - _site_paths were changed to include paths from sysconfig

_site_paths = set(
str(pathlib.Path(p).resolve())
for p in (
as_list(site.getsitepackages())
+ as_list(site.getusersitepackages())
+ list(sysconfig.get_paths().values())
)
)

These paths are then used as prefixes to detect standard library files.

def is_stdlib_file(file_path: str) -> bool:
"""Return True if the file belongs to the standard library."""
normalized_path = str(pathlib.Path(file_path).resolve())
return any(normalized_path.startswith(path) for path in _site_paths)

These files are skipped here:

if utils.is_stdlib_file(document.path):
log_warning(f"Skipping standard library file: {document.path}")
return None

Output from python:

Python 3.11.4 (main, Jun  7 2023, 10:13:09) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sysconfig
>>> sysconfig.get_default_scheme()
'posix_local'
>>> sysconfig.get_paths()
{'stdlib': '/usr/lib/python3.11', 'platstdlib': '/usr/lib/python3.11', 'purelib': '/usr/local/lib/python3.11/dist-packages', 'platlib': 
'/usr/local/lib/python3.11/dist-packages', 'include': '/usr/include/python3.11', 'platinclude': '/usr/include/python3.11', 'scripts': 
'/usr/local/bin', 'data': '/usr/local'} 

'data' : '/usr/local' is a directory for data files (doc), but here it is also a base folder for the user's home folder. So the source file, which in our example is /usr/local/home/username/code/foo.py, gets skipped. I believe data shouldn't be added to _site_paths.

cant disable

Type: Bug

cant disable linter

Extension version: 2023.4.0
VS Code version: Code 1.79.2 (695af097c7bd098fbf017ce3ac85e09bbc5dda06, 2023-06-14T08:57:04.379Z)
OS version: Windows_NT x64 10.0.22621
Modes:

System Info
Item Value
CPUs 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz (8 x 2803)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
Load (avg) undefined
Memory (System) 15.80GB (7.49GB free)
Process Argv --crash-reporter-id 3841da96-4ed1-49e4-ae70-07450715be92
Screen Reader no
VM 0%
A/B Experiments
vsliv368:30146709
vsreu685:30147344
python383:30185418
vspor879:30202332
vspor708:30202333
vspor363:30204092
vslsvsres303:30308271
vserr242cf:30382550
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263:30335439
vscoreces:30445986
vscod805:30301674
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
vsaa593:30376534
pythonvs932:30410667
py29gd2263cf:30773604
vsclangdf:30486550
c4g48928:30535728
dsvsc012cf:30540253
pynewext54:30695312
azure-dev_surveyone:30548225
2e4cg342:30602488
pyind779:30671433
f6dab269:30613381
vscrp:30673768
pythonsymbol12:30671437
showlangstatbar:30737416
vsctsb:30748421
pythonms35:30701012
03d35959:30757346
pythonfmttext:30731395
pythoncmv:30756943
fixshowwlkth:30771522
hideindicator:30766889
pythongtdpath:30769146
dh2dc718:30770000
pythonidxptcf:30772540
pythondjangots:30772535
pythonnoceb:30773526

Can not format when I use it in single file

When I want to format my file when I do not open an activate workspace, (just open a single file), it doesn't work.
When I format a file with a opened workspace, (this file is not in this workspace) it also doesn't work.
It only work when I open a workspace and open a file which in actually in this workspace.
I hope it can work well in any situations.

Plugin should ignore `--recursive`

Because of the following pyproject.toml configuration:

[tool.autopep8]
recursive = true

I get the following autopep8 output:

c:\Program Files\Python39\python.exe -m autopep8 --max-line-length=120 -
CWD Server: c:\Users\Avasam\Documents\Git\Auto-Split
--recursive cannot be used with standard input

And the formatting fails. This is not an issue with in ms-python.python

Not working

Configuration:
Version: 1.81.1 (system setup)
Commit: 6c3e3dba23e8fadc360aed75ce363ba185c49794
Date: 2023-08-09T22:22:42.175Z
Electron: 22.3.18
ElectronBuildId: 22689846
Chromium: 108.0.5359.215
Node.js: 16.17.1
V8: 10.8.168.25-electron.0
OS: Windows_NT x64 10.0.19045

Python 3.11.4
autopep8 version v2023.6.0

Problem:
autopep8-not-working

Settings:
"editor.defaultFormatter": "ms-python.autopep8"

Exclude Regex is not working for formatOnSave

Hi,
It's very easy to repro this. Say, you have this setting in your for autopep8.args:

 "autopep8.args": [
    "--exclude='*.py'",
  ]

Ideally, this shouldn't let autopep8 format on save any Python files. However, when I save a Python file, it's not respecting this setting and ending up formatting the file.

This is the log trace:

2023-08-06 11:37:59.009 [info] [Trace - 11:37:59 AM] Sending request 'textDocument/formatting - (1)'.
2023-08-06 11:37:59.009 [info] Params: {
    "textDocument": {
        "uri": "file:///Users/kirankumarmanku/test.py"
    },
    "options": {
        "tabSize": 4,
        "insertSpaces": true
    }
}


2023-08-06 11:37:59.024 [info] [Trace - 11:37:59 AM] Received notification 'window/logMessage'.
2023-08-06 11:37:59.024 [info] Params: {
    "type": 4,
    "message": "/opt/homebrew/opt/[email protected]/bin/python3.9 -m autopep8 --exclude='*.py' -"
}

I debugged this and found that we are not passing the path to autopep8 command at this line:

result = _run_tool_on_document(document, use_stdin=True)
by setting use_stdin=True.

This is a bug and should be fixed since autopep8 supports excluding specific files and we should pass complete path while doing autoformat.

Is there any work around for this issue?

Support format on type for `autopep8`

As the title says, I've tried autopep8 and black. My codes can be formatted after saved however "FormatOnType" didn't work at al.

I searched this function, and I found an issue in 2018.

Has this feature been truly implemented? It still doesn't know how to format after multiple line breaks, so I have to manually save the files frequently.

Update library packages for the extension

After setting up the repo run the following command from an activated terminal:

nox --session update_packages

It will take some time to update packages. Be sure to use the minimum version of python for the extension. Look for the line that says @nox.session(python="3.7") in noxfile.py

Tabs are being expanded regardless of project configuration

From the document itself:

Tabs or Spaces?
Spaces are the preferred indentation method.
Tabs should be used solely to remain consistent with code that is already indented with tabs.

Source: https://pep8.org/#tabs-or-spaces

The current behavior is expanding all tabs to spaces, regardless of the project configuration (VS Code tabs configuration, settings.json, EditorConfig, etc.)

This should not happen, the extension should respect the existing indentation settings.

Format not working on file save

After I save the .py file I got these log:

2023-11-03 11:00:39.851 [info] [Trace - 11:00:39 AM] Sending request 'textDocument/formatting - (2)'.
2023-11-03 11:00:39.856 [info] [Trace - 11:00:39 AM] Received notification 'window/logMessage'.
2023-11-03 11:00:39.857 [info] c:\Users\myname\.virtualenvs\XXX\Scripts\python.exe -m autopep8 --max-line-length 180 -
2023-11-03 11:00:39.857 [info] [Trace - 11:00:39 AM] Received notification 'window/logMessage'.
2023-11-03 11:00:39.857 [info] CWD Server: f:\Projects\XXX\Client\UEGame\Content\Scripts\Common
2023-11-03 11:00:40.031 [info] [Trace - 11:00:40 AM] Received notification 'window/logMessage'.
2023-11-03 11:00:40.031 [info] cannot mix stdin and regular files
2023-11-03 11:00:40.031 [info] [Trace - 11:00:40 AM] Received response 'textDocument/formatting - (2)' in 180ms.

I have following configuration in .code-workspace file:

"autopep8.args": [
    "--max-line-length 180"
],
"[python]": {
    "editor.formatOnSave": true,
    "editor.defaultFormatter": "ms-python.autopep8",
},

Windows: 10 21H2
VSCode: 1.84.0
autopep8: v2023.6.0

The problem of reporting errors on argparse example

Recently, my annoying mistake in the autopep8 config took place

	...
	"autopep8.args": ["--global-config, ./config.lake8"]

instead

	...
	"autopep8.args": ["--global-config", "./config.lake8"]

There was error in the vscode logs (command pallete > show logs > autopep8) under the info level
2023-08-05 02:46:32.475 [info] cannot mix stdin and regular files.
The text of the error is sent, apparently, along with a class whose name says a lot more about my situation. It seems to me that it is worth changing something in the output of errors and in determining their level.

Message: KeyError: <function continued_indentation at 0x7f79d4bdc700> Code: -32602

Hello, I use vscode on MacOS with vscode version:
็‰ˆๆœฌ: 1.82.0 (Universal)
ๆไบค: 8b617bd08fd9e3fc94d14adb8d358b56e3f72314
ๆ—ฅๆœŸ: 2023-09-06T22:09:41.364Z
Electron: 25.8.0
ElectronBuildId: 23503258
Chromium: 114.0.5735.289
Node.js: 18.15.0
V8: 11.4.183.29-electron.0
OS: Darwin x64 21.6.0

it coming out the following error:
2023-09-26 23:35:06.586 [info] [Error - 23:35:06] Request textDocument/formatting failed.
2023-09-26 23:35:06.586 [info] Message: KeyError: <function continued_indentation at 0x7f79d4bdc700>
Code: -32602
{'traceback': [' File "/Users/edy/.vscode/extensions/ms-python.autopep8-2023.6.0/bundled/libs/pygls/protocol.py", line 340, in _handle_request\n self._execute_request(msg_id, handler, params)\n', ' File "/Users/edy/.vscode/extensions/ms-python.autopep8-2023.6.0/bundled/libs/pygls/protocol.py", line 264, in _execute_request\n self._send_response(msg_id, handler(params))\n', ' File "/Users/edy/.vscode/extensions/ms-python.autopep8-2023.6.0/bundled/tool/lsp_server.py", line 73, in formatting\n edits = _formatting_helper(document)\n', ' File "/Users/edy/.vscode/extensions/ms-python.autopep8-2023.6.0/bundled/tool/lsp_server.py", line 93, in _formatting_helper\n result = _run_tool_on_document(document, use_stdin=True)\n', ' File "/Users/edy/.vscode/extensions/ms-python.autopep8-2023.6.0/bundled/tool/lsp_server.py", line 429, in _run_tool_on_document\n result = utils.run_module(\n', ' File "/Users/edy/.vscode/extensions/ms-python.autopep8-2023.6.0/bundled/tool/lsp_utils.py", line 153, in run_module\n return _run_module(module, argv, use_stdin, source)\n', ' File "/Users/edy/.vscode/extensions/ms-python.autopep8-2023.6.0/bundled/tool/lsp_utils.py", line 138, in _run_module\n runpy.run_module(module, run_name="main")\n', ' File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/runpy.py", line 210, in run_module\n return _run_code(code, {}, init_globals, run_name, mod_spec)\n', ' File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/runpy.py", line 87, in _run_code\n exec(code, run_globals)\n', ' File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/autopep8.py", line 414, in \n del pycodestyle._checks['logical_line'][pycodestyle.continued_indentation]\n']}

can you help me with this? thank you

UnicodeEncodeError running autopep8 on Windows using pyevn

While running the msautopep8 extension in vscode I am getting this error whenever a file change happens (the autopep8 server starts with no problems the error only shows when actually formatting).

UnicodeEncodeError: 'charmap' codec can't encode character '\udc9d' in position 27664: character maps to <undefined>

Full log:

2023-05-04 12:48:13.956 [info] Server: Stop requested
2023-05-04 12:48:13.956 [info] [Trace - 12:48:13 PM] Sending request 'shutdown - (2)'.
2023-05-04 12:48:13.959 [info] [Trace - 12:48:13 PM] Received response 'shutdown - (2)' in 2ms.
2023-05-04 12:48:13.959 [info] [Trace - 12:48:13 PM] Sending notification 'exit'.
2023-05-04 12:48:13.963 [info] Server run command: c:\Users\joaop.pyenv\pyenv-win\versions\3.7.9\python.exe c:\Users\joaop.vscode\extensions\ms-python.autopep8-2023.2.0\bundled\tool\lsp_server.py
2023-05-04 12:48:13.963 [info] Server: Start requested.
2023-05-04 12:48:14.393 [info] CWD Server: c:\Users\joaop\OneDriveGW\OneDrive - WiseCompany\Documentos\Git\api_platform2
2023-05-04 12:48:14.394 [info] sys.path used to run Server:
c:\Users\joaop.vscode\extensions\ms-python.autopep8-2023.2.0\bundled\libs
c:\Users\joaop.vscode\extensions\ms-python.autopep8-2023.2.0\bundled\tool
c:\Users\joaop.pyenv\pyenv-win\versions\3.7.9\python37.zip
c:\Users\joaop.pyenv\pyenv-win\versions\3.7.9\DLLs
c:\Users\joaop.pyenv\pyenv-win\versions\3.7.9\lib
c:\Users\joaop.pyenv\pyenv-win\versions\3.7.9
c:\Users\joaop.pyenv\pyenv-win\versions\3.7.9\lib\site-packages
2023-05-04 12:48:14.394 [info] PYTHONPATH env variable used to run Server:
c:\Users\joaop.vscode\extensions\ms-python.autopep8-2023.2.0\bundled\libs;
2023-05-04 12:48:14.394 [info] Settings used to run Server:
[
{
"cwd": "c:\Users\joaop\OneDriveGW\OneDrive - WiseCompany\Documentos\Git\api_platform2",
"workspace": "file:///c%3A/Users/joaop/OneDriveGW/OneDrive%20-%20WiseCompany/Documentos/Git/api_platform2",
"args": [
"--max-line-length=250"
],
"path": [],
"interpreter": [
"c:\Users\joaop\.pyenv\pyenv-win\versions\3.7.9\python.exe"
],
"importStrategy": "useBundled",
"showNotifications": "off"
}
]

2023-05-04 12:48:14.394 [info] Global settings:
{
"cwd": "C:\Users\joaop\AppData\Local\Programs\Microsoft VS Code",
"workspace": "C:\Users\joaop\AppData\Local\Programs\Microsoft VS Code",
"args": [],
"path": [],
"interpreter": [],
"importStrategy": "useBundled",
"showNotifications": "off"
}

2023-05-04 12:48:14.410 [info] c:\Users\joaop.pyenv\pyenv-win\versions\3.7.9\python.exe -m autopep8 --version
2023-05-04 12:48:14.410 [info] CWD Server: c:\Users\joaop\OneDriveGW\OneDrive - WiseCompany\Documentos\Git\api_platform2
2023-05-04 12:48:14.490 [info] Version info for formatter running for c:\Users\joaop\OneDriveGW\OneDrive - WiseCompany\Documentos\Git\api_platform2:
autopep8 2.0.2 (pycodestyle: 2.10.0)

2023-05-04 12:48:14.491 [info] SUPPORTED autopep8>=1.7.0
FOUND autopep8==2.0.2

2023-05-04 12:48:14.491 [info] c:\Users\joaop.pyenv\pyenv-win\versions\3.7.9\python.exe -m autopep8 --version
2023-05-04 12:48:14.491 [info] CWD Server: c:\Users\joaop\OneDriveGW\OneDrive - WiseCompany\Documentos\Git\api_platform2
2023-05-04 12:48:14.560 [info] Version info for formatter running for c:\Users\joaop\OneDriveGW\OneDrive - WiseCompany\Documentos\Git\api_platform2:
autopep8 2.0.2 (pycodestyle: 2.10.0)

2023-05-04 12:48:14.560 [info] SUPPORTED autopep8>=1.7.0
FOUND autopep8==2.0.2

2023-05-04 12:48:18.827 [info] [Trace - 12:48:18 PM] Sending notification 'textDocument/didChange'.
2023-05-04 12:48:34.872 [info] [Trace - 12:48:34 PM] Sending notification 'textDocument/didChange'.
2023-05-04 12:48:49.034 [info] [Trace - 12:48:49 PM] Sending request 'textDocument/formatting - (1)'.
2023-05-04 12:48:49.049 [info] [Trace - 12:48:49 PM] Received notification 'window/logMessage'.
2023-05-04 12:48:49.049 [info] c:\Users\joaop.pyenv\pyenv-win\versions\3.7.9\python.exe -m autopep8 --max-line-length=250 -
2023-05-04 12:48:49.049 [info] [Trace - 12:48:49 PM] Received notification 'window/logMessage'.
2023-05-04 12:48:49.049 [info] CWD Server: c:\Users\joaop\OneDriveGW\OneDrive - WiseCompany\Documentos\Git\api_platform2
2023-05-04 12:48:50.158 [info] [Trace - 12:48:50 PM] Received notification 'window/logMessage'.
2023-05-04 12:48:50.158 [info] Traceback (most recent call last):
File "c:\Users\joaop.pyenv\pyenv-win\versions\3.7.9\lib\runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "c:\Users\joaop.pyenv\pyenv-win\versions\3.7.9\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "c:\Users\joaop.vscode\extensions\ms-python.autopep8-2023.2.0\bundled\libs\autopep8.py", line 4570, in
sys.exit(main())
File "c:\Users\joaop.vscode\extensions\ms-python.autopep8-2023.2.0\bundled\libs\autopep8.py", line 4516, in main
wrap_output(sys.stdout, encoding=encoding).write(fixed_stdin)
File "c:\Users\joaop.pyenv\pyenv-win\versions\3.7.9\lib\codecs.py", line 377, in write
data, consumed = self.encode(object, self.errors)
File "c:\Users\joaop.pyenv\pyenv-win\versions\3.7.9\lib\encodings\cp1252.py", line 12, in encode
return codecs.charmap_encode(input,errors,encoding_table)
UnicodeEncodeError: 'charmap' codec can't encode character '\udc9d' in position 27652: character maps to

2023-05-04 12:48:50.158 [info] [Trace - 12:48:50 PM] Received response 'textDocument/formatting - (1)' in 1124ms.

Autopep8 Extension <KeyError>

Black formatter works fine yet Autopep8 fails when I format the document, here are my settings.json and autopep8 output

settings.json


{
    "workbench.colorTheme": "Default Dark Modern",
    "editor.fontSize": 16,
    "[python]": {
        "editor.defaultFormatter": "ms-python.autopep8"
    },
    "python.formatting.provider": "none",
}

autopep8 output

2023-09-20 23:34:49.248 [info] [Trace - 11:34:49 PM] Sending request 'textDocument/formatting - (2)'.
2023-09-20 23:34:49.253 [info] [Trace - 11:34:49 PM] Received notification 'window/logMessage'.
2023-09-20 23:34:49.253 [info] /bin/python3 -m autopep8 -
2023-09-20 23:34:49.253 [info] [Trace - 11:34:49 PM] Received notification 'window/logMessage'.
2023-09-20 23:34:49.253 [info] CWD formatter: /home/innsolit
2023-09-20 23:34:49.255 [info] [Trace - 11:34:49 PM] Received notification 'window/logMessage'.
2023-09-20 23:34:49.255 [info] [Error - 11:34:49 PM] Traceback (most recent call last):
  File "/home/innsolit/.vscode/extensions/ms-python.autopep8-2023.6.0/bundled/tool/lsp_server.py", line 429, in _run_tool_on_document
    result = utils.run_module(
  File "/home/innsolit/.vscode/extensions/ms-python.autopep8-2023.6.0/bundled/tool/lsp_utils.py", line 153, in run_module
    return _run_module(module, argv, use_stdin, source)
  File "/home/innsolit/.vscode/extensions/ms-python.autopep8-2023.6.0/bundled/tool/lsp_utils.py", line 138, in _run_module
    runpy.run_module(module, run_name="__main__")
  File "/usr/lib/python3.10/runpy.py", line 227, in run_module
    return _run_code(code, {}, init_globals, run_name, mod_spec)
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/innsolit/.vscode/extensions/ms-python.autopep8-2023.6.0/bundled/libs/autopep8.py", line 414, in <module>
    del pycodestyle._checks['logical_line'][pycodestyle.continued_indentation]
KeyError: <function continued_indentation at 0x7f49fba41ab0>

2023-09-20 23:34:49.255 [info] [Trace - 11:34:49 PM] Received response 'textDocument/formatting - (2)' in 8ms. Request failed: KeyError: <function continued_indentation at 0x7f49fba41ab0> (-32602).
2023-09-20 23:34:49.255 [info] [Error - 11:34:49 PM] Request textDocument/formatting failed.
2023-09-20 23:34:49.255 [info]   Message: KeyError: <function continued_indentation at 0x7f49fba41ab0>
  Code: -32602 
{'traceback': ['  File "/home/innsolit/.vscode/extensions/ms-python.autopep8-2023.6.0/bundled/libs/pygls/protocol.py", line 340, in _handle_request\n    self._execute_request(msg_id, handler, params)\n', '  File "/home/innsolit/.vscode/extensions/ms-python.autopep8-2023.6.0/bundled/libs/pygls/protocol.py", line 264, in _execute_request\n    self._send_response(msg_id, handler(params))\n', '  File "/home/innsolit/.vscode/extensions/ms-python.autopep8-2023.6.0/bundled/tool/lsp_server.py", line 73, in formatting\n    edits = _formatting_helper(document)\n', '  File "/home/innsolit/.vscode/extensions/ms-python.autopep8-2023.6.0/bundled/tool/lsp_server.py", line 93, in _formatting_helper\n    result = _run_tool_on_document(document, use_stdin=True)\n', '  File "/home/innsolit/.vscode/extensions/ms-python.autopep8-2023.6.0/bundled/tool/lsp_server.py", line 429, in _run_tool_on_document\n    result = utils.run_module(\n', '  File "/home/innsolit/.vscode/extensions/ms-python.autopep8-2023.6.0/bundled/tool/lsp_utils.py", line 153, in run_module\n    return _run_module(module, argv, use_stdin, source)\n', '  File "/home/innsolit/.vscode/extensions/ms-python.autopep8-2023.6.0/bundled/tool/lsp_utils.py", line 138, in _run_module\n    runpy.run_module(module, run_name="__main__")\n', '  File "/usr/lib/python3.10/runpy.py", line 227, in run_module\n    return _run_code(code, {}, init_globals, run_name, mod_spec)\n', '  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code\n    exec(code, run_globals)\n', '  File "/home/innsolit/.vscode/extensions/ms-python.autopep8-2023.6.0/bundled/libs/autopep8.py", line 414, in <module>\n    del pycodestyle._checks[\'logical_line\'][pycodestyle.continued_indentation]\n']}

Support format on range

When I try to format selected code with this extension, it prompts:

Extension 'autopep8' is configured as formatter but it cannot format 'Python'-files

But autopep8 actually supports formatting a code fragment, and the Python extension with autopep8 can work properly.

Autopep8 skipping files

this my settings configure.

{
   "[python]": {
        "editor.tabSize": 4,
        "editor.defaultFormatter": "ms-python.autopep8",
        "editor.formatOnSave": true
        
    },
    "autopep8.path": ["python","-m","autopep8"],
    "autopep8.args": ["-i"],
}

the autopep8 log say Skipping standard library file


if formatting my python file with I used autopep8 command , the command is working.

Cannot Format Selection

When I select a piece of code, and then choose Format Selection, vscode raises a pop-up as in below image:

image

these are my configurations:

"[python]": {
        "editor.defaultFormatter": "ms-python.autopep8",
        "editor.formatOnSave": true,
        "editor.formatOnPaste": true,
        "editor.formatOnSaveMode": "modifications",
    },
"autopep8.path": [
    "/home/xuananh/.pyenv/versions/3.9.0/bin/autopep8" 
],
"autopep8.interpreter":[
    "/home/xuananh/.pyenv/versions/3.9.0/bin/python"
],
"autopep8.args": [
    "--max-line-length", "120", "--experimental",
    "--global-config", "${workspaceFolder}/setup.cfg"
],
"autopep8.showNotifications": "onError",
"autopep8.importStrategy":"fromEnvironment",

Ubuntu 22.04
Vscode 1.83.1
autopep8 2.0.4 (pycodestyle: 2.11.1)

Mistake in python 3.7(autopep8 v2022.1.12871025)

Traceback (most recent call last):
  File "C:\Users\Oleg Kolesov\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Users\Oleg Kolesov\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "c:\Users\Oleg Kolesov\.vscode\extensions\ms-python.autopep8-2022.1.12871025\bundled\libs\autopep8.py", line 4590, in <module>
    sys.exit(main())
  File "c:\Users\Oleg Kolesov\.vscode\extensions\ms-python.autopep8-2022.1.12871025\bundled\libs\autopep8.py", line 4536, in main
    wrap_output(sys.stdout, encoding=encoding).write(fixed_stdin)
  File "C:\Users\Oleg Kolesov\AppData\Local\Programs\Python\Python37\lib\codecs.py", line 377, in write
    data, consumed = self.encode(object, self.errors)
  File "C:\Users\Oleg Kolesov\AppData\Local\Programs\Python\Python37\lib\encodings\cp1251.py", line 12, in encode
    return codecs.charmap_encode(input,errors,encoding_table)
UnicodeEncodeError: 'charmap' codec can't encode character '\udc98' in position 255: character maps to \<undefined\>

Auto-formatting inside f-strings

Hey.
The latest version of the extension has a problem that edits inside python f-strings. For instance:
Line of code before formatting:
connector = f"socks5://{user}:{password}:{url}:{port}"
Line after saving with the formatter enabled:
connector = f"socks5: //{user}: {password}: {url}: {port}"

Running 'autopep8' Formatter running forever

Today I stated a single project with Python 3.12.0 and when I save a file, a message saying: "Running 'autopep8' Formatter".

The only way to end the process is by kill it through terminal.

Version: 1.83.1
Commit: f1b07bd25dfad64b0167beb15359ae573aecd2cc
Date: 2023-10-10T23:45:31.402Z
Electron: 25.8.4
ElectronBuildId: 24154031
Chromium: 114.0.5735.289
Node.js: 18.15.0
V8: 11.4.183.29-electron.0
OS: Linux x64 6.2.0-34-generic

Extension autopep8 version: v2023.6.0

image


Publish `vscode-autopep8` to Open VSX

Dear extension author,
Please publish this extension to the Open VSX marketplace.

Context

Unfortunately, as Microsoft prohibits usages of the Microsoft marketplace by any other products or redistribution of .vsix files from it, in order to use VS Code extensions in non-Microsoft products, we kindly ask that you take ownership of the VS Code extension namespace in Open VSX and publish this extension on Open VSX.

What is Open VSX? Why does it exist?

Open VSX is a vendor neutral alternative to the MS marketplace used by most other derivatives of VS Code like VSCodium, Gitpod, OpenVSCode, Theia-based IDEs, and so on.

You can read on about Open VSX at the Eclipse Foundation's Open VSX FAQ.

How can you publish to Open VSX?

The docs to publish an extension can be found here. This process is straightforward and shouldn't take too long. Essentially, you need an authentication token and to execute the ovsx publish command to publish your extension. There's also a doc explaining the whole process with an example GitHub Action workflow.

UnicodeEncodeError when formatting code including Japanese characters on Windows

When formatting my code using autopep8 in VSCode, I encounter the following error:

2023-06-03 11:50:30.339 [info] c:\Users\xxxxx\AppData\Local\Programs\Python\Python310\python.exe -m autopep8 -
2023-06-03 11:50:30.340 [info] [Trace - 11:50:30] Received notification 'window/logMessage'.
2023-06-03 11:50:30.340 [info] CWD Server: c:\Users\xxxxx\Desktop\test
2023-06-03 11:50:30.554 [info] [Trace - 11:50:30] Received notification 'window/logMessage'.
2023-06-03 11:50:30.554 [info] Traceback (most recent call last):
  File "c:\Users\xxxxx\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\Users\xxxxx\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "c:\Users\xxxxx\.vscode\extensions\ms-python.autopep8-2023.4.0\bundled\libs\autopep8.py", line 4570, in <module>
    sys.exit(main())
  File "c:\Users\xxxxx\.vscode\extensions\ms-python.autopep8-2023.4.0\bundled\libs\autopep8.py", line 4516, in main
    wrap_output(sys.stdout, encoding=encoding).write(fixed_stdin)
UnicodeEncodeError: 'cp932' codec can't encode character '\udc81' in position 948: illegal multibyte sequence

I am writing my code in UTF-8, but I noticed that this error occurs only when the code includes Japanese characters, such as:

print("ใ“ใ‚“ใซใกใฏ")

I also noticed that running autopep8 like the following way does not raise the error:

autopep8 test.py
# correctly formatted

but passing the code from stdin as is done in the above log results the error:

cat test.py | autopep8 -
# error

I would like to know if there are any solutions or workarounds available to resolve this problem.

Thank you.

ModuleNotFoundError: No module named 'lsp_jsonrpc'

2023-06-16 15:47:40.917 [info] Name: autopep8
2023-06-16 15:47:40.917 [info] Module: autopep8
2023-06-16 15:47:40.917 [info] Python extension loading
2023-06-16 15:47:40.917 [info] Waiting for interpreter from python extension.
2023-06-16 15:47:40.917 [info] Python extension loaded
2023-06-16 15:47:40.917 [info] Server run command: d:\tools\python-3.9.13\python.exe c:\Users\tiancom.vscode\extensions\ms-python.autopep8-2023.4.0\bundled\tool\lsp_server.py
2023-06-16 15:47:40.917 [info] Server: Start requested.
2023-06-16 15:47:40.998 [info] Traceback (most recent call last):
File "c:\Users\tiancom.vscode\extensions\ms-python.autopep8-2023.4.0\bundled\tool\lsp_server.py", line 38, in

2023-06-16 15:47:40.998 [info] import lsp_jsonrpc as jsonrpc
ModuleNotFoundError: No module named 'lsp_jsonrpc'

2023-06-16 15:47:41.006 [info] [Error - 15:47:41] Server initialization failed.
2023-06-16 15:47:41.006 [info] Message: Pending response rejected since connection got disposed
Code: -32097
2023-06-16 15:47:41.006 [info] [Info - 15:47:41] Connection to server got closed. Server will restart.
2023-06-16 15:47:41.006 [info] true
2023-06-16 15:47:41.007 [info] [Error - 15:47:41] autopep8 client: couldn't create connection to server.
2023-06-16 15:47:41.007 [info] Message: Pending response rejected since connection got disposed
Code: -32097
2023-06-16 15:47:41.103 [info] Traceback (most recent call last):
File "c:\Users\tiancom.vscode\extensions\ms-python.autopep8-2023.4.0\bundled\tool\lsp_server.py", line 38, in

2023-06-16 15:47:41.103 [info] import lsp_jsonrpc as jsonrpc
ModuleNotFoundError: No module named 'lsp_jsonrpc'

2023-06-16 15:47:41.107 [info] [Error - 15:47:41] Server initialization failed.
2023-06-16 15:47:41.107 [info] Message: Pending response rejected since connection got disposed
Code: -32097
2023-06-16 15:47:41.107 [info] [Info - 15:47:41] Connection to server got closed. Server will restart.
2023-06-16 15:47:41.107 [info] true
2023-06-16 15:47:41.108 [info] [Error - 15:47:41] autopep8 client: couldn't create connection to server.
2023-06-16 15:47:41.108 [info] Message: Pending response rejected since connection got disposed
Code: -32097
2023-06-16 15:47:41.108 [error] Server: Start failed: Error: Pending response rejected since connection got disposed
2023-06-16 15:47:41.190 [info] Traceback (most recent call last):
File "c:\Users\tiancom.vscode\extensions\ms-python.autopep8-2023.4.0\bundled\tool\lsp_server.py", line 38, in

2023-06-16 15:47:41.190 [info] import lsp_jsonrpc as jsonrpc
ModuleNotFoundError: No module named 'lsp_jsonrpc'

2023-06-16 15:47:41.195 [info] [Error - 15:47:41] Server initialization failed.
2023-06-16 15:47:41.195 [info] Message: Pending response rejected since connection got disposed
Code: -32097
2023-06-16 15:47:41.195 [info] [Info - 15:47:41] Connection to server got closed. Server will restart.
2023-06-16 15:47:41.195 [info] true
2023-06-16 15:47:41.195 [info] [Error - 15:47:41] autopep8 client: couldn't create connection to server.
2023-06-16 15:47:41.195 [info] Message: Pending response rejected since connection got disposed
Code: -32097
2023-06-16 15:47:41.195 [info] [Error - 15:47:41] Restarting server failed
2023-06-16 15:47:41.196 [info] Message: Pending response rejected since connection got disposed
Code: -32097
2023-06-16 15:47:41.307 [info] Traceback (most recent call last):
File "c:\Users\tiancom.vscode\extensions\ms-python.autopep8-2023.4.0\bundled\tool\lsp_server.py", line 38, in

2023-06-16 15:47:41.307 [info] import lsp_jsonrpc as jsonrpc
ModuleNotFoundError: No module named 'lsp_jsonrpc'

2023-06-16 15:47:41.313 [info] [Error - 15:47:41] Server initialization failed.
2023-06-16 15:47:41.313 [info] Message: Pending response rejected since connection got disposed
Code: -32097
2023-06-16 15:47:41.313 [info] [Info - 15:47:41] Connection to server got closed. Server will restart.
2023-06-16 15:47:41.313 [info] true
2023-06-16 15:47:41.313 [info] [Error - 15:47:41] autopep8 client: couldn't create connection to server.
2023-06-16 15:47:41.313 [info] Message: Pending response rejected since connection got disposed
Code: -32097
2023-06-16 15:47:41.314 [info] [Error - 15:47:41] Restarting server failed
2023-06-16 15:47:41.314 [info] Message: Pending response rejected since connection got disposed
Code: -32097
2023-06-16 15:47:41.399 [info] Traceback (most recent call last):
File "c:\Users\tiancom.vscode\extensions\ms-python.autopep8-2023.4.0\bundled\tool\lsp_server.py", line 38, in
import lsp_jsonrpc as jsonrpc
ModuleNotFoundError: No module named 'lsp_jsonrpc'

2023-06-16 15:47:41.406 [info] [Error - 15:47:41] Server initialization failed.
2023-06-16 15:47:41.406 [info] Message: Pending response rejected since connection got disposed
Code: -32097
2023-06-16 15:47:41.406 [info] [Error - 15:47:41] The autopep8 server crashed 5 times in the last 3 minutes. The server will not be restarted. See the output for more information.
2023-06-16 15:47:41.406 [info] [Error - 15:47:41] autopep8 client: couldn't create connection to server.
2023-06-16 15:47:41.406 [info] Message: Pending response rejected since connection got disposed
Code: -32097
2023-06-16 15:47:41.406 [info] [Error - 15:47:41] Restarting server failed
2023-06-16 15:47:41.406 [info] Message: Pending response rejected since connection got disposed
Code: -32097

with vscode reinstalled
image

with python version 3.9 reinstalled

it always failed to start, how to fix it? thank you

Extension 'autopep8' is configured as formatter but it cannot format 'Pyton'-files

image
I have latest stable version of the autopep8 extension.

I have configured it exactly as requested:

"[python]": {
    "editor.defaultFormatter": "ms-python.autopep8"
},

image

There is no "python.formatting.provider" set anywhere. Not in user nor in workspace/folder settings.

I don't have autopep8 python package installed, so I expect the extension is using its own.

The formatting does not work, whatsoever. When trying to format manually using "Format Selection" command, I get this error:
image

The selection popup doesn't list autopep8 as available for formatting Python files:
image

Windows 11 22H2
VSCode 1.83.1
autopep8 v2023.6.0
Happens both with global environment as well as virtual environment.

Here's the log:
autopep8.log

Autopep8 not working

Hey programmers, I've encountered an issue while trying to format my code using autopep it just gives me this error:

Traceback (most recent call last): File "c:\Users\MackO.vscode\extensions\ms-python.autopep8-2023.6.0\bundled\tool\lsp_server.py", line 429, in _run_tool_on_document result = utils.run_module( ^^^^^^^^^^^^^^^^^ File "c:\Users\MackO.vscode\extensions\ms-python.autopep8-2023.6.0\bundled\tool\lsp_utils.py", line 153, in run_module return _run_module(module, argv, use_stdin, source) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "c:\Users\MackO.vscode\extensions\ms-python.autopep8-2023.6.0\bundled\tool\lsp_utils.py", line 138, in _run_module runpy.run_module(module, run_name="main") File "", line 229, in run_module File "", line 88, in _run_code File "c:\Users\MackO.vscode\extensions\ms-python.autopep8-2023.6.0\bundled\libs\autopep8.py", line 414, in del pycodestyle._checks['logical_line'][pycodestyle.continued_indentation] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^...

Cannot run with a portable python interpreter.

Hello, I'm using VSCode with a embed version of python, which can be downloaded from https://www.python.org/ftp/python/3.10.11/python-3.10.11-embed-amd64.zip

Recent releases of vscode-autopep8 seems not compatible with these embed version of python. Is it possible to solve the problem in future releases?

The following is the output logs:

2023-08-02 20:21:11.756 [info] Name: autopep8
2023-08-02 20:21:11.757 [info] Module: autopep8
2023-08-02 20:21:11.757 [info] Interpreter from setting autopep8.interpreter: f:\Python\python310\python.exe
2023-08-02 20:21:11.757 [info] Interpreter from setting autopep8.interpreter: f:\Python\python310\python.exe
2023-08-02 20:21:11.757 [info] Server run command: f:\Python\python310\python.exe f:\VSCode\data\extensions\ms-python.autopep8-2023.6.0\bundled\tool\lsp_server.py
2023-08-02 20:21:11.757 [info] Server: Start requested.
2023-08-02 20:21:11.834 [info] Traceback (most recent call last):
File "f:\VSCode\data\extensions\ms-python.autopep8-2023.6.0\bundled\tool\lsp_server.py", line 38, in

2023-08-02 20:21:11.834 [info] import lsp_jsonrpc as jsonrpc
ModuleNotFoundError: No module named 'lsp_jsonrpc'

2023-08-02 20:21:11.853 [info] [Error - 8:21:11 PM] Server initialization failed.

The extension uses black instead of autopep8

function getArgs(namespace: string, workspace: WorkspaceFolder): string[] {
const config = getConfiguration(namespace, workspace.uri);
const args = config.get<string[]>('args', []);
if (args.length > 0) {
return args;
}
const legacyConfig = getConfiguration('python', workspace.uri);
return legacyConfig.get<string[]>('formatting.blackArgs', []);
}
function getPath(namespace: string, workspace: WorkspaceFolder): string[] {
const config = getConfiguration(namespace, workspace.uri);
const path = config.get<string[]>('path', []);
if (path.length > 0) {
return path;
}
const legacyConfig = getConfiguration('python', workspace.uri);
const legacyPath = legacyConfig.get<string>('formatting.blackPath', '');
if (legacyPath.length > 0 && legacyPath !== 'black') {
return [legacyPath];
}
return [];
}

Some logs
2023-05-15 07:35:04.058 [info] Name: autopep8
2023-05-15 07:35:04.058 [info] Module: autopep8
2023-05-15 07:35:04.058 [info] Python extension loading
2023-05-15 07:35:04.058 [info] Waiting for interpreter from python extension.
2023-05-15 07:35:04.058 [info] Python extension loaded
2023-05-15 07:35:04.058 [info] Server run command: /workspaces/test/.venv/bin/python /home/vscode/.vscode-remote/extensions/ms-python.autopep8-2023.3.10961007/bundled/tool/lsp_server.py
2023-05-15 07:35:04.058 [info] Server: Start requested.
2023-05-15 07:35:06.387 [info] CWD Server: /workspaces/test
2023-05-15 07:35:06.388 [info] sys.path used to run Server:
   /home/vscode/.vscode-remote/extensions/ms-python.autopep8-2023.3.10961007/bundled/libs
   /home/vscode/.vscode-remote/extensions/ms-python.autopep8-2023.3.10961007/bundled/tool
   /usr/local/lib/python311.zip
   /usr/local/lib/python3.11
   /usr/local/lib/python3.11/lib-dynload
   /workspaces/test/.venv/lib/python3.11/site-packages
   /workspaces/test
2023-05-15 07:35:06.390 [info] PYTHONPATH env variable used to run Server:
   /home/vscode/.vscode-remote/extensions/ms-python.autopep8-2023.3.10961007/bundled/libs:
2023-05-15 07:35:06.391 [info] Settings used to run Server:
[
    {
        "cwd": "/workspaces/test",
        "workspace": "file:///workspaces/test",
        "args": [],
        "path": [
            "/usr/local/py-utils/bin/black"
        ],
        "interpreter": [
            "/workspaces/test/.venv/bin/python"
        ],
        "importStrategy": "useBundled",
        "showNotifications": "off"
    }
]
 "path": [
            "/usr/local/py-utils/bin/black"
        ],

It completely destroyed my project ๐Ÿ˜ž

Writes configuration error into the target source code

When run formatter on a python source file, the format ends with no obvious error but on closer inspection a line has been appened to the python source file:

unknown option 'max-complexity' ignored

autopep8 logs doesn't state any error

2023-11-25 19:58:30.840 [info] [Trace - 7:58:30 PM] Sending request 'textDocument/formatting - (2)'.
2023-11-25 19:58:30.844 [info] [Trace - 7:58:30 PM] Received notification 'window/logMessage'.
2023-11-25 19:58:30.845 [info] c:\Python\Python310\python.exe -m autopep8 -
2023-11-25 19:58:30.845 [info] [Trace - 7:58:30 PM] Received notification 'window/logMessage'.
2023-11-25 19:58:30.845 [info] CWD Server: d:\<retracted>
2023-11-25 19:58:30.986 [info] [Trace - 7:58:30 PM] Received response 'textDocument/formatting - (2)' in 145ms.
2023-11-25 19:58:30.989 [info] [Trace - 7:58:30 PM] Sending notification 'textDocument/didChange'.

I found the "max-complexity" in an butt old .pycodestyle in my user dir and it's probably invalid but not the point here.

For reproduction add this to %USERPROFILE%\.pydevstyle

[pycodestyle]
max-complexity = 20

I expect a visible notification of the error or in the LOG and possibly a hint on where it reads the configuration.

Important

It is absolutely forbidden to put the error message in the source file!

ms-python.autopep8 version: 2023.8.0
Tested with with python 3.10.11 and python 3.8.10

formatter does not work if it contains a specific string

first, my settings.py
image

Normally, it works fine.
But it doesn't work if it contains special characters.
test

I tested in Korean, but the same phenomenon occurred when Japanese or certain special characters were included.

Is there a way to resolve the issue?

Unable to format with Keyboard Shortcut

When I format a file with Cmd K + Cmd F, the following message appears:

Extension 'autopep8' is configured as formatter but it cannot format 'Python'-files

While using Format With command using Cmd+Shift+P, the file is successfully formatted.

python | ms- | 2023.14.0
vscode-pylance | ms- | 2023.8.50
autopep8 | ms- | 2023.6.0

Formatting not working

Hello,

I switched to prerelease channel to solve other issue I had with formatting not working, but I am now running into another one. This time errors like these:

2023-10-28 19:51:41.420 [info] c:\Users\rawal\AppData\Roaming\Blender Foundation\Blender\PyEnv\Scripts\python.exe -m autopep8 --max-line-length=960 -
2023-10-28 19:51:41.420 [info] CWD Server: c:\Users\rawal\AppData\Roaming\Blender Foundation\Blender\3.6\scripts\addons\uvpackmaster3
2023-10-28 19:51:41.463 [info] Could not import runpy module
Traceback (most recent call last):
  File "C:\Users\rawal\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 15, in <module>
    import importlib.util
  File "C:\Users\rawal\AppData\Local\Programs\Python\Python310\lib\importlib\util.py", line 14, in <module>
    from contextlib import contextmanager
  File "C:\Users\rawal\AppData\Local\Programs\Python\Python310\lib\contextlib.py", line 5, in <module>
    from collections import deque
  File "C:\Users\rawal\AppData\Local\Programs\Python\Python310\lib\collections\__init__.py", line 36, in <module>
    from operator import eq as _eq
  File "c:\Users\rawal\AppData\Roaming\Blender Foundation\Blender\3.6\scripts\addons\uvpackmaster3\operator.py", line 20, in <module>
    import subprocess
  File "C:\Users\rawal\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 50, in <module>
    import threading
  File "C:\Users\rawal\AppData\Local\Programs\Python\Python310\lib\threading.py", line 6, in <module>
    import functools
  File "C:\Users\rawal\AppData\Local\Programs\Python\Python310\lib\functools.py", line 18, in <module>
    from collections import namedtuple
ImportError: cannot import name 'namedtuple' from partially initialized module 'collections' (most likely due to a circular import) (C:\Users\rawal\AppData\Local\Programs\Python\Python310\lib\collections\__init__.py)

2023-10-28 19:52:03.228 [info] c:\Users\rawal\AppData\Roaming\Blender Foundation\Blender\PyEnv\Scripts\python.exe -m autopep8 --max-line-length=960 -
2023-10-28 19:52:03.228 [info] CWD Server: c:\Users\rawal\AppData\Roaming\Blender Foundation\Blender\3.6\scripts\addons\uvpackmaster3
2023-10-28 19:52:03.271 [info] Could not import runpy module
Traceback (most recent call last):
  File "C:\Users\rawal\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 15, in <module>
    import importlib.util
  File "C:\Users\rawal\AppData\Local\Programs\Python\Python310\lib\importlib\util.py", line 14, in <module>
    from contextlib import contextmanager
  File "C:\Users\rawal\AppData\Local\Programs\Python\Python310\lib\contextlib.py", line 5, in <module>
    from collections import deque
  File "C:\Users\rawal\AppData\Local\Programs\Python\Python310\lib\collections\__init__.py", line 36, in <module>
    from operator import eq as _eq
  File "c:\Users\rawal\AppData\Roaming\Blender Foundation\Blender\3.6\scripts\addons\uvpackmaster3\operator.py", line 20, in <module>
    import subprocess
  File "C:\Users\rawal\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 50, in <module>
    import threading
  File "C:\Users\rawal\AppData\Local\Programs\Python\Python310\lib\threading.py", line 6, in <module>
    import functools
  File "C:\Users\rawal\AppData\Local\Programs\Python\Python310\lib\functools.py", line 18, in <module>
    from collections import namedtuple
ImportError: cannot import name 'namedtuple' from partially initialized module 'collections' (most likely due to a circular import) (C:\Users\rawal\AppData\Local\Programs\Python\Python310\lib\collections\__init__.py)

2023-10-28 19:52:40.312 [info] c:\Users\rawal\AppData\Roaming\Blender Foundation\Blender\PyEnv\Scripts\python.exe -m autopep8 --max-line-length=960 -
2023-10-28 19:52:40.312 [info] CWD Server: c:\Users\rawal\AppData\Roaming\Blender Foundation\Blender\3.6\scripts\addons\uvpackmaster3
2023-10-28 19:52:40.358 [info] Could not import runpy module
Traceback (most recent call last):
  File "C:\Users\rawal\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 15, in <module>
    import importlib.util
  File "C:\Users\rawal\AppData\Local\Programs\Python\Python310\lib\importlib\util.py", line 14, in <module>
    from contextlib import contextmanager
  File "C:\Users\rawal\AppData\Local\Programs\Python\Python310\lib\contextlib.py", line 5, in <module>
    from collections import deque
  File "C:\Users\rawal\AppData\Local\Programs\Python\Python310\lib\collections\__init__.py", line 36, in <module>
    from operator import eq as _eq
  File "c:\Users\rawal\AppData\Roaming\Blender Foundation\Blender\3.6\scripts\addons\uvpackmaster3\operator.py", line 20, in <module>
    import subprocess
  File "C:\Users\rawal\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 50, in <module>
    import threading
  File "C:\Users\rawal\AppData\Local\Programs\Python\Python310\lib\threading.py", line 6, in <module>
    import functools
  File "C:\Users\rawal\AppData\Local\Programs\Python\Python310\lib\functools.py", line 18, in <module>
    from collections import namedtuple
ImportError: cannot import name 'namedtuple' from partially initialized module 'collections' (most likely due to a circular import) (C:\Users\rawal\AppData\Local\Programs\Python\Python310\lib\collections\__init__.py)

2023-10-28 19:52:59.826 [info] [Error - 7:52:59 PM] Syntax error in code: Traceback (most recent call last):
  File "c:\Users\rawal\.vscode\extensions\ms-python.autopep8-2023.7.12841011\bundled\tool\lsp_server.py", line 94, in is_python
    ast.parse(code)
  File "C:\Users\rawal\AppData\Local\Programs\Python\Python310\lib\ast.py", line 50, in parse
    return compile(source, filename, mode, flags,
  File "<unknown>", line 82
    def draw_header(self, context):
IndentationError: unexpected indent

2023-10-28 19:52:59.826 [info] [Warn  - 7:52:59 PM] Skipping non python code: c:\Users\rawal\AppData\Roaming\Blender Foundation\Blender\3.6\scripts\addons\uvpackmaster3\ui.py
2023-10-28 19:53:13.904 [info] c:\Users\rawal\AppData\Roaming\Blender Foundation\Blender\PyEnv\Scripts\python.exe -m autopep8 --max-line-length=960 -
2023-10-28 19:53:13.905 [info] CWD Server: c:\Users\rawal\AppData\Roaming\Blender Foundation\Blender\3.6\scripts\addons\uvpackmaster3
2023-10-28 19:53:13.952 [info] Could not import runpy module
Traceback (most recent call last):
  File "C:\Users\rawal\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 15, in <module>
    import importlib.util
  File "C:\Users\rawal\AppData\Local\Programs\Python\Python310\lib\importlib\util.py", line 14, in <module>
    from contextlib import contextmanager
  File "C:\Users\rawal\AppData\Local\Programs\Python\Python310\lib\contextlib.py", line 5, in <module>
    from collections import deque
  File "C:\Users\rawal\AppData\Local\Programs\Python\Python310\lib\collections\__init__.py", line 36, in <module>
    from operator import eq as _eq
  File "c:\Users\rawal\AppData\Roaming\Blender Foundation\Blender\3.6\scripts\addons\uvpackmaster3\operator.py", line 20, in <module>
    import subprocess
  File "C:\Users\rawal\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 50, in <module>
    import threading
  File "C:\Users\rawal\AppData\Local\Programs\Python\Python310\lib\threading.py", line 6, in <module>
    import functools
  File "C:\Users\rawal\AppData\Local\Programs\Python\Python310\lib\functools.py", line 18, in <module>
    from collections import namedtuple
ImportError: cannot import name 'namedtuple' from partially initialized module 'collections' (most likely due to a circular import) (C:\Users\rawal\AppData\Local\Programs\Python\Python310\lib\collections\__init__.py)

Windows 11 22H2
VSCode 1.83.1
autopep8 v2023.7.12841011 Pre-Release
Here's the full log:
autopep8.log

autopep8 didnt work well in vs code

File "c:\Users\Parham\AppData\Local\Programs\Python\Python39\lib\site-packages\autopep8.py", line 419, in
del pycodestyle._checks['logical_line'][pycodestyle.continued_indentation]
KeyError: <function continued_indentation at 0x0000020C8E8F3AF0>
When I used shift + alt + f I received this error!

--max-line-length detect the error but does not format the file.

Hello and thank you for your work on this support for autopep8.

I have the following logs when trying to format a file with a line longer than the parameter provided:

2023-09-06 18:59:35.654 [info] Server: Start requested.
2023-09-06 18:59:36.044 [info] CWD Server: /home/vincent/project
2023-09-06 18:59:36.044 [info] sys.path used to run Server:
   /home/vincent/.vscode-server/extensions/ms-python.autopep8-2023.7.12271005/bundled/libs
   /home/vincent/.vscode-server/extensions/ms-python.autopep8-2023.7.12271005/bundled/tool
   /home/vincent/.conda/envs/project/lib/python39.zip
   /home/vincent/.conda/envs/project/lib/python3.9
   /home/vincent/.conda/envs/project/lib/python3.9/lib-dynload
   /home/vincent/.conda/envs/project/lib/python3.9/site-packages
   /home/vincent/project/src
2023-09-06 18:59:36.044 [info] PYTHONPATH env variable used to run Server:
   /home/vincent/.vscode-server/extensions/ms-python.autopep8-2023.7.12271005/bundled/libs:
2023-09-06 18:59:36.044 [info] Settings used to run Server:
[
    {
        "cwd": "/home/vincent/project",
        "workspace": "file:///home/vincent/project",
        "args": [
            "-v",
            "--experimental",
            "--max-line-length",
            "120"
        ],
        "path": [],
        "interpreter": [
            "/home/vincent/.conda/envs/project/bin/python"
        ],
        "importStrategy": "useBundled",
        "showNotifications": "off"
    }
]

2023-09-06 18:59:36.044 [info] Global settings:
{
    "cwd": "/home/vincent",
    "workspace": "/home/vincent",
    "args": [],
    "path": [],
    "interpreter": [],
    "importStrategy": "useBundled",
    "showNotifications": "off"
}

2023-09-06 18:59:36.046 [info] /home/vincent/.conda/envs/project/bin/python -m autopep8 --version
2023-09-06 18:59:36.046 [info] CWD Server: /home/vincent/project
2023-09-06 18:59:36.088 [info] Version info for formatter running for /home/vincent/project:
autopep8 2.0.2 (pycodestyle: 2.10.0)

2023-09-06 18:59:36.089 [info] SUPPORTED autopep8>=1.7.0
FOUND autopep8==2.0.2

2023-09-06 18:59:36.089 [info] /home/vincent/.conda/envs/project/bin/python -m autopep8 --version
2023-09-06 18:59:36.089 [info] CWD Server: /home/vincent/project
2023-09-06 18:59:36.131 [info] Version info for formatter running for /home/vincent/project:
autopep8 2.0.2 (pycodestyle: 2.10.0)

2023-09-06 18:59:36.131 [info] SUPPORTED autopep8>=1.7.0
FOUND autopep8==2.0.2

2023-09-06 18:59:36.472 [info] [Trace - 6:59:36 PM] Sending notification 'textDocument/didOpen'.
2023-09-06 18:59:36.472 [info] [Trace - 6:59:36 PM] Sending notification 'textDocument/didClose'.
2023-09-06 18:59:42.428 [info] [Trace - 6:59:42 PM] Sending request 'textDocument/formatting - (1)'.
2023-09-06 18:59:42.433 [info] [Trace - 6:59:42 PM] Received notification 'window/logMessage'.
2023-09-06 18:59:42.433 [info] /home/vincent/.conda/envs/project/bin/python -m autopep8 -v --experimental --max-line-length 120 -
2023-09-06 18:59:42.433 [info] [Trace - 6:59:42 PM] Received notification 'window/logMessage'.
2023-09-06 18:59:42.433 [info] CWD Server: /home/vincent/project
2023-09-06 18:59:42.494 [info] [Trace - 6:59:42 PM] Received notification 'window/logMessage'.
2023-09-06 18:59:42.494 [info] --->  1 issue(s) to fix {'E501': {24}}

2023-09-06 18:59:42.495 [info] [Trace - 6:59:42 PM] Received response 'textDocument/formatting - (1)' in 66ms.
2023-09-06 18:59:42.758 [info] [Trace - 6:59:42 PM] Sending notification 'textDocument/didChange'.
2023-09-06 19:00:02.883 [info] [Trace - 7:00:02 PM] Sending notification 'textDocument/didChange'.
2023-09-06 19:00:03.493 [info] [Trace - 7:00:03 PM] Sending notification 'textDocument/didChange'.
2023-09-06 19:00:05.735 [info] [Trace - 7:00:05 PM] Sending request 'textDocument/formatting - (2)'.
2023-09-06 19:00:05.738 [info] [Trace - 7:00:05 PM] Received notification 'window/logMessage'.
2023-09-06 19:00:05.738 [info] /home/vincent/.conda/envs/project/bin/python -m autopep8 -v --experimental --max-line-length 120 -
2023-09-06 19:00:05.738 [info] [Trace - 7:00:05 PM] Received notification 'window/logMessage'.
2023-09-06 19:00:05.738 [info] CWD Server: /home/vincent/project
2023-09-06 19:00:05.797 [info] [Trace - 7:00:05 PM] Received notification 'window/logMessage'.
2023-09-06 19:00:05.797 [info] --->  1 issue(s) to fix {'E501': {24}}

2023-09-06 19:00:05.799 [info] [Trace - 7:00:05 PM] Received response 'textDocument/formatting - (2)' in 64ms.
2023-09-06 19:00:06.080 [info] [Trace - 7:00:06 PM] Sending notification 'textDocument/didChange'.
2023-09-06 19:00:18.261 [info] [Trace - 7:00:18 PM] Sending notification 'textDocument/didChange'.
2023-09-06 19:00:18.691 [info] [Trace - 7:00:18 PM] Sending notification 'textDocument/didChange'.
2023-09-06 19:00:26.749 [info] No interpreter found from setting autopep8.interpreter
2023-09-06 19:00:26.749 [info] Getting interpreter from ms-python.python extension for workspace /home/vincent/project
2023-09-06 19:00:26.754 [info] Interpreter from ms-python.python extension for /home/vincent/project: /home/vincent/.conda/envs/project/bin/python
2023-09-06 19:00:26.755 [info] Server: Stop requested
2023-09-06 19:00:26.767 [info] No interpreter found from setting autopep8.interpreter
2023-09-06 19:00:26.767 [info] Getting interpreter from ms-python.python extension for workspace /home/vincent/project
2023-09-06 19:00:26.768 [info] Interpreter from ms-python.python extension for /home/vincent/project: /home/vincent/.conda/envs/project/bin/python
2023-09-06 19:00:26.775 [info] Server run command: /home/vincent/.conda/envs/project/bin/python /home/vincent/.vscode-server/extensions/ms-python.autopep8-2023.7.12271005/bundled/tool/lsp_server.py

However the formatting issue is not being fix. Other issue like removing additional space works correctly.
Am I doing something wrong with the settings ? I tried various set up and could not make it work.

Unclear instructions for configuring .vscode\settings.json

I find the following instructions unclear:

Once installed in Visual Studio Code, "autopep8" will be available as a formatter for python files. Please select "autopep8" (extension id:ms-python.autopep8) as the default formatter. You can do this either by using the context menu (right click on a open python file in the editor) and select "Format Document With...", or you can add the following to your settings:

  "[python]": {
    "editor.defaultFormatter": "ms-python.autopep8"
  }

and change the following, if set:

  "python.formatting.provider": "none"

Specifically, I find the last part unclear as it raises an unanswered question: "Change it to what?" If the intention is to remove the line of code, then a better choice of words would be "and delete the following, if set" or "and remove the following, if set". Kindly clarify.

I also felt that this would be more of a discussion than an issue, but I think discussions aren't enabled yet for the Autopep8 repository.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.