PyCQA / PyCQA/isort

isort doesn't format the imports in PyCharm's Jupyter notebooks

Open
#2,254 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
7k
Forks
687
Avg merge
4h 56m
Merged PRs (30d)
2

Description

Hi! I've just created an External Tool instance for isort in PyCharm Professional and checked whether it works or not. Here's a screenshot of my tool's settings.
Screenshot_1

It turned out that it works smoothly with regular .py scripts, but it doesn't work with .ipynb files (Jupyter notebooks) at all. It might be worth noting that I've also been using the black formatter (see the settings in the screenshot below) together with isort and it works without any problems in .py files.
Screenshot_2

However, when I run isort in a notebook, it doesn't format imports in the notebook's cells; I just receive the following output:

C:\Users\USERNAME\AppData\Local\Programs\Python\Python310/Scripts/isort file_name.ipynb

Process finished with exit code 0

The only solution I've come across at this point is to use nbQA in the terminal as follows:
nbqa isort file_name.ipynb

In this case, it's possible to format the imports as expected. Could you tell me if it's a bug or not? Would it be better to contact JetBrains, as it might be a problem from their side?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the reported difference between running isort directly on a .ipynb file and running nbqa isort on the same notebook. Check whether notebook-cell formatting is expected from isort itself or depends on PyCharm or nbQA; done means the supported behavior and ownership are clear, with a regression test or documentation path identified.

Written by the indexing model from the issue text.

Assessment

Tech stack
jupyter-notebook, python
Domain
cli, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.