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

Does not work in VS Code Jupyter Notebooks #19

Open
grahamwetzler opened this issue Mar 1, 2020 · 5 comments
Open

Does not work in VS Code Jupyter Notebooks #19

grahamwetzler opened this issue Mar 1, 2020 · 5 comments

Comments

@grahamwetzler
Copy link

Neither %load_ext nb_black nor %load_ext lab_black work with Jupyter Notebooks in Visual Studio Code. There is no error. The code just doesn't format.

  • nb-black version 1.0.7
  • VS Code version 1.42.1
  • VS Code Python Extension version 2020.2.64397
  • Python version 3.8.1
@michaelaye
Copy link

Can one not simply use the black functionality of VSCode in there?

@grahamwetzler
Copy link
Author

The format document command does not appear in the command palette while in a notebook.

@MarcoGorelli
Copy link

MarcoGorelli commented Aug 22, 2020

@grahamwetzler the black functionality in VScode only works on .py files, as far as I can tell.

In case it's useful to you, though, I've made a tool which might be helpful to you - https://github.com/nbQA-dev/nbQA. You can use it via the command-line as

python -m pip install -U nbqa
nbqa black my_notebook.ipynb

It only works via the command-line or as a pre-commit hook though, so it's certainly not a replacement for the excellent tool that black_nb is


pre-commit example:

- repo: https://github.com/nbQA-dev/nbQA
  rev: 1.5.3
  hooks:
    - id: nbqa-black

EDIT: as for 2022, black has a built-in black-jupyter hook, so the above suggestion to use nbQA is no longer necessary

@LucasHattoriCosta
Copy link

Just leaving as another suggestion: there is a command for format_cell available in VsCode. In Mac the shortcut is shift+option+F
Again, not a real replacement for the excelent tool that is nb_black, but better than having un-linted code 😅

@morberg
Copy link

morberg commented Dec 10, 2022

https://github.com/n8henrie/jupyter-black works really well for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants