-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Doesn't work with certain files #52
Comments
@Bobronium That is just a representation, the path itself is passed in programmatically via
Can you share the settings you are using? |
We use
you may have to quote the paths when actually running from the terminal. |
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
},
"black-formatter.args": [
"-S"
], Upd. cat "/Users/bobronium/Library/Application Support/Code/User/globalStorage/buenon.scratchpads/scratchpads/1a4f2b73c916c9af3926773a674c6453/scratch..py" | python -m black -S --stdin-filename "/Users/bobronium/Library/Application Support/Code/User/globalStorage/buenon.scratchpads/scratchpads/1a4f2b73c916c9af3926773a674c6453/scratch..py" -
No Python files are present to be formatted. Nothing to do 😴 But python -m black -S "/Users/bobronium/Library/Application Support/Code/User/globalStorage/buenon.scratchpads/scratchpads/1a4f2b73c916c9af3926773a674c6453/scratch..py"
All done! ✨ 🍰 ✨ So, I guess it's an issue with |
Maintainer of Black here 👋 Yeah I think Black is mishandling |
Here's the line where path is lost https://github.com/psf/black/blob/9ce100ba61b6738298d86818a3d0eee7b18bfed7/src/black/__init__.py#L626 Or, to be more precise:
|
Sounds like Black is mishandling the project root in STDIN mode. I can look into this later today. A list of reproduction steps would be nice, but it seems like an easy enough issue to reproduce? |
Here you go!
echo "print('Hello, world!')" > outside.py
poetry new project && cd project && poetry add black && poetry shell
cat ../outside.py | black --stdin-filename "../outside.py" -
|
For another issue, this time with the extension iteslfI wasn't getting any output to the console or any indication that anything is happening while trying to format certain files. Had to hack in def _format(
params: types.DocumentFormattingParams,
) -> Union[List[types.TextEdit], None]:
"""Runs formatter, processes the output, and returns text edits."""
document = LSP_SERVER.workspace.get_document(params.text_document.uri)
LSP_SERVER.show_message_log(f"Formatting... {document}")
if utils.is_stdlib_file(document.path) or not is_python(document.source):
LSP_SERVER.show_message_log(f"{utils.is_stdlib_file(document.path)=}, {not is_python(document.source)=}")
# Don't format standard library python files. Or, invalid python code
# or non-python code in case of notebooks
return None Got this output: Formatting... file:///Users/bobronium/dev/py/pythings/tests/conftest.py
utils.is_stdlib_file(document.path)=False, not is_python(document.source)=True
Not only it indicates the error, but also shows the exact line that couldn't be parsed. My proposal:
|
Closing in favor of #55 |
black -S --stdin-filename /Users/bobronium/Library/Application Support/Code/User/globalStorage/buenon.scratchpads/scratchpads/1a4f2b73c916c9af3926773a674c6453/scratch.py - CWD Formatter: /Users/bobronium/dev/py/... [Error - 1:45:24 AM] No Python files are present to be formatted. Nothing to do 😴
I'm not sure if it's an actual cmd, or its representation, but I can see right away that the file path is not escaped/quoted, which might cause this issue.
The text was updated successfully, but these errors were encountered: