microsoft/vscode-autopep8

Formatting not working

Rawalanche opened this issue · 7 comments

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

Can you try using a Python interpreter outside of Blender? It looks like Blender modifies their copy of Python enough to not have everything working as autopep8 wants (e.g. "Could not import runpy module").

@Rawalanche Another option is to set autopep8.path to the autopep8 binary.

@brettcannon @karthiknadig
Hi, I am actually not running any custom python. I am just using fake-bpy module to get autocomplete for Blender development in VSCode, but I am using just regular python in a virtual environment. I am 100% sure autopep8 formatting did work previously with this exact setup, so I am confused.

@Rawalanche Can you check the begining of the logs to see how the sys.path looks like? And the settings being passed to the extension.

@Rawalanche Can you check the begining of the logs to see how the sys.path looks like? And the settings being passed to the extension.

Hi, it should be in the attached log file (it's hard to spot, at the bottom of the report), looks like this:

2023-10-28 17:58:52.662 [info] sys.path used to run Server:
   c:\Users\rawal\.vscode\extensions\ms-python.autopep8-2023.7.12841011\bundled\libs
   c:\Users\rawal\.vscode\extensions\ms-python.autopep8-2023.7.12841011\bundled\tool
   C:\Users\rawal\AppData\Local\Programs\Python\Python310\python310.zip
   C:\Users\rawal\AppData\Local\Programs\Python\Python310\DLLs
   C:\Users\rawal\AppData\Local\Programs\Python\Python310\lib
   C:\Users\rawal\AppData\Local\Programs\Python\Python310
   c:\Users\rawal\AppData\Roaming\Blender Foundation\Blender\PyEnv
   c:\Users\rawal\AppData\Roaming\Blender Foundation\Blender\PyEnv\lib\site-packages

@Rawalanche From what I can see, any script that tries to use runpy will fail in this environment. We have not published a pre-release for autopep8 extension since oct 11. If this started happening recently (in the last few days), then something else in the environment must have changed.

In these cases you can try and have it launch autopep8 using the autopep8.path (by installing it in your environment)

Because we have not heard back with the information we requested, we are closing this issue for now. If you are able to provide the info later on then we will be happy to re-open this issue to pick up where we left off.