microsoft / vscode-black-formatter

Formatting support for Python using the Black formatter
https://marketplace.visualstudio.com/items?itemName=ms-python.black-formatter
MIT License
159 stars 37 forks source link

Black formatter does not format symlinked files (Black 24.1.1) #444

Closed de-ranit closed 9 months ago

de-ranit commented 10 months ago

Today, my VS Code got updated to the following version: Version: 1.86.0 (Universal) Commit: 05047486b6df5eb8d44b2ecd70ea3bdf775fd937 Date: 2024-01-31T10:29:15.765Z Electron: 27.2.3 ElectronBuildId: 26495564 Chromium: 118.0.5993.159 Node.js: 18.17.1 V8: 11.8.172.18-electron.0 OS: Darwin arm64 23.2.0

I have Black Foramatter v2024.0.0.

I am not able to format my Python code after the VS Code update. The output log is following:

2024-02-02 14:06:12.247 [info] [Trace - 2:06:12 PM] Sending request 'textDocument/formatting - (1)'.
2024-02-02 14:06:12.263 [info] [Trace - 2:06:12 PM] Received notification 'window/logMessage'.
2024-02-02 14:06:12.263 [info] path/to/dir/miniconda3/envs/my_env/bin/python -m black --stdin-filename path/to/code/my_code.py -
2024-02-02 14:06:12.264 [info] [Trace - 2:06:12 PM] Received notification 'window/logMessage'.
2024-02-02 14:06:12.264 [info] CWD formatter: /path/path/path
2024-02-02 14:06:12.328 [info] [Trace - 2:06:12 PM] Received notification 'window/logMessage'.
2024-02-02 14:06:12.328 [info] No Python files are present to be formatted. Nothing to do 😴

But running black my_code.py works perfectly fine. It doesn't work only when I right click on my code and select format document with -> black formatter. Black formatter used to work perfectly before the VS Code update.

karthiknadig commented 10 months ago

What is the version of black that you have in your terminal? can you update it to match the latest from the extension. also the equivalent way of launching it is this:

cat path/to/code/my_code.py | path/to/dir/miniconda3/envs/my_env/bin/python -m black --stdin-filename path/to/code/my_code.py -
de-ranit commented 10 months ago

Thank you very much. The version of black, I had in terminal is black, 23.9.1 (compiled: yes) Python (CPython) 3.10.13. Updating black to 24.1.1 solved my issue.

de-ranit commented 10 months ago

The problem is back again after I restarted VS Code the next day. In terminal, now I also have black, 24.1.1 (compiled: yes) Python (CPython) 3.10.13

stefmf commented 10 months ago

I am also having this issue. No formatter is working in vscode for python files specifically.

MarcosRodrigoT commented 10 months ago

I am also facing this issue. I have been using this extension for a while without ever installing the black python package in the virtual environment. Installing the latest version of this package did not resolve the issue.

Of course, running black my_code.py does work, but the extension does not. I have tried resetting the black formatter extension settings to default and restarting the black server (through the Command Palette CTRL+SHIFT+P > Black Formatter: Restart Server) to no avail.

MarcosRodrigoT commented 10 months ago

I downgraded the black formatter extension to the previous version (v2023.6.0) and it solved the issue.

karthiknadig commented 10 months ago

Just to verify in you run the following command do you see the formatted output?

cat path/to/code/my_code.py | path/to/env/bin/python -m black --stdin-filename path/to/code/my_code.py -
karthiknadig commented 10 months ago

Which command or short cut are you using to trigger formatting: image

Would it be possible to capture a gif or provide a minimal repro.

The main difference between 2023.6.0 and 2024.0.0 is the version of black that is shipped by default, and support for selection formatting.

karthiknadig commented 10 months ago

This message: image

comes from black itself. https://github.com/psf/black/blob/e026c93888f91a47a9c9f4e029f3eb07d96375e6/src/black/__init__.py#L680-L686

This is looking like a bug in the latest version of black. If we can find a minimal repo, or pattern it would be useful when filing this on black.

de-ranit commented 10 months ago

Just to verify in you run the following command do you see the formatted output?

cat path/to/code/my_code.py | path/to/env/bin/python -m black --stdin-filename path/to/code/my_code.py -

Yes, it works and I get the formatted output

de-ranit commented 10 months ago

Which command or short cut are you using to trigger formatting: image

Would it be possible to capture a gif or provide a minimal repro.

The main difference between 2023.6.0 and 2024.0.0 is the version of black that is shipped by default, and support for selection formatting.

https://github.com/microsoft/vscode-black-formatter/assets/145925975/baf2706d-40d6-409c-86c6-f6a5d1f17a69

karthiknadig commented 10 months ago

Unfortunately I am not able to repro this locally:

https://github.com/microsoft/vscode-black-formatter/assets/3840081/4c1615b4-5ffd-4365-bfa3-3a82e7415d0b

Can you provide more detail on the environment you are using like version of python, packages installed etc.

stefmf commented 10 months ago

None of the formatters are working. Not sure what else to try.

https://github.com/microsoft/vscode-black-formatter/assets/84077914/1c46d4b6-16ca-40dc-806f-34a4cc733629

side2k commented 10 months ago

After update to 1.86.0, this extension stopped working with non-bundled black version. In local environment, I have black 22.6.0, extension description says it needs a minimum of 22.3.0 - so it should be ok. But I've also tried to update to 24.1.1. This is what I see in Output=>Black Formatter:

Log with errors ```log 2024-02-06 12:29:06.154 [info] Name: Black Formatter 2024-02-06 12:29:06.154 [info] Module: black 2024-02-06 12:29:06.154 [info] Default formatter is set to ms-python.black-formatter for workspace /my/project/dir 2024-02-06 12:29:06.154 [info] Python extension loading 2024-02-06 12:29:06.154 [info] Waiting for interpreter from python extension. 2024-02-06 12:29:06.154 [info] No interpreter found from setting black-formatter.interpreter 2024-02-06 12:29:06.154 [info] Getting interpreter from ms-python.python extension for workspace /my/project/dir 2024-02-06 12:29:06.154 [info] Python extension loaded 2024-02-06 12:29:06.154 [info] Interpreter from ms-python.python extension for /my/project/dir: /my/project/dir/.venv/bin/python 2024-02-06 12:29:06.154 [info] No interpreter found from setting black-formatter.interpreter 2024-02-06 12:29:06.154 [info] Getting interpreter from ms-python.python extension for workspace /my/project/dir 2024-02-06 12:29:06.154 [info] Interpreter from ms-python.python extension for /my/project/dir: /my/project/dir/.venv/bin/python 2024-02-06 12:29:06.154 [info] Server run command: /my/project/dir/.venv/bin/python /my/home/dir/.vscode/extensions/ms-python.black-formatter-2024.1.10361006/bundled/tool/lsp_server.py 2024-02-06 12:29:06.154 [info] Server: Start requested. 2024-02-06 12:29:06.340 [info] Unable to deserialize message Traceback (most recent call last): File "/my/home/dir/.vscode/extensions/ms-python.black-formatter-2024.1.10361006/bundled/libs/pygls/protocol/json_rpc.py", line 330, in _deserialize_message return self._converter.structure(data, request_type) File "/my/home/dir/.vscode/extensions/ms-python.black-formatter-2024.1.10361006/bundled/libs/cattrs/converters.py", line 332, in structure return self._structure_func.dispatch(cl)(obj, cl) File "/my/home/dir/.vscode/extensions/ms-python.black-formatter-2024.1.10361006/bundled/libs/cattrs/dispatch.py", line 112, in _dispatch res = self._function_dispatch.dispatch(typ) File "/my/home/dir/.vscode/extensions/ms-python.black-formatter-2024.1.10361006/bundled/libs/cattrs/dispatch.py", line 62, in dispatch return handler(typ) File "/my/home/dir/.vscode/extensions/ms-python.black-formatter-2024.1.10361006/bundled/libs/lsprotocol/_hooks.py", line 1233, in _with_custom_structure return cattrs.gen.make_dict_structure_fn(cls, converter, **attributes) File "/my/home/dir/.vscode/extensions/ms-python.black-formatter-2024.1.10361006/bundled/libs/cattrs/gen/__init__.py", line 355, in make_dict_structure_fn ian = a.alias AttributeError: 'Attribute' object has no attribute 'alias' Error receiving data Traceback (most recent call last): File "/my/home/dir/.vscode/extensions/ms-python.black-formatter-2024.1.10361006/bundled/libs/pygls/protocol/json_rpc.py", line 330, in _deserialize_message return self._converter.structure(data, request_type) File "/my/home/dir/.vscode/extensions/ms-python.black-formatter-2024.1.10361006/bundled/libs/cattrs/converters.py", line 332, in structure return self._structure_func.dispatch(cl)(obj, cl) File "/my/home/dir/.vscode/extensions/ms-python.black-formatter-2024.1.10361006/bundled/libs/cattrs/dispatch.py", line 112, in _dispatch res = self._function_dispatch.dispatch(typ) File "/my/home/dir/.vscode/extensions/ms-python.black-formatter-2024.1.10361006/bundled/libs/cattrs/dispatch.py", line 62, in dispatch return handler(typ) File "/my/home/dir/.vscode/extensions/ms-python.black-formatter-2024.1.10361006/bundled/libs/lsprotocol/_hooks.py", line 1233, in _with_custom_structure return cattrs.gen.make_dict_structure_fn(cls, converter, **attributes) File "/my/home/dir/.vscode/extensions/ms-python.black-formatter-2024.1.10361006/bundled/libs/cattrs/gen/__init__.py", line 355, in make_dict_structure_fn ian = a.alias AttributeError: 'Attribute' object has no attribute 'alias' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/my/home/dir/.vscode/extensions/ms-python.black-formatter-2024.1.10361006/bundled/libs/pygls/protocol/json_rpc.py", line 443, in data_received self._data_received(data) File "/my/home/dir/.vscode/extensions/ms-python.black-formatter-2024.1.10361006/bundled/libs/pygls/protocol/json_rpc.py", line 475, in _data_received json.loads( File "/usr/lib/python3.10/json/__init__.py", line 359, in loads return cls(**kw).decode(s) File "/usr/lib/python3.10/json/decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python3.10/json/decoder.py", line 353, in raw_decode obj, end = self.scan_once(s, idx) File "/my/home/dir/.vscode/extensions/ms-python.black-formatter-2024.1.10361006/bundled/libs/pygls/protocol/json_rpc.py", line 348, in _deserialize_message raise JsonRpcInternalError() from exc pygls.exceptions.JsonRpcInternalError: Internal Error ```

The log above is for black 22.6.0. For 24.1.1 it is the same. However, the moment I switch black-formatter.importStrategy from fromEnvironment to useBundled it is all fixed, with this output in the log:

