3👍
Make sure black is installed in current used environment.
Open a integrated Terminal and activate the venv, run pip show black
to see if it’s installed in current environment. If not,
1.Comment these two settings;
"python.formatting.provider": "black",
"python.formatting.blackPath":"path-to-/bin/black",
2.Turn to python file, right click choose Format Document With… –> Python, there would be a prompt popping up to mention you install formatter, choose install black. After installation, the following setting will occur automatically in the Settings.json:
"python.formatting.provider": "black"
Then you can Format Document.
1👍
I found out that you must set the default formatter which is language specific.
For python this is ms-python.python
extension by Microsoft, which allows a specific formatter to be enabled, e.g autopep8, black, yapf, etc. Note I was getting notification telling me that Extension 'prettier - Code formatter' cannot format file.py
"[python]": {
"editor.defaultFormatter": "ms-python.python",
}
Then include your actual formatter:
"python.formatting.provider": "black",
"python.formatting.blackPath": "/path/"
- [Django]-What is the difference between Authorization and Authentication in Django?
- [Django]-How to translate Enum string in django?
- [Django]-Python PIL – background displayed opaque instead of transparent
0👍
If you’re developing in docker you can add
RUN ln -s $(poetry env info -p)/bin/black /usr/local/bin/black
and in your settings.json
use the link
...
"python.formatting.provider": "black",
"python.formatting.blackPath": "/usr/local/bin/black",
which will use your black settings in your pyproject.toml
(i.e) something like
[tool.black]
line-length = 80
target-version = ['py39']
- [Django]-Retrieve the integer stored in (?P<topic_id>\d+)
- [Django]-How do I specify order of fields in Django form?
- [Django]-Django ORM: Perform conditional `order_by`
- [Django]-Django 1.5 extend admin/change_form.html object tools
- [Django]-How to post a list with django-restframework testclient