Skip to content

Commit

Permalink
ERR Clarify error message (#81)
Browse files Browse the repository at this point in the history
* better error message if a notebook/directory isn't passed

* better error message if a notebook/directory isn't passed
  • Loading branch information
MarcoGorelli committed Jul 19, 2020
2 parents 40f917b + aada465 commit 1f3b9b6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
15 changes: 12 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Format your notebooks using :code:`black`:

.. code-block:: bash
$ nbqa black .
$ nbqa black . --line-length=96
reformatted tweet-sentiment-roberta-pytorch.ipynb
All done! ✨ 🍰 ✨
1 files reformatted.
Expand Down Expand Up @@ -144,14 +144,23 @@ could add to your :code:`.pre-commit-config.yaml` file:
hooks:
- id: nbqa
args: ['flake8']
name: nbqa-flake8
- repo: https://github.com/MarcoGorelli/nbQA-mirror-1
rev: master
hooks:
- id: nbqa
args: ['isort']
name: nbqa-isort
- repo: https://github.com/MarcoGorelli/nbQA-mirror-2
rev: master
hooks:
- id: nbqa
args: ['mypy']
name: nbqa-mypy
Note that, because the repository keys need to be unique, you will need to use a
different mirror repository for each pre-commit hook you wish to use.
It's entirely optional which tool to use with which mirror, the purpose of having
these mirror is to avoid duplicate keys in the :code:`.pre-commit.yaml` file, but
they're all the same.

See Also
--------
Expand Down
14 changes: 12 additions & 2 deletions nbqa/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,22 @@ def _parse_args(raw_args):
"""
parser = argparse.ArgumentParser(
description="Adapter to run any code-quality tool on a Jupyter notebook.",
usage="nbqa <command> <notebook or directory> <flags>",
usage=(
"nbqa <command> <notebook or directory> <flags>\n"
"e.g. `nbqa flake8 my_notebook.ipynb --ignore=E203`"
),
)
parser.add_argument("command", help="Command to run, e.g. `flake8`.")
parser.add_argument("root_dir", help="Notebook or directory to run command on.")
parser.add_argument("--version", action="version", version=f"nbQA {__version__}")
args, kwargs = parser.parse_known_args(raw_args)
try:
args, kwargs = parser.parse_known_args(raw_args)
except SystemExit as e:
msg = (
"Please specify both a command and a notebook/directory, e.g.\n"
"nbqa flake8 my_notebook.ipynb"
)
raise ValueError(msg) from e
command = args.command
root_dir = args.root_dir
return command, root_dir, kwargs
Expand Down
12 changes: 12 additions & 0 deletions tests/test_missing_root_dir.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import pytest

from nbqa.__main__ import main


def test_missing_root_dir():
msg = (
"Please specify both a command and a notebook/directory, e.g.\n"
"nbqa flake8 my_notebook.ipynb"
)
with pytest.raises(ValueError, match=msg):
main(["flake8", "--ignore=E203"])

0 comments on commit 1f3b9b6

Please sign in to comment.