Closed wragge closed 10 months ago
Run the QA on a single file without committing:
pre-commit run --files Composite-thumbnails.ipynb
This should run automatically when committed.
Runs:
isort
black
flake8
Alternatively, to run separately:
nbqa isort
Test a single file:
pytest --nbval-lax Analysing_OCR_corrections.ipynb
Add skip-nbval tag to any cell you don't want to run.
skip-nbval
Create requirements-dev.in with the following:
requirements-dev.in
pytest nbval nbqa black[jupyter] isort flake8 pre-commit
Install
Create .pre-commit-config.yaml:
.pre-commit-config.yaml
repos: - repo: https://github.com/nbQA-dev/nbQA rev: 1.2.3 hooks: - id: nbqa-isort - id: nbqa-black - id: nbqa-flake8
Run
pre-commit install to set up hooks
pre-commit install
Create config
pyproject.toml:
pyproject.toml
Modify as necessary to exclude files
[tool.nbqa.addopts] flake8 = [ "--ignore=E501,W503" ] [tool.pytest.ini_options] addopts = "--ignore-glob=Untitled* --ignore=snippets.ipynb --ignore=newspaper-explorer.ipynb --ignore-glob=App* --ignore-glob=draft* --ignore=appmode-checking.ipynb"
Handy test script
test_and_lint.sh:
test_and_lint.sh
#!/bin/bash pytest --nbval-lax $1 if nbqa isort $1; then echo "ISort: $(tput setab 2)$(tput setaf 7)PASSED$(tput sgr0)" else echo "ISort: $(tput setab 1)$(tput setaf 7)FAILED$(tput sgr0)" fi if nbqa black $1; then echo "Black: $(tput setab 2)$(tput setaf 7)PASSED$(tput sgr0)" else echo "Black: $(tput setab 1)$(tput setaf 7)FAILED$(tput sgr0)" fi if nbqa flake8 $1; then echo "Flake8: $(tput setab 2)$(tput setaf 7)PASSED$(tput sgr0)" else echo "Flake8: $(tput setab 1)$(tput setaf 7)FAILED$(tput sgr0)" fi
Also include checks for broken links using pytest-check-links: https://github.com/jupyterlab/pytest-check-links
Run the QA on a single file without committing:
pre-commit run --files Composite-thumbnails.ipynb
This should run automatically when committed.
Runs:
isort
- sort imports (changes nb)black
- format code (changes nb)flake8
- lints code (displays warnings)Alternatively, to run separately:
nbqa isort
Test a single file:
pytest --nbval-lax Analysing_OCR_corrections.ipynb
Add
skip-nbval
tag to any cell you don't want to run.Set up
Create
requirements-dev.in
with the following:pytest nbval nbqa black[jupyter] isort flake8 pre-commit
Install
Create
.pre-commit-config.yaml
:Run
pre-commit install
to set up hooksCreate config
pyproject.toml
:Modify as necessary to exclude files
Handy test script
test_and_lint.sh
: