microsoft / microsoft/vscode-black-formatter

Extension does not seem to use the local `pyproject.toml`

Open
#519 8 comments 5 reactions 1 assignee Claimed by @karthiknadig View on GitHub
bug triage-needed
Dominant language
Python
Stars
196
Forks
49
Avg merge
1d 5h
Merged PRs (30d)
7

Description

## Diagnostic Data
- Python version (& distribution if applicable, e.g., Anaconda): 3.10.14
- Type of virtual environment used (e.g., conda, venv, virtualenv, etc.): poetry
- Operating system (and version): MacOS Monterey
- Version of tool extension you are using: v2024.2.0

## Behaviour

When I save my `.py` files, the extension converts single-quote strings to double-quote strings, even though I have the following in my `pyproject.toml`

```
[tool.black]
target-version = ["py310"]
exclude = "migrations"
skip-string-normalization = true
```

I tried to call black directly from the command-line and it does do this, so it works as expected.

But now suddenly it stopped ignoring the single-quotes and it doesn't format them anymore. If I change my settings in `pyproject.toml` to

```
[tool.black]
target-version = ["py310"]
exclude = "migrations"
# skip-string-normalization = true
```

Now, it doesn't format the single-quotes to double-quotes.

Maybe this is a cache problem?

## Logs:

```
2024-06-17 15:39:46.372 [info] /Users/me/Library/Caches/pypoetry/virtualenvs/myproject-GRsX74iM-py3.10/bin/python -m black --stdin-filename /mydir/file.py -
2024-06-17 15:39:46.372 [info] CWD formatter: /mydir
2024-06-17 15:39:46.392 [info] reformatted /mydir/file.py

All done! ✨ 🍰 ✨
1 file reformatted.
```

## Outcome When Attempting Debugging Steps:

Did running it from the command line work? No

If I run `/Users/me/Library/Caches/pypoetry/virtualenvs/myproject-GRsX74iM-py3.10/bin/python -m black --stdin-filename /mydir/file.py` from the terminal, I get the error

```
Usage: python -m black [OPTIONS] SRC ...

One of 'SRC' or 'code' is required.
```

So, I tried `/Users/me/Library/Caches/pypoetry/virtualenvs/myproject-GRsX74iM-py3.10/bin/python -m black --stdin-filename SRC /mydir/file.py` and it works now.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.