Skip to content

Commit

Permalink
Merge pull request #94 from MarcoGorelli/pylint
Browse files Browse the repository at this point in the history
CI pylint
  • Loading branch information
MarcoGorelli committed Jul 24, 2020
2 parents 54a6570 + c67e713 commit eab3ca0
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[MESSAGES CONTROL]
disable =
C0330, # to work well with `black`
R0801, # Unfortunately I do need some duplication, e.g. with imports
W1510 # I need to run subprocess.run without check because it's OK if it fails
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ nbQA
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/psf/black

.. image:: https://img.shields.io/badge/pylint-10/10-green.svg
:target: https://github.com/PyCQA/pylint

Adapter to run any code-quality tool on a Jupyter notebook. Documentation is hosted here_.

Prerequisites
Expand Down
2 changes: 2 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ stages:
mypy .
interrogate nbqa tests -v -c pyproject.toml
pydocstyle nbqa tests
pylint nbqa tests
displayName: 'static analysis'
- script: |
Expand Down Expand Up @@ -102,6 +103,7 @@ stages:
mypy .
interrogate nbqa tests -v -c pyproject.toml
pydocstyle nbqa tests
pylint nbqa tests
displayName: 'static analysis'
- script: |
Expand Down
12 changes: 6 additions & 6 deletions nbqa/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ def _parse_args(raw_args: Optional[List[str]]) -> Tuple[str, str, List[str]]:
parser.add_argument("--version", action="version", version=f"nbQA {__version__}")
try:
args, kwargs = parser.parse_known_args(raw_args)
except SystemExit as e:
if e.code != 0:
except SystemExit as exception:
if exception.code != 0:
msg = (
"Please specify both a command and a notebook/directory, e.g.\n"
"nbqa flake8 my_notebook.ipynb"
)
raise ValueError(msg) from e
raise ValueError(msg) from exception
sys.exit(0)
command = args.command
root_dir = args.root_dir
Expand Down Expand Up @@ -225,14 +225,14 @@ def _map_python_line_to_nb_lines(
mapping = {}
cell_no = 0
cell_count = None
for n, i in enumerate(cells):
if i == "# %%\n":
for idx, cell in enumerate(cells):
if cell == "# %%\n":
cell_no += 1
cell_count = 0
else:
assert cell_count is not None
cell_count += 1
mapping[n + 1] = f"cell_{cell_no}:{cell_count}"
mapping[idx + 1] = f"cell_{cell_no}:{cell_count}"
out = re.sub(
rf"(?<={notebook.name}:)\d+", lambda x: str(mapping[int(x.group())]), out,
)
Expand Down
3 changes: 2 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
black==19.10b0
flake8==3.8.3
interrogate==1.2.0
isort==5.0.9
isort==4.3.21
mypy==0.782
pre-commit==2.6.0
pydocstyle==5.0.2
pylint==2.5.3
pytest==5.4.3
pytest-cov==2.10.0
4 changes: 3 additions & 1 deletion tests/test_black.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ def test_black_works(
# check out and err
out, err = capsys.readouterr()
expected_out = ""
expected_err = f"reformatted {path}{os.linesep}All done! {os.linesep}1 file reformatted.{os.linesep}" # noqa
expected_err = os.linesep.join(
[f"reformatted {path}", "All done! ", "1 file reformatted."]
)
assert out == expected_out
for i in (0, 2): # haven't figured out how to test the emojis part
assert err.splitlines()[i] == expected_err.splitlines()[i]
4 changes: 2 additions & 2 deletions tests/test_isort_works.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_isort_works(
after = handle.readlines()
diff = difflib.unified_diff(before, after)
result = "".join([i for i in diff if any([i.startswith("+ "), i.startswith("- ")])])
expected = '+ "import glob\\n",\n' '- "\\n",\n' '- "import glob\\n",\n'
expected = '+ "import glob\\n",\n- "\\n",\n- "import glob\\n",\n'
assert result == expected

# check out and err
Expand Down Expand Up @@ -77,7 +77,7 @@ def test_isort_initial_md(
after = handle.readlines()
diff = difflib.unified_diff(before, after)
result = "".join([i for i in diff if any([i.startswith("+ "), i.startswith("- ")])])
expected = '+ "import glob\\n",\n' '- "\\n",\n' '- "import glob\\n",\n'
expected = '+ "import glob\\n",\n- "\\n",\n- "import glob\\n",\n'
assert result == expected

# check out and err
Expand Down
9 changes: 6 additions & 3 deletions tests/test_nbqa_ini.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ def test_nbqa_ini_works(
capsys
Pytest fixture to capture stdout and stderr.
"""
with open(".nbqa.ini", "w") as f:
f.write("[flake8]\nignore=F401\nselect=E303\nquiet\n")
with open(".nbqa.ini", "w") as handle:
handle.write("[flake8]\nignore=F401\nselect=E303\nquiet\n")

# check diff
with open(tmp_notebook_for_testing, "r") as handle:
Expand All @@ -47,7 +47,10 @@ def test_nbqa_ini_works(

# check out and err
out, err = capsys.readouterr()
expected_out = f"{os.path.abspath(os.path.join('tests', 'data', 'notebook_starting_with_md.ipynb'))}\n"
notebook = os.path.abspath(
os.path.join("tests", "data", "notebook_starting_with_md.ipynb")
)
expected_out = f"{notebook}\n"
expected_err = ""
assert sorted(out.splitlines()) == sorted(expected_out.splitlines())
assert sorted(err.splitlines()) == sorted(expected_err.splitlines())

0 comments on commit eab3ca0

Please sign in to comment.