question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Different behaviour between `nbqa black` and `nbqa black --check`

See original GitHub issue

Hello,

Thanks for making this awesome tool.

I’ve been having some problems related to nbqa black --check raising problems but nbqa black not doing anything to change it. I’ve managed to recreate this with the following minimal example. It appears to be related to how the configuration is parsed.

.
├── notebook.ipynb
└── pyproject.toml

My project has something like the following configuration. We set the line length to be 79 for source code but are happy with longer lines inside notebooks.

# pyproject.toml
[tool.black]
line-length = 79

[tool.nbqa.addopts]
# use longer lines in notebooks
black = [
    "--line-length=88",
]

notebook.ipynb has a single cell with the following contents

result = function_name(xxxxxxxxxxxxxxxxxxxxxxxxxx, xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)

The exact contents are not so important, the important thing is that the line length is more than 79 but less than 88. Running

nbqa black notebook.ipynb

results in no changes, but running

nbqa black --check notebook.ipynb

indicates that the notebook would be reformatted.

image

To avoid any ambiguity, here’s the notebook JSON

{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "77402ebb-99fc-4232-9f9a-d46bb0d3aa3d",
   "metadata": {},
   "outputs": [],
   "source": [
    "result = function_name(xxxxxxxxxxxxxxxxxxxxxxxxxx, xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "nbqa",
   "language": "python",
   "name": "nbqa"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
MarcoGorellicommented, Jul 21, 2021

@tcbegley I’ve made a new release (it’s been about a year since the first version, so I’ve finally made a 1.0.0 release 🎉), if you could try it out and let me know if this doesn’t work for you, that’d be much appreciated

As an aside, --nbqa-mutate is no longer necessary (it won’t error if you pass it, but it won’t do anything anymore)

0reactions
tcbegleycommented, Jul 22, 2021

Thanks @MarcoGorelli! Updated our CI and it all seems to be working like a charm.

Read more comments on GitHub >

github_iconTop Results From Across the Web

nbQA Documentation
Install nbqa and at least one Python code quality tool - here, we'll use black pip install -U nbqa black. 2. Check your...
Read more >
nbQA-dev/nbQA: Run isort, pyupgrade, mypy, pylint, flake8 ...
Run isort, pyupgrade, mypy, pylint, flake8, black, blacken-docs, and more on Jupyter Notebooks · ✓ handles IPython magics robustly · ✓ respects your...
Read more >
nbqa - PyPI
nbqa is a clean, easy to use, and effective tool for notebook code style. Formatting and readability makes a huge difference when rendering...
Read more >
HowTo: add formating and linting to nbdev (black, isort, mypy ...
this does not allow you to use other tools like isort or mypy. nbqa. use nbqa to format and verify code in your...
Read more >
Short Introduction to nbqa - Calmcode
Many of our favorite code checking tools in python (like, black and flake8) only work on .py files. That's a shame because it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found