Skip to content

Commit

Permalink
make root dir obligatory (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli committed Jul 18, 2020
1 parent 9686e78 commit 24b3404
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 48 deletions.
18 changes: 9 additions & 9 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,18 @@ The general syntax is

.. code-block:: bash
nbqa -c <command> <args>
nbqa <command> <notebook or directory> <args>
, where :code:`command` is any Python code quality tool. For example, you could run:

.. code-block:: bash
$ nbqa -c flake8 my_notebook.ipynb
$ nbqa -c black my_notebook.ipynb --check
$ nbqa -c mypy my_notebook.ipynb --ignore-missing-imports
$ nbqa -c pytest my_notebook.ipynb --doctest-modules
$ nbqa flake8 my_notebook.ipynb
$ nbqa black my_notebook.ipynb --check
$ nbqa mypy my_notebook.ipynb --ignore-missing-imports
$ nbqa pytest my_notebook.ipynb --doctest-modules
You can also pass an entire directory instead of a single file, e.g. :code:`nbqa -c flake8 my_notebooks`.
You can also pass an entire directory instead of a single file, e.g. :code:`nbqa flake8 my_notebooks`.

Examples
--------
Expand All @@ -73,7 +73,7 @@ Format your notebooks using :code:`black`:

.. code-block:: bash
$ nbqa -c black .
$ nbqa black .
reformatted tweet-sentiment-roberta-pytorch.ipynb
All done! ✨ 🍰 ✨
1 files reformatted.
Expand All @@ -82,14 +82,14 @@ Check static type annotations:

.. code-block:: bash
$ nbqa -c mypy tweet-sentiment-roberta-pytorch.ipynb --ignore-missing-imports
$ nbqa mypy tweet-sentiment-roberta-pytorch.ipynb --ignore-missing-imports
tweet-sentiment-roberta-pytorch.ipynb:cell_10:5: error: Argument "batch_size" to "get_test_loader" has incompatible type "str"; expected "int"
Check any examples in your docstrings are correct:

.. code-block:: bash
$ nbqa -c pytest tweet-sentiment-roberta-pytorch.ipynb --doctest-modules
$ nbqa pytest tweet-sentiment-roberta-pytorch.ipynb --doctest-modules
============================= test session starts ==============================
platform linux -- Python 3.8.2, pytest-5.4.3, py-1.9.0, pluggy-0.13.1
rootdir: /home/marco/tweet-sentiment-extraction
Expand Down
6 changes: 2 additions & 4 deletions nbqa/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ def _parse_args(raw_args):
description="Adapter to run any code-quality tool on a Jupyter notebook.",
usage="nbqa <command> <notebook or directory> <flags>",
)
parser.add_argument("-c", "--command", help="Command to run, e.g. `flake8`.")
parser.add_argument(
"root_dir", default=".", nargs="?", help="File or directory to run command on."
)
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)
command = args.command
Expand Down
2 changes: 1 addition & 1 deletion tests/data/test_isort_works.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_isort_works(tmp_notebook_for_testing, capsys):
with open(tmp_notebook_for_testing, "r") as handle:
before = handle.readlines()
with pytest.raises(SystemExit):
main(["--command=isort", "tests/data/notebook_for_testing.ipynb"])
main(["isort", "tests/data/notebook_for_testing.ipynb"])

with open(tmp_notebook_for_testing, "r") as handle:
after = handle.readlines()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_black.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_black_works(tmp_notebook_for_testing, capsys):
with open(tmp_notebook_for_testing, "r") as handle:
before = handle.readlines()
with pytest.raises(SystemExit):
main(["--command=black", "tests/data/notebook_for_testing.ipynb"])
main(["black", "tests/data/notebook_for_testing.ipynb"])
with open(tmp_notebook_for_testing, "r") as handle:
after = handle.readlines()

