使用 nbQA 在 Jupyter 笔记本上运行 Ruff、Mypy 和其他代码质量工具
Apply standard Python formatters, linters, and type checkers to notebook-heavy repositories without manually converting notebooks to scripts.
Prerequisites
Python 3, pip, nbQA, Jupyter notebooks, underlying QA tools such as Ruff or Mypy
Installation
Use the upstream install or setup path that matches your environment:
- $ python -m pip install -U nbqa
- $ python -m pip install -U "nbqa[toolchain]"
Requirements and caveats from upstream:
- In your virtual environment, run (note: the $ is not part of the command):
- Format .md files saved via Jupytext (requires jupytext to be installed):
- See command-line examples for examples involving doctest, flake8, [mypy](...
Basic usage or getting-started notes:
- Run ruff, isort, pyupgrade, mypy, pylint, flake8, black, blacken-docs, and more on Jupyter Notebooks
- Here's an example of how to set up some pre-commit hooks: put this in your .pre-commit-config.yaml file (see usage as pre-commit hook)
- https://github.com/1991513ccie-png/skills
- Source: https://github.com/1991513ccie-png/skills
- Extracted from upstream docs: https://raw.githubusercontent.com/nbQA-dev/nbQA/HEAD/README.md
Documentation
- https://nbqa.readthedocs.io/