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

Format on save #12206

Open
aladinoster opened this issue Mar 14, 2022 · 5 comments
Open

Format on save #12206

aladinoster opened this issue Mar 14, 2022 · 5 comments
Labels
question tag:Extension Idea Ideas for interesting extensions that live outside of JupyterLab core.
Milestone

Comments

@aladinoster
Copy link

Problem

  • I am constantly switching between Jupyter Lab and VSCode just for the formatting functionality. I like a lot the possibility to format on save the code by applying formatting via black.

Proposed Solution

  • Would it be possible to have an option to format on save your code available via the settings option? This could probably imply the selector of a code formatter and maybe some parameters for the configuration.

Additional context

@welcome
Copy link

welcome bot commented Mar 14, 2022

Thank you for opening your first issue in this project! Engagement like this is essential for open source projects! 🤗

If you haven't done so already, check out Jupyter's Code of Conduct. Also, please try to follow the issue template as it helps other other community members to contribute more effectively.
welcome
You can meet the other Jovyans by joining our Discourse forum. There is also an intro thread there where you can stop by and say Hi! 👋

Welcome to the Jupyter community! 🎉

@jupyterlab-probot jupyterlab-probot bot added the status:Needs Triage Applied to new issues that need triage label Mar 14, 2022
@fcollonval
Copy link
Member

I would advice installing that extension: jupyterlab-code-formatter.

@fcollonval fcollonval added tag:Extension Idea Ideas for interesting extensions that live outside of JupyterLab core. and removed enhancement status:Needs Triage Applied to new issues that need triage labels Mar 14, 2022
@bollwyvl
Copy link
Contributor

We'd also like to support this for all the languages in jupyterlab-lsp but it's a bit of A Thing to support for All The Servers especially in the notebook.

@StefanBrand
Copy link

StefanBrand commented Mar 17, 2022

@aladinoster There are several possible workarounds. I myself now most often use VSCode myself because of its capability of formatting cells.*

Most simple: jupyter_black

I can really recommend jupyter_black. After installation you just have to run this in the first cell:

import jupyter_black

jupyter_black.load(lab= True)

All subsequent cells will be formatted after they have been run successfully.

Requires notebook reload: nbqa black

nbQA is a command line tool that not only supports black, but other formatters and linters as well. You would run nbqa black from the Terminal. Downside is that you would then have to go to "File > Reload Notebook from Disk" because JupyterLab does not automatically reload the notebook.


* I always have to manually "Select Python Intepreter" in VSCode before formatting would work. This most probably is a peculiarity of attaching to a JupyterHub-spawned hub and simultaneously connecting to the remote kernel.

@StefanBrand
Copy link

I propose to close this issue in favor of the older jupyter-lsp/jupyterlab-lsp#632, which is also closer to where the formatting feature would probably be implemented.

@fcollonval fcollonval added this to the Reference milestone Mar 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question tag:Extension Idea Ideas for interesting extensions that live outside of JupyterLab core.
Projects
None yet
Development

No branches or pull requests

4 participants