Log with success ```log 2024-02-06 12:33:53.519 [info] No interpreter found from setting black-formatter.interpreter 2024-02-06 12:33:53.519 [info] Getting interpreter from ms-python.python extension for workspace /my/project/dir 2024-02-06 12:33:53.520 [info] Interpreter from ms-python.python extension for /my/project/dir: /my/project/dir/.venv/bin/python 2024-02-06 12:33:53.520 [info] No interpreter found from setting black-formatter.interpreter 2024-02-06 12:33:53.520 [info] Getting interpreter from ms-python.python extension for workspace /my/project/dir 2024-02-06 12:33:53.522 [info] Interpreter from ms-python.python extension for /my/project/dir: /my/project/dir/.venv/bin/python 2024-02-06 12:33:53.525 [info] Server run command: /my/project/dir/.venv/bin/python /my/home/dir/.vscode/extensions/ms-python.black-formatter-2024.1.10361006/bundled/tool/lsp_server.py 2024-02-06 12:33:53.526 [info] Server: Start requested. 2024-02-06 12:33:53.909 [info] CWD Server: /my/project/dir 2024-02-06 12:33:53.910 [info] Settings used to run Server: [ { "cwd": "/my/project/dir", "workspace": "file:///my/project/dir", "args": [], "path": [], "interpreter": [ "/my/project/dir/.venv/bin/python" ], "importStrategy": "useBundled", "showNotifications": "off" } ] 2024-02-06 12:33:53.910 [info] Global settings: { "cwd": "/my/home/dir", "workspace": "/my/home/dir", "args": [], "path": [], "interpreter": [], "importStrategy": "useBundled", "showNotifications": "off" } 2024-02-06 12:33:53.910 [info] sys.path used to run Server: /my/home/dir/.vscode/extensions/ms-python.black-formatter-2024.1.10361006/bundled/libs /my/home/dir/.vscode/extensions/ms-python.black-formatter-2024.1.10361006/bundled/tool /usr/lib/python310.zip /usr/lib/python3.10 /usr/lib/python3.10/lib-dynload /my/project/dir/.venv/lib/python3.10/site-packages 2024-02-06 12:33:53.913 [info] /my/project/dir/.venv/bin/python -m black --version 2024-02-06 12:33:53.913 [info] CWD formatter: /my/project/dir 2024-02-06 12:33:54.039 [info] Version info for formatter running for /my/project/dir: black, 24.1.1 (compiled: no) Python (CPython) 3.10.12 2024-02-06 12:33:54.039 [info] SUPPORTED black>=22.3.0 FOUND black==24.1.1 ```

And we can't easily switch project to the latest black version, unfortunately. Any help would be appreciated.

