Skip to content
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

Make format-on-save easier for Python #2249

Closed
nealrichardson opened this issue Feb 13, 2024 · 8 comments
Closed

Make format-on-save easier for Python #2249

nealrichardson opened this issue Feb 13, 2024 · 8 comments
Assignees

Comments

@nealrichardson
Copy link

I seem to be struggling with this in Positron more than I did in VS Code, though maybe I did some extra setup steps there that I don't remember now. I've enabled the "Format on save" setting, but nothing ever happens in either Python or R (I haven't tried C++ in Positron yet).

I know that Python and R packages are required to do the formatting, but I would expect either that (a) when I create a virtualenv from the command pallete, it would also install black there if that's what's needed to do formatting, or (b) it would prompt me to install black, just as it often does (or used to at least) prompt me to install ipython for jupyter, or (c) raise some message that it couldn't format on save because I have to install some package.

@jmcphers
Copy link
Collaborator

jmcphers commented Feb 13, 2024

For R, you need to install the styler package, after which "format on save" should work. See this comment: #1407 (comment). I've filed #2251 to track the work to break that dependency.

For Python, the core Python extension we use doesn't support format on save (see https://code.visualstudio.com/docs/python/formatting). You can use black via https://open-vsx.org/extension/ms-python/black-formatter which is available via OpenVSX.

Don't disagree that this should be easier/we should bundle or help you do this.

@nealrichardson
Copy link
Author

I wondered if there was something up with the Python extension because when I searched the settings for format on save, I was surprised that there wasn't an entry under Python that would let me choose black or something else, which I recall having in VS Code.

@petetronic
Copy link
Collaborator

Repurposing this as "Format on save" should work better out of the box for Python (as there are different issues for R as mentioned above).

@petetronic petetronic added this to the Public Beta 2024 Q2 milestone Feb 26, 2024
@petetronic petetronic changed the title Make format-on-save easier Make format-on-save easier for Python Feb 26, 2024
@nealrichardson
Copy link
Author

Repurposing this as "Format on save" should work better out of the box for Python (as there are different issues for R as mentioned above).

Sounds good. In case it's useful color, I've been working on a python project lately, and I've been tempted to switch back to VS Code so that I don't have to manually run black on my changes.

@isabelizimm
Copy link
Contributor

isabelizimm commented Feb 27, 2024

If you download the black extension in Positron, format on save will work. Right now, black is a recommended extension for positron-python. If people ignore the "Download recommended extensions" popup (which, realistically, most everyone does), then you have to know to download it, which is a weird state to be in.

To make it easier for users, we could have black bundled in Positron.

If we wanted to go further, we could just bundle all the recommended extensions, which include isort and flake8 as well.

@nealrichardson
Copy link
Author

Oh nice, I was not aware that there was a separate black extension (and I don't recall seeing a "Download recommended extensions" popup, but I may have brushed it off back in the beginning). I've installed it and now I'm nice and formatted 💅 , thank you!

I wouldn't complain if it were bundled with Positron.

@petetronic
Copy link
Collaborator

Positron Version: 2024.02.0 (Universal) build 1585 included a bundled version of the Black Formatter extension from the ms-python group at Microsoft under the MIT license.

@petetronic
Copy link
Collaborator

I set up the default formatter as the new Black Formatter, turned on Format on Save, and when I saved a .py file, it formatted using Black format rules.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants