nbQA-dev / nbQA

Run ruff, isort, pyupgrade, mypy, pylint, flake8, and more on Jupyter Notebooks
https://nbqa.readthedocs.io/en/latest/index.html
MIT License
1.04k stars 41 forks source link

Useful tool for nbQA: docformatter #765

Closed tovrstra closed 1 year ago

tovrstra commented 2 years ago

The following works with nbQA (1.5.2) and docformatter (1.5.0).

nbqa docformatter -i example.ipynb

The -i option is needed to tell docformatter to modify the notebook in-place.

For those using pre-commit, the following configuration can be used:

repos:
- repo: https://github.com/nbQA-dev/nbQA
  rev: "1.5.2"
  hooks:
    - id: nbqa
      entry: nbqa docformatter -i
      name: nbqa-docformatter
      alias: nbqa-docformatter
      additional_dependencies: [docformatter==1.5.0]

It might be useful to support docformatter out of the box in nbQA, or to show this example in the documentation. (The documentation already explains how to get custom tools to work, but a working example is always nice to have.)

Here is an example notebook to try out the above setup: example_nbqa_docformatter.zip

MarcoGorelli commented 2 years ago

sure, PRs welcome

tovrstra commented 2 years ago

What do you think is the best way to go?

  1. Add docformatter as an example of a custom tool.
  2. Built-in support for docformatter in nbQA.

The first would be easy. The second will take a bit longer, but should not be too hard either.

MarcoGorelli commented 2 years ago

If it's added as an example, there should be tests - do you want to go about adding them? There's examples of other tools, a simple one with --nbqa-diff should be fine

tovrstra commented 2 years ago

Sure thing. I wouldn't mind adding tests too. I'll see how the example idea works out and make a PR for it.

MarcoGorelli commented 1 year ago

closing for now as there's been no activity here in several months, but feel free to open a PR if you'd still like this