My system details **My vscode**: ``` Version: 1.86.0 Commit: 05047486b6df5eb8d44b2ecd70ea3bdf775fd937 Date: 2024-01-31T10:27:46.147Z Electron: 27.2.3 ElectronBuildId: 26495564 Chromium: 118.0.5993.159 Node.js: 18.17.1 V8: 11.8.172.18-electron.0 OS: Linux x64 5.15.0-58-generic snap ``` **OS**: `Ubuntu 22.04.3 LTS` **virtualenv Python**: `3.10` **Installed packages**: ``` aiohttp==3.8.3 aiosignal==1.3.1 amqp==5.1.1 apispec==5.2.2 apispec-oneofschema==3.0.0 appnope==0.1.3 arrow==1.2.1 asgiref==3.7.2 async-timeout==4.0.2 attrs==22.1.0 autopep8==1.7.0 backcall==0.2.0 beautifulsoup4==4.7.1 billiard==3.6.4.0 black==22.6.0 bleach==6.0.0 boto3==1.20.49 botocore==1.23.49 build==1.0.3 celery==5.2.7 certifi==2019.3.9 cffi==1.15.0 charset-normalizer==2.0.7 ciso8601==2.2.0 classify-imports==4.2.0 click==8.1.3 click-didyoumean==0.3.0 click-plugins==1.1.1 click-repl==0.2.0 clickhouse-driver==0.1.5 colorlog==6.6.0 coverage==6.1.2 cron-descriptor==1.3.0 cryptography==35.0.0 cyrtranslit==1.0 decorator==5.1.0 defusedxml==0.7.1 Deprecated==1.2.14 Django==4.2.2 django-admin-rangefilter==0.9.0 django-admin-sortable2==2.1.8 django-ajax-selects==2.2.0 django-celery-beat==2.5.0 django-classy-tags==2.0.0 django-elasticsearch-dsl==7.2.2 django-gfklookupwidget==1.0.9 django-impersonate==1.8.1 django-jet-reboot==1.3.3 django-js-asset==1.2.2 django-mptt==0.13.4 django-mysql==3.12.0 django-nyt==1.3 django-oauth-toolkit==1.7.0 django-phonenumber-field==7.0.2 django-querycount==0.7.0 django-redis==5.2.0 django-robots==5.0 django-sekizai==2.0.0 django-serializer==1.2.1 django-silk==5.0.3 django-solo==2.0.0 django-storages==1.13 django-timezone-field==5.0 django-tinymce==3.4.0 django-user-agents==0.4.0 django-webpack-loader==1.7.0 docxtpl==0.11.5 elasticsearch==7.17.6 elasticsearch-dsl==7.4.0 flake8==7.0.0 flake8-pyi==24.1.0 flower==1.2.0 freezegun==1.1.0 frozenlist==1.3.3 gprof2dot==2022.7.29 h11==0.14.0 html5lib==1.1 humanize==4.4.0 icalendar==5.0.4 idna==3.3 influxdb-client==1.31.0 iniconfig==2.0.0 ipython==7.27.0 iyzipay==1.0.32 jedi==0.18.0 Jinja2==3.0.2 jmespath==0.10.0 jsonrpcclient==4.0.1 jwcrypto==1.0 kombu==5.2.4 lxml==4.6.4 Markdown==3.3.7 MarkupSafe==2.0.1 marshmallow==3.17.0 marshmallow-oneofschema==2.1.0 matplotlib-inline==0.1.3 mccabe==0.7.0 more-itertools==9.0.0 multidict==6.0.3 mypy-extensions==1.0.0 mysqlclient==2.1.1 oauthlib==3.1.1 orjson==3.8.14 otus-radomizer @ git+https://git@github.com/otus-opensource/randomizer.git@8fcad388fb77e46d1ff9e358e0e6367ea6f8b440 packaging==23.2 parso==0.8.2 pathspec==0.12.1 pexpect==4.5.0 phonenumberslite==8.12.46 pickleshare==0.7.5 Pillow==7.2.0 pip-tools==6.13.0 platformdirs==4.1.0 pluggy==1.3.0 prometheus-client==0.8.0 prompt-toolkit==3.0.22 ptyprocess==0.7.0 py==1.11.0 pycodestyle==2.9.1 pycparser==2.20 pydantic==1.9.0 pyflakes==3.2.0 Pygments==2.2.0 PyJWT==2.0.1 pyparsing==2.4.7 pyproject_hooks==1.0.0 pytest==6.2.5 pytest-django==4.4.0 pytest-lazy-fixture==0.6.3 pytest-responses==0.5.0 python-crontab==2.6.0 python-dateutil==2.8.0 python-docx==0.8.11 python3-openid==3.2.0 pytz==2021.3 PyYAML==6.0.1 redis==4.6.0 requests==2.28.2 requests-oauthlib==1.3.0 responses==0.16.0 Rx==3.2.0 s3transfer==0.5.1 sentry-sdk==1.11.1 six==1.16.0 social-auth-app-django==5.0.0 social-auth-core==4.1.0 sorl-thumbnail==12.9.0 soupsieve==2.3 sqlparse==0.4.2 suds-community==0.8.5 tinycss2==1.1.1 toml==0.10.2 tomli==2.0.1 tornado==6.2 tqdm==4.32.1 traitlets==5.1.1 transliterate==1.10.2 typing_extensions==4.6.2 tzdata==2022.7 tzlocal==2.1 ua-parser==0.10.0 urllib3==1.26.11 user-agents==2.2.0 uvicorn==0.22.0 uvloop==0.17.0 vine==5.0.0 Wand==0.5.3 wcwidth==0.2.5 webencodings==0.5.1 wiki==0.10 wrapt==1.13.3 XlsxWriter==3.0.1 yarl==1.8.2 ```
de-ranit commented 10 months ago

Unfortunately I am not able to repro this locally:

formatting_with_black_latest.mp4 Can you provide more detail on the environment you are using like version of python, packages installed etc.

OS: VS Code running on Mac (M1 chip) OS Somona 14.2.1 (23C71) The codes are on a remote server connected using Remote - SSH v0.108.0 OS on the remote server is CentOS Linux 8.

VS Code:

Version: 1.86.0 (Universal)
Commit: 05047486b6df5eb8d44b2ecd70ea3bdf775fd937
Date: 2024-01-31T10:29:15.765Z
Electron: 27.2.3
ElectronBuildId: 26495564
Chromium: 118.0.5993.159
Node.js: 18.17.1
V8: 11.8.172.18-electron.0
OS: Darwin arm64 23.2.0

VS Code extensions installed on remote server

  1. Black Formatter v2024.0.0
  2. Cython VSCode v0.3.10
  3. GitHub Copilot v1.156.0
  4. GitHub Copilot Chat v0.12.0
  5. GitLens — Git supercharged v14.7.0
  6. IntelliCode v1.2.30
  7. IntelliCode API Usage Examples v0.2.8
  8. isort v2023.10.1
  9. Jupyter v2024.1.0
  10. Jupyter Cell Tags v0.1.8
  11. Jupyter Notebook Renderers v1.0.17
  12. Jupyter Slide Show v0.1.5
  13. Pylance v2023.12.1
  14. Pylint v2023.10.1
  15. Python v2024.0.0
  16. Python Debugger v2024.0.0
  17. Jupyter Keymap v1.1.2
  18. Rainbow CSV v3.11.0

In user settings.json

"python.defaultInterpreterPath": "/path/to/miniconda3/envs/default_env/bin/python",
    "terminal.integrated.inheritEnv": false,

    "python.formatting.provider": "black",
    "[python]": {
        "editor.defaultFormatter": "ms-python.black-formatter",
    },

Conda environment and packages

