formatting python code with custom argument isn't working
Check for existing issues
- [X] Completed
Describe the bug / provide steps to reproduce it
I have the following configuration about python formatting:
{
"buffer_font_size": 16,
"buffer_font_family": "BerkeleyMono Nerd Font",
"language_overrides": {
"Python": {
"format_on_save": "off",
"formatter": {
"external": {
"command": "black",
"arguments": [
"--line-length",
"110"
]
}
}
}
}
}
And given following python code:
# a.py
def a(b, c, d, e):
pass
a("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "cccccccccccccccccccccccccc", "dddddddddddddddddddddddd", "eeeeeeeeeeeeeeeeeeeeee")
Trying to format python code, nothing is happened.
But the following configuration is ok:
"language_overrides": {
"Python": {
"format_on_save": "off",
"formatter": {
"external": {
"command": "black",
"arguments": [
"-"
]
}
}
}
}
Expected behavior
I'd expect python code is formatted.
Environment
Zed 0.62.8 – /Applications/Zed.app \nmacOS 13.0 \narchitecture x86_64
If applicable, add mockups / screenshots to help explain present your vision of the feature
No response
If applicable, attach your ~/Library/Logs/Zed/Zed.log file to this issue
Here is relative log about formatting:
08:39:58 [ERROR] failed to format via external command "black"
Caused by:
command failed with exit code Some(1):
stdout:
stderr: Usage: black [OPTIONS] SRC ...
One of 'SRC' or 'code' is required.
Just curious, is Black installed in your virtual environment, or globally? I feel like we have a current restriction that only allows the to work if black is installed globally.
Black is installed globally
This works for me fyi,
{
"language_overrides": {
"Python": {
"format_on_save": "on",
"formatter": {
"external": {
"command": "black",
"arguments": [
"-"
]
}
}
}
}
}
Hi, can't make black formatter work with language_overrides setting, but everything works fine if I add a Python section under languages:
"languages": {
"Plain Text": {
"soft_wrap": "preferred_line_length"
},
"C": {
"tab_size": 2
},
"C++": {
"tab_size": 2
},
"Elixir": {
"tab_size": 2
},
"Go": {
"tab_size": 4,
"hard_tabs": true
},
"Markdown": {
"soft_wrap": "preferred_line_length"
},
"Rust": {
"tab_size": 4
},
"JavaScript": {
"tab_size": 2
},
"TypeScript": {
"tab_size": 2
},
"TSX": {
"tab_size": 2
},
"Yaml": {
"tab_size": 2
},
"Python": {
"format_on_save": {
"external": {
"command": "black",
"arguments": [
"-"
]
}
}
}
Hi, can't make black formatter work with language_overrides setting, but everything works fine if I add a Python section under languages:
"languages": { "Plain Text": { "soft_wrap": "preferred_line_length" }, "C": { "tab_size": 2 }, "C++": { "tab_size": 2 }, "Elixir": { "tab_size": 2 }, "Go": { "tab_size": 4, "hard_tabs": true }, "Markdown": { "soft_wrap": "preferred_line_length" }, "Rust": { "tab_size": 4 }, "JavaScript": { "tab_size": 2 }, "TypeScript": { "tab_size": 2 }, "TSX": { "tab_size": 2 }, "Yaml": { "tab_size": 2 }, "Python": { "format_on_save": { "external": { "command": "black", "arguments": [ "-" ] } } }
This scheme worked for me!
Hmm... formatting used to work, but for whatever reason it stopped. Maybe I am missing something like python association?
I tried both blocks of code:
"language_overrides": {
"Python": {
"format_on_save": "on",
"formatter": {
"external": {
"command": "black",
"arguments": [
"--line-length",
"89",
"-"
]
}
}
}
// "Lua": {
// "format_on_save": "off"
// }
},
or this one which used to work originally:
"language_overrides": {
"Python": {
"format_on_save": "on",
"formatter": {
"external": {
"command": "black",
"arguments": [
"--line-length",
"89",
"-"
]
}
}
}
I am 99% positive it is something with python association I have with ZED, just not sure now how to fix it 🤔
Also note log does not show any error related to black or python itself, so ¯_(ツ)_/¯
Also when launching terminal within ZED I can execute the manual black command and it works fine, so this is not the env setup.
Using languages instead of language_overrides worked for me too, I'm not sure why but it sounds like a bug.
It works fine on newest version with following config, I think the issue is resolved
"language_overrides": {
"Python": {
"format_on_save": "off",
"formatter": {
"external": {
"command": "black",
"arguments": ["--line-length", "110", "-"]
}
}
}
}