Expand Down
2 changes: 1 addition & 1 deletion tests/test_doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_pytest_doctest_works(tmp_notebook_for_testing, capsys):
with open(tmp_notebook_for_testing, "r") as handle:
before = handle.readlines()
with pytest.raises(SystemExit):
main(["--command=pytest", "--doctest-modules"])
main(["pytest", "--doctest-modules", "."])

with open(tmp_notebook_for_testing, "r") as handle:
after = handle.readlines()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_flake8_works.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_flake8_works(tmp_notebook_for_testing, capsys):
with open(tmp_notebook_for_testing, "r") as handle:
before = handle.readlines()
with pytest.raises(SystemExit):
main(["--command=flake8"])
main(["flake8", "."])

with open(tmp_notebook_for_testing, "r") as handle:
after = handle.readlines()
Expand Down
4 changes: 2 additions & 2 deletions tests/test_isort_works.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_isort_works(tmp_notebook_for_testing, capsys):
with open(tmp_notebook_for_testing, "r") as handle:
before = handle.readlines()
with pytest.raises(SystemExit):
main(["--command=isort", "tests/data/notebook_for_testing.ipynb"])
main(["isort", "tests/data/notebook_for_testing.ipynb"])

with open(tmp_notebook_for_testing, "r") as handle:
after = handle.readlines()
Expand All @@ -38,7 +38,7 @@ def test_isort_initial_md(tmp_notebook_starting_with_md, capsys):
with open(tmp_notebook_starting_with_md, "r") as handle:
before = handle.readlines()
with pytest.raises(SystemExit):
main(["--command=isort", "tests/data/notebook_starting_with_md.ipynb"])
main(["isort", "tests/data/notebook_starting_with_md.ipynb"])

with open(tmp_notebook_starting_with_md, "r") as handle:
after = handle.readlines()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_missing_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ def test_missing_command():
"Please make sure you have it installed before running nbQA on it."
)
with pytest.raises(ValueError, match=msg):
main([f"--command={command}", "--some-flag"])
main([command, ".", "--some-flag"])
2 changes: 1 addition & 1 deletion tests/test_mypy_works.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_mypy_works(tmp_notebook_for_testing, capsys):
with open(tmp_notebook_for_testing, "r") as handle:
before = handle.readlines()
with pytest.raises(SystemExit):
main(["--command=mypy", "--ignore-missing-imports"])
main(["mypy", "--ignore-missing-imports", "."])

with open(tmp_notebook_for_testing, "r") as handle:
after = handle.readlines()
Expand Down
31 changes: 4 additions & 27 deletions tests/test_return_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,14 @@

def test_flake8_return_code():
output = subprocess.run(
[
"python",
"-m",
"nbqa",
"--command",
"flake8",
"tests/data/notebook_for_testing.ipynb",
]
["python", "-m", "nbqa", "flake8", "tests/data/notebook_for_testing.ipynb"]
)
result = output.returncode
expected = 1
assert result == expected

output = subprocess.run(
[
"python",
"-m",
"nbqa",
"--command",
"flake8",
"tests/data/clean_notebook.ipynb",
]
["python", "-m", "nbqa", "flake8", "tests/data/clean_notebook.ipynb"]
)
result = output.returncode
expected = 0
Expand All @@ -47,21 +33,13 @@ def test_black_return_code():
assert result == expected

output = subprocess.run(
[
"python",
"-m",
"nbqa",
"-c",
"black",
"--check",
"tests/data/clean_notebook.ipynb",
]
["python", "-m", "nbqa", "black", "--check", "tests/data/clean_notebook.ipynb"]
)
result = output.returncode
expected = 0
assert result == expected

output = subprocess.run(["python", "-m", "nbqa", "--command", "black", "--check"])
output = subprocess.run(["python", "-m", "nbqa", "black", "--check", "."])
result = output.returncode
expected = 1
assert result == expected
Expand All @@ -71,7 +49,6 @@ def test_black_return_code():
"python",
"-m",
"nbqa",
"--command",
"black",
"tests/data/clean_notebook.ipynb",
"--check",
Expand Down

0 comments on commit 24b3404

Please sign in to comment.