name: my_env
channels:
  - anaconda
  - conda-forge
  - defaults
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - abseil-cpp=20211102.0=hd4dd3e8_0
  - archspec=0.2.1=pyhd3eb1b0_0
  - arrow-cpp=11.0.0=h374c478_2
  - asciitree=0.3.3=py_2
  - astroid=2.14.2=py310h06a4308_0
  - asttokens=2.0.5=pyhd3eb1b0_0
  - aws-c-common=0.6.8=h5eee18b_1
  - aws-c-event-stream=0.1.6=h6a678d5_6
  - aws-checksums=0.1.11=h5eee18b_2
  - aws-sdk-cpp=1.8.185=h721c034_1
  - backcall=0.2.0=pyhd3eb1b0_0
  - blas=1.0=mkl
  - blosc=1.21.3=h6a678d5_0
  - bokeh=3.3.0=py310h2f386ee_0
  - boltons=23.0.0=py310h06a4308_0
  - boost-cpp=1.82.0=hdb19cb5_2
  - bottleneck=1.3.5=py310ha9d4c09_0
  - branca=0.7.1=pyhd8ed1ab_0
  - brotli=1.0.9=h5eee18b_7
  - brotli-bin=1.0.9=h5eee18b_7
  - brotli-python=1.0.9=py310h6a678d5_7
  - bzip2=1.0.8=h7b6447c_0
  - c-ares=1.19.1=h5eee18b_0
  - ca-certificates=2024.2.2=hbcca054_0
  - cairo=1.16.0=hb05425b_5
  - cffi=1.16.0=py310h5eee18b_0
  - cfitsio=3.470=hb418390_7
  - cftime=1.6.2=py310ha9d4c09_0
  - click=8.1.7=py310h06a4308_0
  - click-plugins=1.1.1=py_0
  - cligj=0.7.2=pyhd8ed1ab_1
  - cloudpickle=2.2.1=py310h06a4308_0
  - cmcrameri=1.8=pyhd8ed1ab_0
  - colorama=0.4.6=py310h06a4308_0
  - comm=0.1.2=py310h06a4308_0
  - conda=24.1.0=py310h06a4308_0
  - conda-libmamba-solver=24.1.0=pyhd3eb1b0_0
  - conda-package-handling=2.2.0=py310h06a4308_0
  - conda-package-streaming=0.9.0=py310h06a4308_0
  - contourpy=1.2.0=py310hdb19cb5_0
  - cryptography=41.0.7=py310hdda0065_0
  - cycler=0.11.0=pyhd3eb1b0_0
  - cyrus-sasl=2.1.28=h52b45da_1
  - cytoolz=0.12.2=py310h5eee18b_0
  - dask=2023.9.3=pyhd8ed1ab_0
  - dask-core=2023.9.3=pyhd8ed1ab_0
  - dbus=1.13.18=hb2f20db_0
  - debugpy=1.6.7=py310h6a678d5_0
  - decorator=5.1.1=pyhd3eb1b0_0
  - dill=0.3.7=py310h06a4308_0
  - distributed=2023.9.3=pyhd8ed1ab_0
  - distro=1.8.0=py310h06a4308_0
  - entrypoints=0.4=py310h06a4308_0
  - exceptiongroup=1.0.4=py310h06a4308_0
  - executing=0.8.3=pyhd3eb1b0_0
  - expat=2.5.0=h6a678d5_0
  - fasteners=0.16.3=pyhd3eb1b0_0
  - fiona=1.9.5=py310h1128e8f_0
  - fmt=9.1.0=hdb19cb5_0
  - folium=0.15.1=pyhd8ed1ab_0
  - fontconfig=2.14.1=h4c34cd2_2
  - fonttools=4.25.0=pyhd3eb1b0_0
  - freetype=2.12.1=h4a9f257_0
  - freexl=2.0.0=hf309648_0
  - fsspec=2023.10.0=py310h06a4308_0
  - gdal=3.6.2=py310h0daa840_4
  - geopandas=0.14.3=pyhd8ed1ab_0
  - geopandas-base=0.14.3=pyha770c72_0
  - geos=3.8.0=he1b5a44_1
  - geotiff=1.7.0=h2a26cda_3
  - gflags=2.2.2=he6710b0_0
  - giflib=5.2.1=h5eee18b_3
  - glib=2.69.1=he621ea3_2
  - glog=0.5.0=h2531618_0
  - grpc-cpp=1.48.2=he1ff14a_1
  - gst-plugins-base=1.14.1=h6a678d5_1
  - gstreamer=1.14.1=h5eee18b_1
  - hdf4=4.2.13=h3ca952b_2
  - hdf5=1.12.1=h2b7332f_3
  - heapdict=1.0.1=pyhd3eb1b0_0
  - icu=73.1=h6a678d5_0
  - idna=3.4=py310h06a4308_0
  - importlib-metadata=6.0.0=py310h06a4308_0
  - importlib_metadata=6.0.0=hd3eb1b0_0
  - intel-openmp=2023.1.0=hdb19cb5_46306
  - ipykernel=6.25.0=py310h2f386ee_0
  - ipython=8.15.0=py310h06a4308_0
  - ipywidgets=8.0.4=py310h06a4308_0
  - isort=5.9.3=pyhd3eb1b0_0
  - jedi=0.18.1=py310h06a4308_1
  - jinja2=3.1.2=py310h06a4308_0
  - joblib=1.2.0=py310h06a4308_0
  - jpeg=9e=h5eee18b_1
  - json-c=0.16=hc379101_0
  - jsonpatch=1.32=pyhd3eb1b0_0
  - jsonpointer=2.1=pyhd3eb1b0_0
  - jupyter_client=8.6.0=py310h06a4308_0
  - jupyter_core=5.5.0=py310h06a4308_0
  - jupyterlab_widgets=3.0.9=py310h06a4308_0
  - kealib=1.5.0=hd940352_1
  - kiwisolver=1.4.4=py310h6a678d5_0
  - krb5=1.20.1=h143b758_1
  - lazy-object-proxy=1.6.0=py310h7f8727e_0
  - lcms2=2.12=h3be6417_0
  - ld_impl_linux-64=2.38=h1181459_1
  - lerc=3.0=h295c915_0
  - libarchive=3.6.2=h6ac8c49_2
  - libboost=1.82.0=h109eef0_2
  - libbrotlicommon=1.0.9=h5eee18b_7
  - libbrotlidec=1.0.9=h5eee18b_7
  - libbrotlienc=1.0.9=h5eee18b_7
  - libclang=14.0.6=default_hc6dbbc7_1
  - libclang13=14.0.6=default_he11475f_1
  - libcups=2.4.2=h2d74bed_1
  - libcurl=8.4.0=h251f7ec_1
  - libdeflate=1.17=h5eee18b_1
  - libedit=3.1.20230828=h5eee18b_0
  - libev=4.33=h7f8727e_1
  - libevent=2.1.12=hdbd6064_1
  - libffi=3.4.4=h6a678d5_0
  - libgcc-ng=11.2.0=h1234567_1
  - libgdal=3.6.2=heb138ec_4
  - libgfortran-ng=11.2.0=h00389a5_1
  - libgfortran5=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libiconv=1.17=h166bdaf_0
  - libkml=1.3.0=h096b73e_7
  - libllvm14=14.0.6=hdb19cb5_3
  - libmamba=1.5.6=haf1ee3a_0
  - libmambapy=1.5.6=py310h2dafd23_0
  - libnetcdf=4.8.1=h14805e7_4
  - libnghttp2=1.57.0=h2d74bed_0
  - libpng=1.6.39=h5eee18b_0
  - libpq=12.15=hdbd6064_1
  - libprotobuf=3.20.3=he621ea3_0
  - libsodium=1.0.18=h7b6447c_0
  - libsolv=0.7.24=he621ea3_0
  - libspatialindex=1.9.3=h9c3ff4c_4
  - libspatialite=5.1.0=h01e95a1_0
  - libssh2=1.10.0=hdbd6064_2
  - libstdcxx-ng=11.2.0=h1234567_1
  - libthrift=0.15.0=h1795dd8_2
  - libtiff=4.5.1=h6a678d5_0
  - libuuid=1.41.5=h5eee18b_0
  - libwebp=1.3.2=h11a3e52_0
  - libwebp-base=1.3.2=h5eee18b_0
  - libxcb=1.15=h7f8727e_0
  - libxkbcommon=1.0.1=h5eee18b_1
  - libxml2=2.10.4=hf1b16e4_1
  - libzip=1.8.0=h6ac8c49_1
  - llvmlite=0.41.0=py310he621ea3_0
  - locket=1.0.0=py310h06a4308_0
  - lz4=4.3.2=py310h5eee18b_0
  - lz4-c=1.9.4=h6a678d5_0
  - mapclassify=2.6.1=pyhd8ed1ab_0
  - markupsafe=2.1.1=py310h7f8727e_0
  - matplotlib=3.7.2=py310h06a4308_0
  - matplotlib-base=3.7.2=py310h1128e8f_0
  - matplotlib-inline=0.1.6=py310h06a4308_0
  - mccabe=0.7.0=pyhd3eb1b0_0
  - menuinst=2.0.2=py310h06a4308_0
  - minizip=4.0.3=hf59b114_0
  - mizani=0.9.2=py310h06a4308_0
  - mkl=2023.1.0=h213fc3f_46344
  - mkl-service=2.4.0=py310h5eee18b_1
  - mkl_fft=1.3.8=py310h5eee18b_0
  - mkl_random=1.2.4=py310hdb19cb5_0
  - mpi=1.0=mpich
  - mpi4py=3.1.4=py310hfc96bbd_0
  - mpich=3.3.2=external_0
  - msgpack-python=1.0.3=py310hd09550d_0
  - munkres=1.1.4=py_0
  - mysql=5.7.24=h721c034_2
  - ncurses=6.4=h6a678d5_0
  - nest-asyncio=1.5.6=py310h06a4308_0
  - netcdf4=1.6.2=py310h6d89c78_0
  - networkx=3.2.1=pyhd8ed1ab_0
  - nspr=4.35=h6a678d5_0
  - nss=3.89.1=h6a678d5_0
  - numba=0.58.0=py310h1128e8f_0
  - numcodecs=0.11.0=py310h6a678d5_0
  - numexpr=2.8.7=py310h85018f9_0
  - numpy=1.25.2=py310h5f9d8c6_0
  - numpy-base=1.25.2=py310hb5e798b_0
  - openjpeg=2.4.0=h3ad879b_0
  - openssl=3.0.12=h7f8727e_0
  - orc=1.7.4=hb3bc3d3_1
  - packaging=23.1=py310h06a4308_0
  - pandas=2.0.3=py310h1128e8f_0
  - parso=0.8.3=pyhd3eb1b0_0
  - partd=1.4.1=py310h06a4308_0
  - patsy=0.5.3=py310h06a4308_0
  - pcre=8.45=h295c915_0
  - pcre2=10.42=hebb0a14_0
  - pexpect=4.8.0=pyhd3eb1b0_3
  - pickleshare=0.7.5=pyhd3eb1b0_1003
  - pillow=10.0.1=py310ha6cbd5a_0
  - pip=23.3.1=py310h06a4308_0
  - pixman=0.40.0=h36c2ea0_0
  - platformdirs=3.10.0=py310h06a4308_0
  - plotnine=0.12.3=pyhd8ed1ab_0
  - pluggy=1.0.0=py310h06a4308_1
  - ply=3.11=py310h06a4308_0
  - poppler=22.12.0=h9614445_3
  - poppler-data=0.4.12=hd8ed1ab_0
  - proj=9.3.1=he5811b7_0
  - prompt-toolkit=3.0.36=py310h06a4308_0
  - psutil=5.9.0=py310h5eee18b_0
  - ptyprocess=0.7.0=pyhd3eb1b0_2
  - pure_eval=0.2.2=pyhd3eb1b0_0
  - pyarrow=11.0.0=py310h468efa6_1
  - pybind11-abi=4=hd3eb1b0_1
  - pycosat=0.6.6=py310h5eee18b_0
  - pycparser=2.21=pyhd3eb1b0_0
  - pygments=2.15.1=py310h06a4308_1
  - pylint=2.16.2=py310h06a4308_0
  - pyopenssl=23.2.0=py310h06a4308_0
  - pyparsing=3.0.9=py310h06a4308_0
  - pyproj=3.6.1=py310h6370d16_0
  - pyqt=5.15.10=py310h6a678d5_0
  - pyqt5-sip=12.13.0=py310h5eee18b_0
  - pysocks=1.7.1=py310h06a4308_0
  - python=3.10.13=h955ad1f_0
  - python-dateutil=2.8.2=pyhd3eb1b0_0
  - python-lmdb=1.4.1=py310h6a678d5_0
  - python-tzdata=2023.3=pyhd3eb1b0_0
  - python_abi=3.10=2_cp310
  - pytz=2023.3.post1=py310h06a4308_0
  - pyyaml=6.0.1=py310h5eee18b_0
  - pyzmq=25.1.0=py310h6a678d5_0
  - qhull=2020.2=h4bd325d_2
  - qt-main=5.15.2=h53bd1ea_10
  - re2=2022.04.01=h295c915_0
  - readline=8.2=h5eee18b_0
  - reproc=14.2.4=h295c915_1
  - reproc-cpp=14.2.4=h295c915_1
  - requests=2.31.0=py310h06a4308_0
  - rtree=1.2.0=py310hbdcdc62_0
  - ruamel.yaml=0.17.21=py310h5eee18b_0
  - ruamel.yaml.clib=0.2.6=py310h5eee18b_1
  - scikit-learn=1.3.0=py310h1128e8f_0
  - scipy=1.11.3=py310h5f9d8c6_0
  - seaborn=0.13.1=hd8ed1ab_0
  - seaborn-base=0.13.1=pyhd8ed1ab_0
  - setuptools=68.2.2=py310h06a4308_0
  - sip=6.7.12=py310h6a678d5_0
  - six=1.16.0=pyhd3eb1b0_1
  - snappy=1.1.10=h6a678d5_1
  - sortedcontainers=2.4.0=pyhd3eb1b0_0
  - sqlite=3.41.2=h5eee18b_0
  - stack_data=0.2.0=pyhd3eb1b0_0
  - statsmodels=0.14.0=py310ha9d4c09_0
  - tbb=2021.8.0=hdb19cb5_0
  - tblib=1.7.0=pyhd3eb1b0_0
  - threadpoolctl=2.2.0=pyh0d69192_0
  - tiledb=2.3.3=h77177df_3
  - tk=8.6.12=h1ccaba5_0
  - tomli=2.0.1=py310h06a4308_0
  - tomlkit=0.11.1=py310h06a4308_0
  - toolz=0.12.0=py310h06a4308_0
  - tornado=6.3.3=py310h5eee18b_0
  - tqdm=4.65.0=py310h2f386ee_0
  - traitlets=5.7.1=py310h06a4308_0
  - truststore=0.8.0=py310h06a4308_0
  - typing-extensions=4.7.1=py310h06a4308_0
  - typing_extensions=4.7.1=py310h06a4308_0
  - tzdata=2023c=h04d1e81_0
  - uriparser=0.9.7=h5eee18b_0
  - urllib3=1.26.18=py310h06a4308_0
  - utf8proc=2.6.1=h27cfd23_0
  - wcwidth=0.2.5=pyhd3eb1b0_0
  - wheel=0.41.2=py310h06a4308_0
  - widgetsnbextension=4.0.5=py310h06a4308_0
  - wrapt=1.14.1=py310h5eee18b_0
  - xarray=2023.9.0=pyhd8ed1ab_0
  - xerces-c=3.2.4=h6a678d5_1
  - xyzservices=2022.9.0=py310h06a4308_1
  - xz=5.4.5=h5eee18b_0
  - yaml=0.2.5=h7b6447c_0
  - yaml-cpp=0.8.0=h6a678d5_0
  - zarr=2.16.1=pyhd8ed1ab_0
  - zeromq=4.3.4=h2531618_0
  - zict=3.0.0=py310h06a4308_0
  - zipp=3.11.0=py310h06a4308_0
  - zlib=1.2.13=h5eee18b_0
  - zstandard=0.19.0=py310h5eee18b_0
  - zstd=1.5.5=hc292b87_0
  - pip:
      - aiosignal==1.3.1
      - attrs==23.1.0
      - black==24.1.1
      - brokenaxes==0.5.0
      - cartopy==0.22.0
      - certifi==2023.7.22
      - charset-normalizer==3.3.0
      - cma==3.3.0.1
      - cython==3.0.7
      - dacite==1.8.1
      - et-xmlfile==1.1.0
      - filelock==3.13.1
      - frozenlist==1.4.1
      - gprof2dot==2022.7.29
      - icoscp-core==0.3.0
      - ipdb==0.13.13
      - jsonschema==4.20.0
      - jsonschema-specifications==2023.11.2
      - matplotlib-scalebar==0.8.1
      - moarchiving==0.6.0
      - mycolorpy==1.5.1
      - mypy-extensions==1.0.0
      - openpyxl==3.1.2
      - patchworklib==0.6.2
      - pathspec==0.11.2
      - permetrics==1.5.0
      - protobuf==4.25.1
      - pyshp==2.3.1
      - ray==2.8.1
      - referencing==0.32.0
      - remote-plot==1.2.1
      - rpds-py==0.15.2
      - shapely==2.0.2
      - snakeviz==2.2.0
      - tuna==0.5.11
prefix: /path/to/miniconda3/envs/my_env

Another thing, I noticed just now is I have the issue of black formatter not working when /path/to/my_code.py follows a symlink. Black formatter is working if I open my code in VS Code without following a symlink.

werwack commented 10 months ago

Same issue here, no formatting anymore on VSC 1.86.0 with Black... Tried all the tips above, plus screwed up my settings here and there, no success. But... thanks to this note from @de-ranit, it is now "working" again! :

Black formatter is working if I open my code in VS Code without following a symlink.

So without using the mapped drive created with subst, I can still continue to work. I would strongly prefer to keep using the symlink though...

karthiknadig commented 10 months ago

@werwack The symlink issue is with black itself, it was fixed in version 24.0.0.

@side2k If you have dependency on specific version of black then I recommend doing this:

"black-formatter.importStrategy": "useBundled",
"black-formatter.path": ["${interpreter}", "-m", "black"],

The above settings will make the extension use the bundled libs for communication, but black from your environment.

stefmf commented 10 months ago

@karthiknadig any suggestions for me ? I've tried all of the above but still am not able to get it to work.

karthiknadig commented 10 months ago

@stefmf Can you open your Output > Black Formatter logs and see what it says?

stefmf commented 10 months ago

never mind i see the issue. it works but stops, if there is syntax issues.

de-ranit commented 10 months ago

The symlink issue is with black itself, it was fixed in version 24.0.0

I have black, 24.1.1 in terminal which works fine. Is the black shipped with the VS Code extension > =black, 24.0.0? If yes, why is it still not working in a path with symlink?

karthiknadig commented 10 months ago

@de-ranit It might have to do with how black is seeing the file. Because all we do in the extension is launch black in the following form. This extension is a wrapper around black, all we do is transform the responses from black in a way VS Code understands.

cat <your script path> | python -m black --stdin-filename <your script path> -

The only think I can think of is that there is some mismatch due to which directory is used for cwd. This should be in the logs. I suspect we might be using the resolved symlink directory but using the symlink path. You should be able to replicate this behaviro in terminal by cd-ing to the symlink target directory and then using the symlink script path.

> cd <symlink target workspace>
> cat <symlink script path> | python -m black --stdin-filename <symlink script path> -
nfvs commented 9 months ago

Can confirm that cat <path> | python -m black --stdin-filename <path> - works using the real paths, but not if they contain symlinks, so it seems to be an issue with black itself. Tested with latest black version 24.1.1.

de-ranit commented 9 months ago

I also tried black --verbose /path/with/symlink/my_script.py. It also produced /path/with/symlink/my_script.py ignored: is a symbolic link that points outside /actual/path/to/script No Python files are present to be formatted. Nothing to do 😴. An issue (https://github.com/psf/black/issues/4205) has already been created in the black repository.

karthiknadig commented 9 months ago

Leaving this issue open to update bundled black after https://github.com/psf/black/issues/4205 is addressed upstream and released

hauntsaninja commented 9 months ago

Black released 24.2.0, hopefully that fixes issues here

JasonGross commented 9 months ago

In case this ever comes back in the future, I wrote the following script for debugging this before realizing that it had already been reported and fixed (note that a previous version of black had problems with symlinks only in the presence of pyproject.toml):

#!/usr/bin/env bash
verbose=""
if [ "$1" == "-v" ] || [ "$1" == "--verbose" ]; then
    verbose=1
    set -x
fi
if [ -z "$PYTHON" ]; then
    PYTHON=python
fi
"$PYTHON" -m black --version
uname -a
testdir="$(mktemp -d)"
trap "rm -rf $testdir" EXIT
cd "$testdir"
subdir="."
mkdir -p "directory/$subdir"
ln -s directory symlink
cd "directory/$subdir"
runtest() {
    for cwd in "directory" "symlink"; do
        for usedir in "directory" "symlink"; do
            cd "$testdir/$cwd/$subdir"
            usefile="$testdir/$usedir/$subdir/test.py"
            echo "import numpy as np# foo" > test.py
            printf "%s in %s using %s..." "$1" "$cwd" "$usedir"
            if [ -n "$verbose" ]; then
                printf "\n"
                echo "import numpy as np# foo" | "$PYTHON" -m black --stdin-filename "$usefile" -
                printf "=====================================\n"
            else
                result="$(echo "import numpy as np# foo" | "$PYTHON" -m black --stdin-filename "$usefile" - 2>&1)"
                if printf -- "$result" | grep -q "1 file reformatted."; then
                    printf "pass\n"
                else
                    printf "fail\n"
                fi
            fi
        done
    done

}
runtest "without pyproject.toml"
touch pyproject.toml
runtest "with pyproject.toml"
karthiknadig commented 9 months ago

@JasonGross you should recommend this as a smoke test to black itself.